geekbot/Geekbot.net/Commands/Choose.cs

36 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
using Discord.Commands;
2017-10-12 16:34:10 +02:00
using Geekbot.net.Lib;
namespace Geekbot.net.Commands
{
public class Choose : ModuleBase
{
private readonly Random _rnd;
private readonly IErrorHandler _errorHandler;
2017-09-15 22:56:03 +02:00
public Choose(Random RandomClient, IErrorHandler errorHandler)
{
_rnd = RandomClient;
_errorHandler = errorHandler;
}
2017-09-15 22:56:03 +02:00
[Command("choose", RunMode = RunMode.Async)]
2017-10-12 16:34:10 +02:00
[Remarks(CommandCategories.Helpers)]
[Summary("Let the bot choose for you, seperate options with a semicolon.")]
2017-09-15 22:56:03 +02:00
public async Task Command([Remainder] [Summary("option1;option2")] string choices)
{
try
{
var choicesArray = choices.Split(';');
var choice = _rnd.Next(choicesArray.Length);
await ReplyAsync($"I choose **{choicesArray[choice]}**");
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
}
}
}
2017-05-15 20:43:50 +02:00
}