#pragma warning disable IDE0060 // Remove unused parameter using System; using System.Threading.Tasks; using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; using System.Text.RegularExpressions; using System.Linq; 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.", "> {0} slaps {1} around a bit with the mustache of Caanon.", "> {0} slaps {1} around a bit with a questionable rubber object.", "> {0} slaps {1} around a bit with a rubber chicken." }; private uint insultIndex; public string Insult { get { if (insultIndex >= insult.Length) { insultIndex = 0; } 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"); } [Command("dice"), Aliases("r", "d", "roll")] [Description("A classic dice throwing command. Limited to 1 use per 2 seconds. Format: d ")] [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 dieResults = $"{volume}d{sides}: Total: " + dieResult + " Avg: " + Math.Round(dieResult * 1.0 / volume, 2); 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 await ctx.RespondAsync(overallResults); } [Command("random")] [Description("Random number generator.")] public async Task Random(CommandContext ctx, [Description("Lowest number choice. (Inclusive)")] int min, [Description("Highest Number Choice. (Inclusive)")] int max) { 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) + 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