From 6cdb7b6702c470078160015baa7dfcd98807823b Mon Sep 17 00:00:00 2001 From: cohlexyz <142505474+cohlexyz@users.noreply.github.com> Date: Fri, 9 Jan 2026 03:00:36 +0100 Subject: [PATCH] Add !8ball command (#35) --- KfChatDotNetBot/Commands/EightballCommand.cs | 123 +++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 KfChatDotNetBot/Commands/EightballCommand.cs diff --git a/KfChatDotNetBot/Commands/EightballCommand.cs b/KfChatDotNetBot/Commands/EightballCommand.cs new file mode 100644 index 0000000..1c73b90 --- /dev/null +++ b/KfChatDotNetBot/Commands/EightballCommand.cs @@ -0,0 +1,123 @@ +using System.Text.RegularExpressions; +using KfChatDotNetBot; +using KfChatDotNetBot.Commands; +using KfChatDotNetBot.Models; +using KfChatDotNetBot.Models.DbModels; +using KfChatDotNetWsClient.Models.Events; +using RandN; +using RandN.Compat; + +public class EightBallCommand : ICommand +{ + public List Patterns => [ + new Regex("^8ball", RegexOptions.IgnoreCase) + ]; + public string? HelpText => "Ask the magic 8-ball a question"; + public UserRight RequiredRight => UserRight.Guest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + public RateLimitOptionsModel? RateLimitOptions => null; + + private static readonly string[] AnswersYes = [ + "Yes, definitely.", + "It is certain.", + "Yes, in due time.", + "Yes, but only if you believe.", + "It is decidedly so.", + "Yes, but be cautious.", + "Yes, but only if you try hard enough.", + "Yes, but only if you ask nicely.", + "Yes, but only if you bribe me.", + "Without a doubt.", + "You may rely on it.", + "As I see it, yes.", + "Most likely.", + "Outlook good.", + "Signs point to yes.", + "Absolutely.", + "Certainly.", + "The stars say yes.", + "The answer is yes.", + "Definitely yes.", + "Yes, yes, yes!", + "Affirmative.", + "By all means.", + "The universe agrees.", + "Chances are good.", + "It's a sure thing.", + "You can count on it.", + "The future looks bright.", + "Yes, go for it.", + "Yes, the answer is clear.", + ]; + + private static readonly string[] AnswersUncertain = [ + "Concentrate and ask again.", + "Ask again later.", + "Cannot predict now.", + "Reply hazy, try again.", + "Better not tell you now.", + "It's unclear at the moment.", + "I'm not sure.", + "Maybe...", + "That's a mystery.", + "The answer is unclear.", + "It's hard to say.", + "I'm undecided.", + "The future is uncertain.", + "It's anyone's guess.", + "I can't tell you right now.", + "The signs are unclear.", + ]; + + private static readonly string[] AnswersNo = [ + "No, absolutely not.", + "No, never.", + "No, the answer is no.", + "No, the universe says no.", + "No, the stars are not aligned.", + "My reply is no.", + "Outlook not so good.", + "Don't count on it.", + "My sources say no.", + "Very doubtful.", + "Definitely not.", + "No way.", + "Not in a million years.", + "The answer is a resounding no.", + "Chances are slim to none.", + "The universe says no.", + "Negative.", + "Absolutely not.", + "I don't think so.", + "The signs point to no.", + "Certainly not.", + "I wouldn't bet on it.", + "The answer is no.", + "No chance.", + "Not likely.", + "The outlook is bleak." + ]; + + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) + { + var random = RandomShim.Create(StandardRng.Create()); + string response; + + var outcome = random.Next(0, 110); + + if (outcome < 50) + { + response = AnswersYes[random.Next(AnswersYes.Length)]; + } + else if (outcome < 100) + { + response = AnswersNo[random.Next(AnswersNo.Length)]; + } + else + { + response = AnswersUncertain[random.Next(AnswersUncertain.Length)]; + } + + await botInstance.SendChatMessageAsync($"@{user.KfUsername}, {response}", true); + } +} \ No newline at end of file