using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; using DSharpPlus.VoiceNext; using System.Text.RegularExpressions; using System.Linq; namespace StarsiegeBot { class Commands : BaseCommandModule { private readonly Random rnd = new Random(); 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]; } } public 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.User)] public async Task Dice(CommandContext ctx, [RemainingText,Description("XdY")] String throwing = "d") { await ctx.TriggerTypingAsync(); throwing = throwing.ToLower(); int totalResult = 0; int totalDie = 0; string overallResults = String.Empty; Regex regex = new Regex("(\\d{0,})(d)(-{0,1}\\d{0,})"); MatchCollection matches = regex.Matches(throwing); foreach (Match m in matches) { if (m.Success) { string dieResults = String.Empty; int dieResult = 0; bool volTest = int.TryParse(m.Groups[1].ToString(), out int volume); bool sideTest = int.TryParse(m.Groups[3].ToString(), out int sides); if (!volTest) volume = 1; if (!sideTest) sides = 6; for (int i = 0; i < volume; i++) { ++totalDie; int roll = rnd.Next(Math.Min(1, sides), Math.Max(sides + 1, 0)); if (dieResults.Equals(String.Empty)) dieResults = roll.ToString(); else dieResults += $", {roll}"; totalResult += roll; dieResult += roll; } 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 (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) { max += 1; var rnd = new Random(); int i = Math.Min(min, max); int a = Math.Max(min, max); await ctx.RespondAsync($"🎲 Your random number is: {rnd.Next(i, a)}"); } [Command("random")] public async Task Random(CommandContext ctx) { await ctx.RespondAsync($"Gives you a random number between