Geekbot logo and roll command
This commit is contained in:
parent
b16bec8517
commit
315526c32b
3 changed files with 36 additions and 12 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
25
Geekbot.net/Modules/Roll.cs
Normal file
25
Geekbot.net/Modules/Roll.cs
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue