2017-09-14 22:11:19 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord.Commands;
|
2017-10-12 16:34:10 +02:00
|
|
|
|
using Geekbot.net.Lib;
|
2018-05-03 00:56:06 +02:00
|
|
|
|
using Geekbot.net.Lib.ErrorHandling;
|
|
|
|
|
using Geekbot.net.Lib.Localization;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
|
2018-05-03 00:56:06 +02:00
|
|
|
|
namespace Geekbot.net.Commands.Utils
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
public class Choose : ModuleBase
|
|
|
|
|
{
|
2017-10-26 00:55:04 +02:00
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
2017-11-16 17:19:43 +01:00
|
|
|
|
private readonly ITranslationHandler _translation;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
|
2018-02-14 23:01:28 +01:00
|
|
|
|
public Choose(IErrorHandler errorHandler, ITranslationHandler translation)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-10-26 00:55:04 +02:00
|
|
|
|
_errorHandler = errorHandler;
|
2017-11-16 17:19:43 +01:00
|
|
|
|
_translation = translation;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
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)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-10-26 00:55:04 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-11-16 17:19:43 +01:00
|
|
|
|
var transDict = _translation.GetDict(Context);
|
2017-10-26 00:55:04 +02:00
|
|
|
|
var choicesArray = choices.Split(';');
|
2018-02-14 23:01:28 +01:00
|
|
|
|
var choice = new Random().Next(choicesArray.Length);
|
2017-11-16 17:19:43 +01:00
|
|
|
|
await ReplyAsync(string.Format(transDict["Choice"], choicesArray[choice]));
|
2017-10-26 00:55:04 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context);
|
|
|
|
|
}
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-15 20:43:50 +02:00
|
|
|
|
}
|