Start chatBots
This commit is contained in:
@@ -2,34 +2,67 @@
|
||||
using Core.Helpers.Dialog.Commando.SptCommands;
|
||||
using Core.Models.Eft.Dialog;
|
||||
using Core.Models.Eft.Profile;
|
||||
using Core.Models.Spt.Config;
|
||||
using Core.Servers;
|
||||
using Core.Services;
|
||||
|
||||
namespace Core.Helpers.Dialog.Commando;
|
||||
|
||||
[Injectable]
|
||||
public class SptCommandoCommands : IChatCommand
|
||||
{
|
||||
protected List<ISptCommand> _sptCommands;
|
||||
protected LocalisationService _localisationService;
|
||||
public SptCommandoCommands(
|
||||
ConfigServer configServer,
|
||||
LocalisationService localisationService,
|
||||
IEnumerable<ISptCommand> sptCommands
|
||||
)
|
||||
{
|
||||
_sptCommands = sptCommands.ToList();
|
||||
_localisationService = localisationService;
|
||||
var coreConfigs = configServer.GetConfig<CoreConfig>();
|
||||
var commandoId = coreConfigs.Features?.ChatbotFeatures.Ids.GetValueOrDefault("commando");
|
||||
if (!(coreConfigs.Features.ChatbotFeatures.CommandoFeatures.GiveCommandEnabled &&
|
||||
coreConfigs.Features.ChatbotFeatures.EnabledBots.ContainsKey(commandoId)))
|
||||
{
|
||||
var giveCommand = _sptCommands.FirstOrDefault(x => x.GetCommand().ToLower() == "give");
|
||||
_sptCommands.Remove(giveCommand);
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterSptCommandoCommand(ISptCommand command)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (_sptCommands.Any((c) => c.GetCommand() == command.GetCommand())) {
|
||||
throw new Exception(
|
||||
_localisationService.GetText(
|
||||
"chat-unable_to_register_command_already_registered",
|
||||
command.GetCommand()
|
||||
)
|
||||
);
|
||||
}
|
||||
_sptCommands.Add(command);
|
||||
}
|
||||
|
||||
|
||||
public string GetCommandPrefix()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return "spt";
|
||||
}
|
||||
|
||||
public string GetCommandHelp(string command)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _sptCommands.FirstOrDefault(c => c.GetCommand() == command)?.GetCommandHelp();
|
||||
}
|
||||
|
||||
public List<string> GetCommands()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _sptCommands.Select(c => c.GetCommand()).ToList();
|
||||
}
|
||||
|
||||
public string Handle(string command, UserDialogInfo commandHandler, string sesssionId, SendMessageRequest request)
|
||||
public string Handle(string command, UserDialogInfo commandHandler, string sessionId, SendMessageRequest request)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _sptCommands
|
||||
.Find((c) => c.GetCommand() == command)
|
||||
.PerformAction(commandHandler, sessionId, request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ public class CommandoDialogChatBot(
|
||||
|
||||
protected string GetUnrecognizedCommandMessage()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return "I'm sorry soldier, I don't recognize the command you are trying to use! Type \"help\" to see available commands.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ namespace Core.Helpers.Dialogue;
|
||||
public interface IDialogueChatBot
|
||||
{
|
||||
public UserDialogInfo GetChatBot();
|
||||
public string HandleMessage(string sessionId, SendMessageRequest request);
|
||||
public string? HandleMessage(string sessionId, SendMessageRequest request);
|
||||
}
|
||||
|
||||
@@ -7,18 +7,26 @@ using Core.Models.Spt.Config;
|
||||
using Core.Models.Utils;
|
||||
using Core.Servers;
|
||||
using Core.Services;
|
||||
using Core.Utils;
|
||||
|
||||
namespace Core.Helpers.Dialogue;
|
||||
|
||||
[Injectable]
|
||||
public class SptDialogueChatBot(
|
||||
ISptLogger<AbstractDialogChatBot> _logger,
|
||||
MailSendService mailSendService,
|
||||
IEnumerable<IChatCommand> chatCommands,
|
||||
ConfigServer configServer
|
||||
) : AbstractDialogChatBot(_logger, mailSendService, chatCommands)
|
||||
MailSendService _mailSendService,
|
||||
IEnumerable<IChatCommand> _chatCommands,
|
||||
ConfigServer _configServer,
|
||||
ProfileHelper _profileHelper,
|
||||
RandomUtil _randomUtil,
|
||||
SeasonalEventService _seasonalEventService,
|
||||
GiftService _giftService,
|
||||
LocalisationService _localisationService
|
||||
) : AbstractDialogChatBot(_logger, _mailSendService, _chatCommands)
|
||||
{
|
||||
protected CoreConfig _coreConfig = configServer.GetConfig<CoreConfig>();
|
||||
protected CoreConfig _coreConfig = _configServer.GetConfig<CoreConfig>();
|
||||
protected WeatherConfig _weatherConfig = _configServer.GetConfig<WeatherConfig>();
|
||||
protected List<string> _listOfMessages = ["hello", "hi", "sup", "yo", "hey"];
|
||||
|
||||
public override UserDialogInfo GetChatBot()
|
||||
{
|
||||
@@ -37,8 +45,194 @@ public class SptDialogueChatBot(
|
||||
};
|
||||
}
|
||||
|
||||
public string HandleMessage(string sessionId, SendMessageRequest request)
|
||||
public string? HandleMessage(string sessionId, SendMessageRequest request)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var sender = _profileHelper.GetPmcProfile(sessionId);
|
||||
|
||||
var sptFriendUser = GetChatBot();
|
||||
var requestInput = request.Text.ToLower();
|
||||
|
||||
// only check if entered text is gift code when feature enabled
|
||||
if (_coreConfig.Features.ChatbotFeatures.SptFriendGiftsEnabled) {
|
||||
var giftSent = _giftService.SendGiftToPlayer(sessionId, request.Text);
|
||||
if (giftSent == GiftSentResult.SUCCESS) {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([
|
||||
"Hey! you got the right code!",
|
||||
"A secret code, how exciting!",
|
||||
"You found a gift code!",
|
||||
"A gift code! incredible",
|
||||
"A gift! what could it be!",
|
||||
]),
|
||||
[],
|
||||
null
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (giftSent == GiftSentResult.FAILED_GIFT_ALREADY_RECEIVED) {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue(["Looks like you already used that code", "You already have that!!"]),
|
||||
[],
|
||||
null
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (requestInput.Contains("love you")) {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([
|
||||
"That's quite forward but i love you too in a purely chatbot-human way",
|
||||
"I love you too buddy :3!",
|
||||
"uwu",
|
||||
$"love you too {sender?.Info?.Nickname}",
|
||||
]),
|
||||
[],
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
if (requestInput == "spt") {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue(["Its me!!", "spt? i've heard of that project"]),
|
||||
[],
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
if (requestInput == "fish") {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue(["blub"]),
|
||||
[],
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
if (_listOfMessages.Contains(requestInput)) {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([
|
||||
"Howdy",
|
||||
"Hi",
|
||||
"Greetings",
|
||||
"Hello",
|
||||
"bonjor",
|
||||
"Yo",
|
||||
"Sup",
|
||||
"Heyyyyy",
|
||||
"Hey there",
|
||||
$"Hello {sender?.Info?.Nickname}",
|
||||
]),
|
||||
[], null
|
||||
);
|
||||
}
|
||||
|
||||
if (requestInput == "nikita") {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([
|
||||
"I know that guy!",
|
||||
"Cool guy, he made EFT!",
|
||||
"Legend",
|
||||
"Remember when he said webel-webel-webel-webel, classic Nikita moment",
|
||||
]), [], null
|
||||
);
|
||||
}
|
||||
|
||||
if (requestInput == "are you a bot") {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue(["beep boop", "**sad boop**", "probably", "sometimes", "yeah lol"]),
|
||||
[], null
|
||||
);
|
||||
}
|
||||
|
||||
if (requestInput == "itsonlysnowalan") {
|
||||
_weatherConfig.OverrideSeason = Season.WINTER;
|
||||
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([_localisationService.GetText("chatbot-snow_enabled")]), [], null
|
||||
);
|
||||
}
|
||||
|
||||
if (requestInput == "givemesunshine") {
|
||||
_weatherConfig.OverrideSeason = Season.SUMMER;
|
||||
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([_localisationService.GetText("chatbot-summer_enabled")]), [], null
|
||||
);
|
||||
}
|
||||
|
||||
if (requestInput == "veryspooky") {
|
||||
var enableEventResult = _seasonalEventService.ForceSeasonalEvent(SeasonalEventType.Halloween);
|
||||
if (enableEventResult) {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([
|
||||
_localisationService.GetText("chatbot-forced_event_enabled", SeasonalEventType.Halloween)
|
||||
]), [], null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (requestInput == "hohoho") {
|
||||
var enableEventResult = _seasonalEventService.ForceSeasonalEvent(SeasonalEventType.Christmas);
|
||||
if (enableEventResult) {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([
|
||||
_localisationService.GetText("chatbot-forced_event_enabled", SeasonalEventType.Christmas)
|
||||
]), [], null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (requestInput == "givemespace") {
|
||||
var stashRowGiftId = "StashRows";
|
||||
var maxGiftsToSendCount = _coreConfig.Features.ChatbotFeatures.CommandUseLimits[stashRowGiftId] ?? 5;
|
||||
if (_profileHelper.PlayerHasRecievedMaxNumberOfGift(sessionId, stashRowGiftId, maxGiftsToSendCount)) {
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_localisationService.GetText("chatbot-cannot_accept_any_more_of_gift"), [], null
|
||||
);
|
||||
} else {
|
||||
_profileHelper.AddStashRowsBonusToProfile(sessionId, 2);
|
||||
|
||||
_mailSendService.SendUserMessageToPlayer(
|
||||
sessionId,
|
||||
sptFriendUser,
|
||||
_randomUtil.GetArrayValue([
|
||||
_localisationService.GetText("chatbot-added_stash_rows_please_restart"),
|
||||
]), [], null
|
||||
);
|
||||
|
||||
_profileHelper.FlagGiftReceivedInProfile(sessionId, stashRowGiftId, maxGiftsToSendCount);
|
||||
}
|
||||
}
|
||||
|
||||
return request.DialogId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ public class UtilityHelper
|
||||
{
|
||||
public List<T> ArrayIntersect<T>(List<T> a, List<T> b)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//a.Intersect(x => b.Contains(x)).ToList();
|
||||
// gives error Delegate type could not be infered
|
||||
|
||||
return a.Where(x => b.Contains(x)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public record ChatbotFeatures
|
||||
public CommandoFeatures CommandoFeatures { get; set; }
|
||||
|
||||
[JsonPropertyName("commandUseLimits")]
|
||||
public Dictionary<string, int> CommandUseLimits { get; set; }
|
||||
public Dictionary<string, int?> CommandUseLimits { get; set; }
|
||||
|
||||
[JsonPropertyName("ids")]
|
||||
public Dictionary<string, string> Ids { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user