From 8d632e9bb2cc83e6d044adb45b97af16267dec5c Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 18 Jan 2025 12:39:42 +0000 Subject: [PATCH] Implemented skeleton of chatbot init --- Core/Controllers/DialogueController.cs | 65 +++++++++++++++---- .../Helpers/Dialogue/AbstractDialogChatBot.cs | 22 +++++-- .../Helpers/Dialogue/CommandoDialogChatBot.cs | 37 ++++++++++- Core/Helpers/Dialogue/SptDialogueChatBot.cs | 43 ++++++++++-- 4 files changed, 142 insertions(+), 25 deletions(-) diff --git a/Core/Controllers/DialogueController.cs b/Core/Controllers/DialogueController.cs index be362a3d..bc239b4a 100644 --- a/Core/Controllers/DialogueController.cs +++ b/Core/Controllers/DialogueController.cs @@ -2,34 +2,47 @@ using Core.Annotations; using Core.Helpers; using Core.Helpers.Dialogue; using Core.Models.Eft.Dialog; -using Core.Models.Eft.HttpResponse; using Core.Models.Eft.Profile; using Core.Models.Enums; using Core.Models.Spt.Config; +using Core.Models.Utils; using Core.Servers; +using Core.Services; +using Core.Utils; namespace Core.Controllers; [Injectable] public class DialogueController { + protected ISptLogger _logger; + protected TimeUtil _timeUtil; protected DialogueHelper _dialogueHelper; protected ProfileHelper _profileHelper; protected ConfigServer _configServer; protected SaveServer _saveServer; + protected LocalisationService _localisationService; protected List _dialogueChatBots; protected CoreConfig _coreConfig; public DialogueController( + ISptLogger logger, + TimeUtil timeUtil, DialogueHelper dialogueHelper, ProfileHelper profileHelper, ConfigServer configServer, - SaveServer saveServer) + SaveServer saveServer, + LocalisationService localisationService, + IEnumerable dialogueChatBots) { + _logger = logger; + _timeUtil = timeUtil; _dialogueHelper = dialogueHelper; _profileHelper = profileHelper; _configServer = configServer; _saveServer = saveServer; + _localisationService = localisationService; + _dialogueChatBots = dialogueChatBots.ToList(); _coreConfig = _configServer.GetConfig(); } @@ -38,19 +51,25 @@ public class DialogueController /// /// /// - /* - public void RegisterChatBot(DialogueChatBot chatBot) // TODO: this is in with the helper types + public void RegisterChatBot(IDialogueChatBot chatBot) // TODO: this is in with the helper types { - throw new NotImplementedException(); + if (_dialogueChatBots.Any((cb) => cb.GetChatBot().Id == chatBot.GetChatBot().Id)) + { + _logger.Error(_localisationService.GetText("dialog-chatbot_id_already_exists", chatBot.GetChatBot().Id)); + } + _dialogueChatBots.Add(chatBot); } - */ + /// /// Handle onUpdate spt event /// public void Update() { - throw new NotImplementedException(); + var profiles = _saveServer.GetProfiles(); + foreach (var kvp in profiles) { + RemoveExpiredItemsFromMessages(kvp.Key); + } } /// @@ -94,7 +113,7 @@ public class DialogueController var activeBots = new List(); var chatBotConfig = _coreConfig.Features.ChatbotFeatures; - /* + foreach (var bot in _dialogueChatBots) { var botData = bot.GetChatBot(); @@ -102,8 +121,6 @@ public class DialogueController activeBots.Add(botData); } } - TODO: FUCK THESE BOTS STOPPING US GETTING TO THE FUCKING MENU - */ return activeBots; } @@ -155,7 +172,7 @@ public class DialogueController /// /// Get the users involved in a dialog (player + other party) /// - /// The dialog to check for users + /// The dialog to check for users /// What type of message is being sent /// Player id /// UserDialogInfo list @@ -352,7 +369,9 @@ public class DialogueController /// Session id private void RemoveExpiredItemsFromMessages(string sessionId) { - throw new NotImplementedException(); + foreach (var dialogueId in _dialogueHelper.GetDialogsForProfile(sessionId)) { + RemoveExpiredItemsFromMessage(sessionId, dialogueId.Key); + } } /// @@ -364,7 +383,27 @@ public class DialogueController string sessionId, string dialogueId) { - throw new NotImplementedException(); + var dialogs = _dialogueHelper.GetDialogsForProfile(sessionId); + if (!dialogs.TryGetValue(dialogueId, out var dialog)) + { + return; + } + + foreach (var message in dialog.Messages) { + if (MessageHasExpired(message)) + { + message.Items = new MessageItems(); + } + } + } + + /** + * Has a dialog message expired + * @param message Message to check expiry of + * @returns true or false + */ + protected bool MessageHasExpired(Message message) { + return _timeUtil.GetTimeStamp() > message.DateTime + (message.MaxStorageTime ?? 0); } public FriendRequestSendResponse SendFriendRequest(string sessionId, FriendRequestData request) diff --git a/Core/Helpers/Dialogue/AbstractDialogChatBot.cs b/Core/Helpers/Dialogue/AbstractDialogChatBot.cs index f5425e11..4bdfda59 100644 --- a/Core/Helpers/Dialogue/AbstractDialogChatBot.cs +++ b/Core/Helpers/Dialogue/AbstractDialogChatBot.cs @@ -1,18 +1,30 @@ -using Core.Annotations; +using Core.Annotations; using Core.Helpers.Dialog.Commando; using Core.Models.Eft.Dialog; using Core.Models.Eft.Profile; +using Core.Models.Utils; +using Core.Services; namespace Core.Helpers.Dialogue; -[Injectable] -public class AbstractDialogChatBot : IDialogueChatBot +public abstract class AbstractDialogChatBot : IDialogueChatBot { - public UserDialogInfo GetChatBot() + protected ISptLogger _logger; + protected MailSendService _mailSendService; + private readonly List _chatCommands; + + public AbstractDialogChatBot( + ISptLogger logger, + MailSendService mailSendService, + IEnumerable chatCommands) { - throw new NotImplementedException(); + _logger = logger; + _mailSendService = mailSendService; + _chatCommands = chatCommands.ToList(); } + public abstract UserDialogInfo GetChatBot(); + public string HandleMessage(string sessionId, SendMessageRequest request) { throw new NotImplementedException(); diff --git a/Core/Helpers/Dialogue/CommandoDialogChatBot.cs b/Core/Helpers/Dialogue/CommandoDialogChatBot.cs index 4635d536..e1ccd1bc 100644 --- a/Core/Helpers/Dialogue/CommandoDialogChatBot.cs +++ b/Core/Helpers/Dialogue/CommandoDialogChatBot.cs @@ -1,14 +1,45 @@ -using Core.Annotations; +using Core.Annotations; +using Core.Helpers.Dialog.Commando; using Core.Models.Eft.Profile; +using Core.Models.Enums; +using Core.Models.Spt.Config; +using Core.Models.Utils; +using Core.Servers; +using Core.Services; namespace Core.Helpers.Dialogue; [Injectable] public class CommandoDialogChatBot : AbstractDialogChatBot { - public UserDialogInfo GetChatBot() + protected ConfigServer _configServer; + protected CoreConfig _coreConfig; + + public CommandoDialogChatBot( + ISptLogger logger, + MailSendService mailSendService, + ConfigServer configServer, + IEnumerable chatCommands): base(logger, mailSendService, chatCommands) { - throw new NotImplementedException(); + _configServer = configServer; + _coreConfig = _configServer.GetConfig(); + } + + public override UserDialogInfo GetChatBot() + { + return new UserDialogInfo + { + Id = _coreConfig.Features.ChatbotFeatures.Ids["commando"], + Aid = 1234566, + Info = new UserDialogDetails + { + Level = 1, + MemberCategory = MemberCategory.DEVELOPER, + SelectedMemberCategory = MemberCategory.DEVELOPER, + Nickname = _coreConfig.SptFriendNickname, + Side = "Usec" + } + }; } protected string GetUnrecognizedCommandMessage() diff --git a/Core/Helpers/Dialogue/SptDialogueChatBot.cs b/Core/Helpers/Dialogue/SptDialogueChatBot.cs index a9e1a100..c67ebad9 100644 --- a/Core/Helpers/Dialogue/SptDialogueChatBot.cs +++ b/Core/Helpers/Dialogue/SptDialogueChatBot.cs @@ -1,15 +1,50 @@ -using Core.Annotations; +using Core.Annotations; +using Core.Helpers.Dialog.Commando; using Core.Models.Eft.Dialog; using Core.Models.Eft.Profile; +using Core.Models.Enums; +using Core.Models.Spt.Config; +using Core.Models.Utils; +using Core.Servers; +using Core.Services; namespace Core.Helpers.Dialogue; [Injectable] -public class SptDialogueChatBot : IDialogueChatBot +public class SptDialogueChatBot : AbstractDialogChatBot { - public UserDialogInfo GetChatBot() + protected ISptLogger _logger; + protected ConfigServer _configServer; + protected CoreConfig _coreConfig; + + public SptDialogueChatBot( + ISptLogger logger, + MailSendService mailSendService, + IEnumerable chatCommands, + ConfigServer configServer + ) : base(logger, mailSendService, chatCommands) { - throw new NotImplementedException(); + _logger = logger; + _configServer = configServer; + + _coreConfig = configServer.GetConfig(); + } + + public override UserDialogInfo GetChatBot() + { + return new UserDialogInfo + { + Id = _coreConfig.Features.ChatbotFeatures.Ids["spt"], + Aid = 1234566, + Info = new UserDialogDetails + { + Level = 1, + MemberCategory = MemberCategory.DEVELOPER, + SelectedMemberCategory = MemberCategory.DEVELOPER, + Nickname = _coreConfig.SptFriendNickname, + Side = "Usec" + } + }; } public string HandleMessage(string sessionId, SendMessageRequest request)