From 315526c32bae958ecc802bcd8ce4e995e870a330 Mon Sep 17 00:00:00 2001 From: dboerlage Date: Wed, 12 Apr 2017 22:43:52 +0200 Subject: [PATCH] Geekbot logo and roll command --- Geekbot.net/Modules/Ping.cs | 1 - Geekbot.net/Modules/Roll.cs | 25 +++++++++++++++++++++++++ Geekbot.net/Program.cs | 22 +++++++++++----------- 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 Geekbot.net/Modules/Roll.cs diff --git a/Geekbot.net/Modules/Ping.cs b/Geekbot.net/Modules/Ping.cs index 4ab9a4c..86f0507 100644 --- a/Geekbot.net/Modules/Ping.cs +++ b/Geekbot.net/Modules/Ping.cs @@ -8,7 +8,6 @@ namespace Geekbot.net.Modules [Command("ping"), Summary("Pong.")] public async Task Say() { - // ReplyAsync is a method on ModuleBase await ReplyAsync("Pong"); } } diff --git a/Geekbot.net/Modules/Roll.cs b/Geekbot.net/Modules/Roll.cs new file mode 100644 index 0000000..a6df75b --- /dev/null +++ b/Geekbot.net/Modules/Roll.cs @@ -0,0 +1,25 @@ +using System; +using System.Threading.Tasks; +using Discord.Commands; + +namespace Geekbot.net.Modules +{ + public class Roll : ModuleBase + { + [Command("roll"), Summary("Roll a number between 1 and 100.")] + public async Task RollCommand() + { + var rnd = new Random(); + var number = rnd.Next(1, 100); + await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); + } + + [Command("dice"), Summary("Roll a number between 1 and 100.")] + public async Task DiceCommand() + { + var rnd = new Random(); + var number = rnd.Next(1, 6); + await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index 3fa8bbb..e230556 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -15,7 +15,13 @@ namespace Geekbot.net private static void Main(string[] args) { - Console.WriteLine("Staring..."); + Console.WriteLine(" ____ _____ _____ _ ______ ___ _____"); + Console.WriteLine(" / ___| ____| ____| |/ / __ ) / _ \\_ _|"); + Console.WriteLine("| | _| _| | _| | ' /| _ \\| | | || |"); + Console.WriteLine("| |_| | |___| |___| . \\| |_) | |_| || |"); + Console.WriteLine(" \\____|_____|_____|_|\\_\\____/ \\___/ |_|"); + Console.WriteLine("========================================="); + Console.WriteLine("Starting..."); new Program().MainAsync().GetAwaiter().GetResult(); } @@ -24,39 +30,33 @@ namespace Geekbot.net client = new DiscordSocketClient(); commands = new CommandService(); - string token = "MTgxMDkyOTgxMDUzNDU2Mzg0.C8_UTw.PvXLAVOTccbrWKLMeyvN9WqRPlU"; + const string token = "MTgxMDkyOTgxMDUzNDU2Mzg0.C8_UTw.PvXLAVOTccbrWKLMeyvN9WqRPlU"; map = new DependencyMap(); await InstallCommands(); - + Console.WriteLine("Connecting to Discord..."); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); + Console.WriteLine("Done and ready for use...\n"); await Task.Delay(-1); } public async Task InstallCommands() { - // Hook the MessageReceived Event into our Command Handler client.MessageReceived += HandleCommand; client.MessageReceived += HandleMessageReceived; - // Discover all of the commands in this assembly and load them. + await commands.AddModulesAsync(Assembly.GetEntryAssembly()); } public async Task HandleCommand(SocketMessage messageParam) { - // Don't process the command if it was a System Message var message = messageParam as SocketUserMessage; if (message == null) return; - // Create a number to track where the prefix ends and the command begins int argPos = 0; - // Determine if the message is a command, based on if it starts with '!' or a mention prefix if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return; - // Create a Command Context var context = new CommandContext(client, message); - // Execute the command. (result does not indicate a return value, - // rather an object stating if the command executed succesfully) var result = await commands.ExecuteAsync(context, argPos, map); if (!result.IsSuccess) {