From cb5d2b7e858f2d7cb719d68cdb1b9b5201d73dcf Mon Sep 17 00:00:00 2001 From: Chris Darnell Date: Tue, 20 Apr 2021 19:37:41 -0700 Subject: [PATCH] Fixed duplicate command issue. Commented Commands.cs file. --- StarsiegeBot/BotSettings.cs | 2 + StarsiegeBot/Commands.cs | 87 ++++++++++++++++++++++++++++---- StarsiegeBot/PrefixManagement.cs | 1 + StarsiegeBot/RoleManagement.cs | 23 ++++++++- 4 files changed, 102 insertions(+), 11 deletions(-) diff --git a/StarsiegeBot/BotSettings.cs b/StarsiegeBot/BotSettings.cs index f94eaf1..fab7e33 100644 --- a/StarsiegeBot/BotSettings.cs +++ b/StarsiegeBot/BotSettings.cs @@ -90,5 +90,7 @@ namespace StarsiegeBot public List Prefixes { get; set; } public Dictionary> SelfRoles { get; set; } public Dictionary> LevelRoles { get; set; } + + public List hiddenRolesList { get; set; } } } diff --git a/StarsiegeBot/Commands.cs b/StarsiegeBot/Commands.cs index 4911c4f..1c4ede7 100644 --- a/StarsiegeBot/Commands.cs +++ b/StarsiegeBot/Commands.cs @@ -13,8 +13,10 @@ namespace StarsiegeBot { class Commands : BaseCommandModule { + // this class depends a lot on the random stuff. so make it class level. private readonly Random rnd = new Random(); + // start: neo wanted this shit.... private string[] insult = { "> {0} slaps {1} around a bit with a large trout.", "> {0} puts a jellyfish on {1}'s head.", @@ -31,9 +33,11 @@ namespace StarsiegeBot return insult[insultIndex++ % insult.Length]; } } + // end: neo's shit. public Commands() { + // Let the console know we've loaded basic commands. Console.WriteLine("Basic Commands Loaded"); } @@ -42,38 +46,57 @@ namespace StarsiegeBot [Cooldown(1, 2, CooldownBucketType.Guild)] public async Task Dice(CommandContext ctx, [RemainingText,Description("XdY")] String throwing = "d") { + // let the end user know the bot is doing something... await ctx.TriggerTypingAsync(); + // in case the end user used caps, lower them. throwing = throwing.ToLower(); + // set some int items. int totalResult = 0; int totalDie = 0; + // set the results to an empty string. string overallResults = String.Empty; + // Prep the regex statement. Regex regex = new Regex("(\\d{0,})(d)(-{0,1}\\d{0,})"); + // Get a collection of regex matches from the dice we're through. MatchCollection matches = regex.Matches(throwing); + // For each match do this. foreach (Match m in matches) { + // if we have a match, do some stuff! if (m.Success) { + // set an empty string, set a counter. string dieResults = String.Empty; int dieResult = 0; + // attempt to get the number of dice being "thrown" and the number of sides those die have. bool volTest = int.TryParse(m.Groups[1].ToString(), out int volume); bool sideTest = int.TryParse(m.Groups[3].ToString(), out int sides); + // They failed? Make some stuff up... We default to a 1d6 throw. if (!volTest) volume = 1; if (!sideTest) sides = 6; + // for each die we roll, get a result. for (int i = 0; i < volume; i++) { + // increase the total dice thrown. ++totalDie; + // this is the result. + // This line looks weird, I know, so here is what is going on. If the number of sides is negative, we adjust for that. + // since the rnd.Next is inclusive, exclusive, we have to adjust for that. int roll = rnd.Next(Math.Min(1, sides), Math.Max(sides + 1, 0)); + // do we have our first result? No, make it! Store the results in a string to show the end user. if (dieResults.Equals(String.Empty)) dieResults = roll.ToString(); else dieResults += $", {roll}"; + // Increase total results for both All Dice (totalResult) and for this specific set of die (dieResult) totalResult += roll; dieResult += roll; } + // If the end user is rolling more than 10 of any kind of die, dont show the results of the rolls. Just if(volume < 11) dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2) + " Results: " + dieResults; else @@ -81,6 +104,7 @@ namespace StarsiegeBot overallResults += "```" + dieResults + "```\r\n"; } } + // If we roll more than one kinda dice for them, give them extra info. if (matches.Count != 1) await ctx.RespondAsync(overallResults + "\r\nTotal: " + totalResult + " Avg: " + Math.Round(totalResult * 1.0 / totalDie * 1.0, 2)); else @@ -91,43 +115,56 @@ namespace StarsiegeBot [Description("Random number generator.")] public async Task Random(CommandContext ctx, [Description("Lowest number choice. (Inclusive)")] int min, [Description("Highest Number Choice. (Inclusive)")] int max) { - max += 1; - var rnd = new Random(); + await ctx.TriggerTypingAsync(); + // Find which number given is lower, which is higher. + // since rnd.Nex is inclusive, exclusive, increase the max by one. int i = Math.Min(min, max); - int a = Math.Max(min, max); - + int a = Math.Max(min, max) + 1; + // output the results await ctx.RespondAsync($"🎲 Your random number is: {rnd.Next(i, a)}"); } + [Command("random")] public async Task Random(CommandContext ctx) { + await ctx.TriggerTypingAsync(); + // some one didn't read the HELP file on Random. Explain it to them. await ctx.RespondAsync($"Gives you a random number between