geekbot/Geekbot.net/Commands/Utils/Choose.cs

39 lines
1.3 KiB
C#
Raw Normal View History

using System;
using System.Threading.Tasks;
using Discord.Commands;
2019-05-23 23:38:07 +02:00
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization;
namespace Geekbot.net.Commands.Utils
{
2019-05-23 23:38:07 +02:00
public class Choose : GeekbotBase
{
private readonly IErrorHandler _errorHandler;
private readonly ITranslationHandler _translation;
2017-09-15 22:56:03 +02:00
public Choose(IErrorHandler errorHandler, ITranslationHandler translation)
{
_errorHandler = errorHandler;
_translation = translation;
}
2017-09-15 22:56:03 +02:00
[Command("choose", RunMode = RunMode.Async)]
2017-10-12 16:34:10 +02:00
[Summary("Let the bot choose for you, seperate options with a semicolon.")]
2017-12-29 01:53:50 +01:00
public async Task Command([Remainder] [Summary("option1;option2")]
string choices)
{
try
{
var transContext = await _translation.GetGuildContext(Context);
var choicesArray = choices.Split(';');
var choice = new Random().Next(choicesArray.Length);
await ReplyAsync(transContext.GetString("Choice", choicesArray[choice].Trim()));
}
catch (Exception e)
{
await _errorHandler.HandleCommandException(e, Context);
}
}
}
2017-05-15 20:43:50 +02:00
}