diff --git a/KfChatDotNetBot/Commands/Kasino/KasinoEventCommands.cs b/KfChatDotNetBot/Commands/Kasino/KasinoEventCommands.cs new file mode 100644 index 0000000..9db968f --- /dev/null +++ b/KfChatDotNetBot/Commands/Kasino/KasinoEventCommands.cs @@ -0,0 +1,367 @@ +using System.Text.RegularExpressions; +using Humanizer; +using KfChatDotNetBot.Extensions; +using KfChatDotNetBot.Models; +using KfChatDotNetBot.Models.DbModels; +using KfChatDotNetBot.Services; +using KfChatDotNetBot.Settings; +using KfChatDotNetWsClient.Models.Events; + +namespace KfChatDotNetBot.Commands.Kasino; + +public class KasinoNewEventCommand : ICommand +{ + public List Patterns => + [ + new Regex("^kasino event new$", RegexOptions.IgnoreCase), + new Regex(@"^kasino event new (?\w+)$", RegexOptions.IgnoreCase), + new Regex(@"^kasino event new (?\w+) (?.+)$", RegexOptions.IgnoreCase), + ]; + + public string? HelpText => "Create a new kasino event"; + public UserRight RequiredRight => UserRight.TrueAndHonest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + public RateLimitOptionsModel? RateLimitOptions => null; + + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, + CancellationToken ctx) + { + var settings = await SettingsProvider.GetMultipleValuesAsync([ + BuiltIn.Keys.KasinoEventWeightWinAgainstSelectionTime, BuiltIn.Keys.KasinoEventData, + BuiltIn.Keys.KasinoEventTextLengthLimit + ]); + if (!arguments.TryGetValue("type", out var type)) + { + await botInstance.SendChatMessageAsync( + $"{user.FormatUsername()}, not enough arguments. !kasino event new ", + true, autoDeleteAfter: TimeSpan.FromSeconds(60)); + return; + } + + if (!arguments.TryGetValue("description", out var description)) + { + await botInstance.SendChatMessageAsync( + $"{user.FormatUsername()}, not enough arguments. !kasino event new ", + true, autoDeleteAfter: TimeSpan.FromSeconds(60)); + return; + } + + if (description.Length > settings[BuiltIn.Keys.KasinoEventTextLengthLimit].ToType()) + { + await botInstance.SendChatMessageAsync($"{user.FormatUsername()}, your event description / text with a length of " + + $"{description.Length} characters exceeds the limit of " + + $"{settings[BuiltIn.Keys.KasinoEventTextLengthLimit].ToType()} " + + $"characters", true); + return; + } + + var useTimeWeightedPayout = settings[BuiltIn.Keys.KasinoEventWeightWinAgainstSelectionTime].ToBoolean(); + KasinoEventType eventType; + var guide = string.Empty; + if (type.Value.Equals("win-lose", StringComparison.CurrentCultureIgnoreCase)) + { + eventType = KasinoEventType.WinLose; + guide = "Add option: !kasino event {EventId} options add|new [br]" + + "Remove option: !kasino event {EventId} options del|remove