Port the choose command to / commands
This commit is contained in:
parent
17cb5951ee
commit
d03525d363
2 changed files with 52 additions and 4 deletions
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord.Commands;
|
||||
using Geekbot.Core;
|
||||
using Geekbot.Core.ErrorHandling;
|
||||
using Geekbot.Core.GuildSettingsManager;
|
||||
|
@ -15,7 +13,7 @@ namespace Geekbot.Bot.Commands.Utils
|
|||
}
|
||||
|
||||
[Command("choose", RunMode = RunMode.Async)]
|
||||
[Summary("Let the bot choose for you, seperate options with a semicolon.")]
|
||||
[Summary("Let the bot choose for you, separate options with a semicolon.")]
|
||||
public async Task Command([Remainder] [Summary("option1;option2")]
|
||||
string choices)
|
||||
{
|
||||
|
|
50
src/Web/Commands/Choose.cs
Normal file
50
src/Web/Commands/Choose.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using Geekbot.Interactions;
|
||||
using Geekbot.Interactions.ApplicationCommand;
|
||||
using Geekbot.Interactions.Request;
|
||||
using Geekbot.Interactions.Response;
|
||||
using Localization = Geekbot.Core.Localization;
|
||||
|
||||
namespace Geekbot.Web.Commands;
|
||||
|
||||
public class Choose : InteractionBase
|
||||
{
|
||||
private struct Options
|
||||
{
|
||||
public const string InputOptions = "options";
|
||||
public const string Separator = "separator";
|
||||
}
|
||||
|
||||
public override Command GetCommandInfo() => new ()
|
||||
{
|
||||
Name = "choose",
|
||||
Description = "Let the bot choose for you.",
|
||||
Type = CommandType.ChatInput,
|
||||
Options = new List<Option>()
|
||||
{
|
||||
new ()
|
||||
{
|
||||
Name = Options.InputOptions,
|
||||
Description = "The options, by default separated with a semicolon.",
|
||||
Type = OptionType.String,
|
||||
Required = true
|
||||
},
|
||||
new ()
|
||||
{
|
||||
Name = Options.Separator,
|
||||
Description = "The separator, by default a semicolon.",
|
||||
Type = OptionType.String,
|
||||
Required = false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public override Task<InteractionResponse> Exec(Interaction interaction)
|
||||
{
|
||||
var options = interaction.Data.Options.Find(o => o.Name == Options.InputOptions)?.Value.GetString();
|
||||
var separator = interaction.Data.Options.Find(o => o.Name == Options.Separator)?.Value.GetString() ?? ";";
|
||||
|
||||
var choicesArray = options.Split(separator);
|
||||
var choice = new Random().Next(choicesArray.Length);
|
||||
return Task.FromResult(SimpleResponse(string.Format(Localization.Choose.Choice, choicesArray[choice].Trim())));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue