#pragma warning disable IDE0060 // Remove unused parameter using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace StarsiegeBot { class GameCommands : BaseCommandModule { // Master insult list. private readonly string[] _insultMaster = { "{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 List _insultCopy; public GameCommands() { // Let the console know we've loaded basic commands. Console.WriteLine("Basic Commands Loaded"); _insultCopy = _insultMaster.ToList(); } [Command("8ball"), Aliases(new string[] { "ball", "8" })] [Description("The Magic 8-Ball is a fortune-telling or seeking advice")] public async Task Eightball(CommandContext ctx, [RemainingText, Description("Your question to the 8 ball")] string remainingText = "") { // Load all the traditional 8-Ball answers into an array. string[] results = new string[] { "It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.", "Reply hazy, try again", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no", "Outlook not so good.", "Very doubtful." }; // give the end user the randomly choosen result. await ctx.RespondAsync(StartEmbed(results[Program.rnd.Next(0, results.Length)])); } [Command("about")] [Description("Gives some basic info about the bot")] public async Task About(CommandContext ctx) { // delcare an embed builder. DiscordEmbedBuilder embed = new DiscordEmbedBuilder(); // Title the ebemd with the bot's name and discrim. embed.WithTitle("About " + ctx.Client.CurrentUser.Username + "#" + ctx.Client.CurrentUser.Discriminator); // add the bot's avatar as the Thumbnail. embed.WithThumbnail(ctx.Client.CurrentUser.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 32)); // Add a bit of color... the color from the member's top most role. embed.WithColor(ctx.Member.Color); // output various data abotu the bot. embed.AddField("D#+ Ver", ctx.Client.VersionString, true); embed.AddField("Guild Count", ctx.Client.Guilds.Count.ToString(), true); embed.AddField("Ping", ctx.Client.Ping.ToString(), true); embed.AddField("Shard Count", ctx.Client.ShardCount.ToString(), true); embed.AddField("Shard", ctx.Client.ShardId.ToString(), true); embed.Color = Program.colours[Program.rnd.Next(0, Program.colours.Length)]; // list all the owners of the bot. string owners = ""; foreach (DiscordUser owner in ctx.Client.CurrentApplication.Owners) { owners += owner.Username + "#" + owner.Discriminator + "\r\n"; } embed.AddField("Owner(s)", owners, false); // send the data to the end user. await ctx.RespondAsync(embed); } [Command("coin")] [Description("Flips a coin for ya!")] public async Task Coinflip(CommandContext ctx) { // We're going to randomly select heads or tails and then give it to the user. string[] choices = { "heads", "tails" }; await ctx.RespondAsync(StartEmbed($"The coin landed on... {choices[Program.rnd.Next(0, choices.Length)]}")); } [Command("credits")] [Description("Shows all those that have helped with my bot(s) over the years!")] public async Task Credits(CommandContext ctx) { // just some people that have helped me build the bot. string credits = "```asciidoc\r\n= CREDITS (Outdated) =\r\n" + "• UndeadShadow :: Flood Protection. Keepign teh bot from killing itself, and others.\r\n" + "• Da_D_Master :: For giving me my start in my first couple bots, and being a friendly rival.\r\n" + "• ThinkExist & Bored.com :: Quotes for the Quote Database\r\n" + "• Hanibal, TaMeD, Liquid- :: For awlays proving the points of others.\r\n" + "• Neo :: For all their hard work on all the things I've ever asked about.\r\n" + "• Alias :: For helping me learn how to make IRC bots back in the day.\r\n" + "• Drake, Eledore :: Supporting the development of the bot and supplying code for it.\r\n" + "\r\n```"; await ctx.RespondAsync(credits); } [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... // 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 = Program.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("guilds"), Hidden, RequireOwner] public async Task GimmeServerNames(CommandContext ctx) { string output = ""; foreach (KeyValuePair item in ctx.Client.Guilds) { output += item.Value.Name + "\r\n"; } await ctx.RespondAsync(output); } [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) { // 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(StartEmbed($"🎲 Your random number is: {Program.rnd.Next(i, a)}")); } [Command("random")] public async Task Random(CommandContext ctx) { // some one didn't read the HELP file on Random. Explain it to them. await ctx.RespondAsync(StartEmbed($"Gives you a random number between