Update chatbots (#463)

This commit is contained in:
Chomp
2025-07-08 21:45:16 +01:00
committed by GitHub
25 changed files with 103 additions and 60 deletions
@@ -1,4 +1,5 @@
using SPTarkov.Server.Core.Helpers.Dialog.Commando;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Utils;
@@ -14,12 +15,12 @@ public abstract class AbstractDialogChatBot(
) : IDialogueChatBot
{
protected readonly IDictionary<string, IChatCommand> _chatCommands = chatCommands.ToDictionary(
command => command.GetCommandPrefix()
command => command.CommandPrefix
);
public abstract UserDialogInfo GetChatBot();
public async ValueTask<string> HandleMessage(string sessionId, SendMessageRequest request)
public async ValueTask<string> HandleMessage(MongoId sessionId, SendMessageRequest request)
{
if ((request.Text ?? "").Length == 0)
{
@@ -33,7 +34,7 @@ public abstract class AbstractDialogChatBot(
if (
splitCommand.Length > 1
&& _chatCommands.TryGetValue(splitCommand[0], out var commando)
&& commando.GetCommands().Contains(splitCommand[1])
&& commando.Commands.Contains(splitCommand[1])
)
{
return await commando.Handle(splitCommand[1], GetChatBot(), sessionId, request);
@@ -58,7 +59,7 @@ public abstract class AbstractDialogChatBot(
}
protected async ValueTask<string> SendPlayerHelpMessage(
string sessionId,
MongoId sessionId,
SendMessageRequest request
)
{
@@ -77,14 +78,14 @@ public abstract class AbstractDialogChatBot(
_mailSendService.SendUserMessageToPlayer(
sessionId,
GetChatBot(),
$"Commands available for \"{chatCommand.GetCommandPrefix()}\" prefix:",
$"Commands available for \"{chatCommand.CommandPrefix}\" prefix:",
[],
null
);
await Task.Delay(TimeSpan.FromSeconds(1));
foreach (var subCommand in chatCommand.GetCommands())
foreach (var subCommand in chatCommand.Commands)
{
_mailSendService.SendUserMessageToPlayer(
sessionId,
@@ -103,7 +104,7 @@ public abstract class AbstractDialogChatBot(
public void RegisterChatCommand(IChatCommand chatCommand)
{
var prefix = chatCommand.GetCommandPrefix();
var prefix = chatCommand.CommandPrefix;
if (!_chatCommands.TryAdd(prefix, chatCommand))
{
throw new Exception(
@@ -1,3 +1,4 @@
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
@@ -5,13 +6,13 @@ namespace SPTarkov.Server.Core.Helpers.Dialog.Commando;
public interface IChatCommand
{
public string GetCommandPrefix();
public string CommandPrefix { get; }
public string GetCommandHelp(string command);
public List<string> GetCommands();
public List<string> Commands { get; }
public ValueTask<string> Handle(
string command,
UserDialogInfo commandHandler,
string sessionId,
MongoId sessionId,
SendMessageRequest request
);
}
@@ -1,5 +1,6 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers.Dialog.Commando.SptCommands;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Spt.Config;
@@ -20,7 +21,7 @@ public class SptCommandoCommands : IChatCommand
IEnumerable<ISptCommand> sptCommands
)
{
_sptCommands = sptCommands.ToDictionary(command => command.GetCommand());
_sptCommands = sptCommands.ToDictionary(command => command.Command);
_serverLocalisationService = localisationService;
var coreConfigs = configServer.GetConfig<CoreConfig>();
var commandoId = coreConfigs.Features?.ChatbotFeatures.Ids.GetValueOrDefault("commando");
@@ -35,25 +36,31 @@ public class SptCommandoCommands : IChatCommand
}
}
public string GetCommandPrefix()
public string CommandPrefix
{
return "spt";
get
{
return "spt";
}
}
public string GetCommandHelp(string command)
{
return _sptCommands.TryGetValue(command, out var value) ? value.GetCommandHelp() : "";
return _sptCommands.TryGetValue(command, out var value) ? value.CommandHelp : "";
}
public List<string> GetCommands()
public List<string> Commands
{
return _sptCommands.Keys.ToList();
get
{
return _sptCommands.Keys.ToList();
}
}
public async ValueTask<string> Handle(
string command,
UserDialogInfo commandHandler,
string sessionId,
MongoId sessionId,
SendMessageRequest request
)
{
@@ -62,7 +69,7 @@ public class SptCommandoCommands : IChatCommand
public void RegisterSptCommandoCommand(ISptCommand command)
{
var key = command.GetCommand();
var key = command.Command;
if (!_sptCommands.TryAdd(key, command))
{
throw new Exception(
@@ -40,21 +40,27 @@ public class GiveSptCommand(
protected readonly Dictionary<string, SavedCommand> _savedCommand = new();
public string GetCommand()
public string Command
{
return "give";
get
{
return "give";
}
}
public string GetCommandHelp()
public string CommandHelp
{
return "spt give\n========\nSends items to the player through the message system.\n\n\tspt give [template ID] [quantity]\n\t\tEx: "
get
{
return "spt give\n========\nSends items to the player through the message system.\n\n\tspt give [template ID] [quantity]\n\t\tEx: "
+ "spt give 544fb25a4bdc2dfb738b4567 2\n\n\tspt give [\"item name\"] [quantity]\n\t\tEx: spt give \"pack of sugar\" 10\n\n\tspt "
+ "give [locale] [\"item name\"] [quantity]\n\t\tEx: spt give fr \"figurine de chat\" 3";
}
}
public ValueTask<string> PerformAction(
UserDialogInfo commandHandler,
string sessionId,
MongoId sessionId,
SendMessageRequest request
)
{
@@ -1,15 +1,16 @@
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
namespace SPTarkov.Server.Core.Helpers.Dialog.Commando.SptCommands;
public interface ISptCommand
{
public string GetCommand();
public string GetCommandHelp();
public string Command { get; }
public string CommandHelp { get; }
public ValueTask<string> PerformAction(
UserDialogInfo commandHandler,
string sessionId,
MongoId sessionId,
SendMessageRequest request
);
}
@@ -30,21 +30,27 @@ public class ProfileSptCommand(
protected static readonly Regex _examineRegex = new(@"^spt profile (?<command>examine)");
public string GetCommand()
public string Command
{
return "profile";
get
{
return "profile";
}
}
public string GetCommandHelp()
public string CommandHelp
{
return "spt profile\n========\nSets the profile level or skill to the desired level through the message system.\n\n\tspt "
get
{
return "spt profile\n========\nSets the profile level or skill to the desired level through the message system.\n\n\tspt "
+ "profile level [desired level]\n\t\tEx: spt profile level 20\n\n\tspt profile skill [skill name] [quantity]\n\t\tEx: "
+ "spt profile skill metabolism 51";
}
}
public ValueTask<string> PerformAction(
UserDialogInfo commandHandler,
string sessionId,
MongoId sessionId,
SendMessageRequest request
)
{
@@ -24,19 +24,25 @@ public class TraderSptCommand(
@"^spt trader (?<trader>[\w]+) (?<command>rep|spend) (?<quantity>(?!0+)[0-9]+)$"
);
public string GetCommand()
public string Command
{
return "trader";
get
{
return "trader";
}
}
public string GetCommandHelp()
public string CommandHelp
{
return "spt trader \n ======== \n Sets the reputation or money spent to the input quantity through the message system.\n\n\tspt trader [trader] rep [quantity]\n\t\tEx: spt trader prapor rep 2\n\n\tspt trader [trader] spend [quantity]\n\t\tEx: spt trader therapist spend 1000000";
get
{
return "spt trader \n ======== \n Sets the reputation or money spent to the input quantity through the message system.\n\n\tspt trader [trader] rep [quantity]\n\t\tEx: spt trader prapor rep 2\n\n\tspt trader [trader] spend [quantity]\n\t\tEx: spt trader therapist spend 1000000";
}
}
public ValueTask<string> PerformAction(
UserDialogInfo commandHandler,
string sessionId,
MongoId sessionId,
SendMessageRequest request
)
{
@@ -1,4 +1,5 @@
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
namespace SPTarkov.Server.Core.Helpers.Dialogue;
@@ -11,5 +12,5 @@ public interface IDialogueChatBot
/// Handles messages for the chatbot. If a message can't be handled, <see cref="string.Empty"/> should be used.
/// </summary>
/// <returns>The response of the bot, or <see cref="string.Empty"/> if the request could not be handled.</returns>
public ValueTask<string> HandleMessage(string sessionId, SendMessageRequest request);
public ValueTask<string> HandleMessage(MongoId sessionId, SendMessageRequest request);
}
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Services;
@@ -21,7 +22,7 @@ public class AreYouABotMessageHandler(MailSendService _mailSendService, RandomUt
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums;
@@ -20,7 +21,7 @@ public class DisplayLocationsHandler(MailSendService _mailSendService) : IChatMe
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums;
@@ -20,7 +21,7 @@ public class DisplaySkillNamesHandler(MailSendService _mailSendService) : IChatM
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Services;
@@ -19,7 +20,7 @@ public class FishMessageHandler(MailSendService _mailSendService) : IChatMessage
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums;
@@ -26,7 +27,7 @@ public class ForceChristmasMessageHandler(
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums;
@@ -26,7 +27,7 @@ public class ForceHalloweenMessageHandler(
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums;
@@ -30,7 +31,7 @@ public class ForceSnowMessageHandler(
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums;
@@ -30,7 +31,7 @@ public class ForceSummerMessageHandler(
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Services;
@@ -21,7 +22,7 @@ public class GarbageMessageHandler(MailSendService _mailSendService, RandomUtil
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -33,7 +33,7 @@ public class GiveMeSpaceMessageHandler(
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,5 +1,6 @@
using System.Collections.Frozen;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
@@ -33,7 +34,7 @@ public class HelloMessageHandler(MailSendService _mailSendService, RandomUtil _r
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -79,7 +80,7 @@ public class HelloMessageHandler(MailSendService _mailSendService, RandomUtil _r
public string PerformAction(
UserDialogInfo commandHandler,
string sessionId,
MongoId sessionId,
SendMessageRequest request
)
{
@@ -1,3 +1,4 @@
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
@@ -10,7 +11,7 @@ public interface IChatMessageHandler
public bool CanHandle(string? message);
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Services;
@@ -21,7 +22,7 @@ public class LoveYouChatMessageHandler(MailSendService _mailSendService, RandomU
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Services;
@@ -21,7 +22,7 @@ public class NikitaMessageHandler(MailSendService _mailSendService, RandomUtil _
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
@@ -31,7 +32,7 @@ public class SendGiftMessageHandler(
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData sender,
object? extraInfo = null
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Services;
@@ -21,7 +22,7 @@ public class SptMessageHandler(MailSendService _mailSendService, RandomUtil _ran
}
public void Process(
string sessionId,
MongoId sessionId,
UserDialogInfo sptFriendUser,
PmcData? sender,
object? extraInfo = null
@@ -1,11 +1,10 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers.Dialog.Commando;
using SPTarkov.Server.Core.Helpers.Dialogue.SPTFriend.Commands;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Dialog;
using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
@@ -40,7 +39,7 @@ public class SptDialogueChatBot(
};
}
public ValueTask<string> HandleMessage(string sessionId, SendMessageRequest request)
public ValueTask<string> HandleMessage(MongoId sessionId, SendMessageRequest request)
{
var sender = _profileHelper.GetPmcProfile(sessionId);
var sptFriendUser = GetChatBot();
@@ -84,7 +83,7 @@ public class SptDialogueChatBot(
return "Unknown command.";
}
protected ValueTask<string> SendPlayerHelpMessage(string sessionId, SendMessageRequest request)
protected ValueTask<string> SendPlayerHelpMessage(MongoId sessionId, SendMessageRequest request)
{
_mailSendService.SendUserMessageToPlayer(
sessionId,