Adding Dice Command

This commit is contained in:
Runebaas 2017-09-15 00:01:00 +02:00
parent ee94c7dabc
commit 40bbef9cd8
2 changed files with 54 additions and 8 deletions

View file

@ -0,0 +1,54 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using StackExchange.Redis;
namespace Geekbot.net.Modules
{
public class Dice : ModuleBase
{
private readonly Random rnd;
public Dice(Random RandomClient)
{
rnd = RandomClient;
}
[Command("dice", RunMode = RunMode.Async), Summary("Roll a dice.")]
public async Task RollCommand([Remainder, Summary("1d20, 1d6, 2d3, etc...")] string diceType = "1d6")
{
var dice = diceType.Split("d");
if (dice.Length != 2
|| !int.TryParse(dice[0], out int times)
|| !int.TryParse(dice[1], out int max))
{
await ReplyAsync("That is not a valid dice, examples are: 1d20, 1d6, 2d10, 5d12, etc...");
return;
}
Console.WriteLine($"Max: {max} - Times {times}");
if (times > 10 && !(times < 0))
{
await ReplyAsync("You can only roll between 1 and 10 dices");
return;
}
if (max > 100 && !(max < 1))
{
await ReplyAsync("The dice must have between 1 and 100 sides");
return;
}
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
.WithIconUrl(Context.User.GetAvatarUrl())
.WithName(Context.User.Username));
eb.WithColor(new Color(133, 189, 219));
eb.Title = $":game_die: Dice Roll - Type {diceType} :game_die:";
for (var i = 0; i < times; i++)
{
eb.AddInlineField($"Dice {i+1}", rnd.Next(1, max));
}
await ReplyAsync("", false, eb.Build());
}
}
}

View file

@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using StackExchange.Redis;
namespace Geekbot.net.Modules
@ -38,12 +37,5 @@ namespace Geekbot.net.Modules
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
}
}
[Command("dice", RunMode = RunMode.Async), Summary("Roll a dice")]
public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6)
{
var number = rnd.Next(1, max);
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
}
}
}