Implemented skeleton of chatbot init

This commit is contained in:
Chomp
2025-01-18 12:39:42 +00:00
parent 2d0d8d6d0b
commit 8d632e9bb2
4 changed files with 142 additions and 25 deletions
+52 -13
View File
@@ -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<DialogueController> _logger;
protected TimeUtil _timeUtil;
protected DialogueHelper _dialogueHelper;
protected ProfileHelper _profileHelper;
protected ConfigServer _configServer;
protected SaveServer _saveServer;
protected LocalisationService _localisationService;
protected List<IDialogueChatBot> _dialogueChatBots;
protected CoreConfig _coreConfig;
public DialogueController(
ISptLogger<DialogueController> logger,
TimeUtil timeUtil,
DialogueHelper dialogueHelper,
ProfileHelper profileHelper,
ConfigServer configServer,
SaveServer saveServer)
SaveServer saveServer,
LocalisationService localisationService,
IEnumerable<IDialogueChatBot> dialogueChatBots)
{
_logger = logger;
_timeUtil = timeUtil;
_dialogueHelper = dialogueHelper;
_profileHelper = profileHelper;
_configServer = configServer;
_saveServer = saveServer;
_localisationService = localisationService;
_dialogueChatBots = dialogueChatBots.ToList();
_coreConfig = _configServer.GetConfig<CoreConfig>();
}
@@ -38,19 +51,25 @@ public class DialogueController
///
/// </summary>
/// <param name="chatBot"></param>
/*
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);
}
*/
/// <summary>
/// Handle onUpdate spt event
/// </summary>
public void Update()
{
throw new NotImplementedException();
var profiles = _saveServer.GetProfiles();
foreach (var kvp in profiles) {
RemoveExpiredItemsFromMessages(kvp.Key);
}
}
/// <summary>
@@ -94,7 +113,7 @@ public class DialogueController
var activeBots = new List<UserDialogInfo>();
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
/// <summary>
/// Get the users involved in a dialog (player + other party)
/// </summary>
/// <param name="dialogue">The dialog to check for users</param>
/// <param name="dialog">The dialog to check for users</param>
/// <param name="messageType">What type of message is being sent</param>
/// <param name="sessionId">Player id</param>
/// <returns>UserDialogInfo list</returns>
@@ -352,7 +369,9 @@ public class DialogueController
/// <param name="sessionId">Session id</param>
private void RemoveExpiredItemsFromMessages(string sessionId)
{
throw new NotImplementedException();
foreach (var dialogueId in _dialogueHelper.GetDialogsForProfile(sessionId)) {
RemoveExpiredItemsFromMessage(sessionId, dialogueId.Key);
}
}
/// <summary>
@@ -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)
+17 -5
View File
@@ -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<AbstractDialogChatBot> _logger;
protected MailSendService _mailSendService;
private readonly List<IChatCommand> _chatCommands;
public AbstractDialogChatBot(
ISptLogger<AbstractDialogChatBot> logger,
MailSendService mailSendService,
IEnumerable<IChatCommand> 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();
+34 -3
View File
@@ -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<AbstractDialogChatBot> logger,
MailSendService mailSendService,
ConfigServer configServer,
IEnumerable<IChatCommand> chatCommands): base(logger, mailSendService, chatCommands)
{
throw new NotImplementedException();
_configServer = configServer;
_coreConfig = _configServer.GetConfig<CoreConfig>();
}
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()
+39 -4
View File
@@ -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<AbstractDialogChatBot> _logger;
protected ConfigServer _configServer;
protected CoreConfig _coreConfig;
public SptDialogueChatBot(
ISptLogger<AbstractDialogChatBot> logger,
MailSendService mailSendService,
IEnumerable<IChatCommand> chatCommands,
ConfigServer configServer
) : base(logger, mailSendService, chatCommands)
{
throw new NotImplementedException();
_logger = logger;
_configServer = configServer;
_coreConfig = configServer.GetConfig<CoreConfig>();
}
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)