setting up subcommands.

This commit is contained in:
benbierens 2023-10-24 14:07:15 +02:00
parent dfe477d192
commit 5aff8c6f6d
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
4 changed files with 60 additions and 4 deletions

View File

@ -62,5 +62,14 @@ namespace BiblioTech
public string Description { get; }
public ApplicationCommandOptionType Type { get; }
public bool IsRequired { get; }
public virtual SlashCommandOptionBuilder Build()
{
return new SlashCommandOptionBuilder()
.WithName(Name)
.WithDescription(Description)
.WithType(Type)
.WithRequired(IsRequired);
}
}
}

View File

@ -32,7 +32,7 @@ namespace BiblioTech
foreach (var option in c.Options)
{
builder.AddOption(option.Name, option.Type, option.Description, isRequired: option.IsRequired);
builder.AddOption(option.Build());
}
return builder;

View File

@ -0,0 +1,46 @@
using Discord;
using Discord.WebSocket;
namespace BiblioTech.Commands
{
public class SubCommandOption : CommandOption
{
private readonly CommandOption[] options;
public SubCommandOption(string name, string description, params CommandOption[] options)
: base(name, description, type: ApplicationCommandOptionType.SubCommand, isRequired: false)
{
this.options = options;
}
public override SlashCommandOptionBuilder Build()
{
var builder = base.Build();
foreach (var option in options)
{
builder.AddOption(option.Build());
}
return builder;
}
}
public class AdminCommand : BaseCommand
{
public override string Name => "admin";
public override string StartingMessage => "...";
public override string Description => "Admins only.";
private readonly SubCommandOption aaa = new SubCommandOption("aaa", "does AAA", new EthAddressOption());
private readonly SubCommandOption bbb = new SubCommandOption("bbb", "does BBB", new UserOption("a user", true));
public override CommandOption[] Options => new CommandOption[]
{
aaa, bbb
};
protected override Task Invoke(SocketSlashCommand command)
{
return Task.CompletedTask;
}
}
}

View File

@ -51,12 +51,13 @@ namespace BiblioTech
var associateCommand = new UserAssociateCommand();
var handler = new CommandHandler(client,
new ClearUserAssociationCommand(),
//new ClearUserAssociationCommand(),
new GetBalanceCommand(monitor, ci, associateCommand),
new MintCommand(monitor, ci, associateCommand),
new ReportHistoryCommand(),
//new ReportHistoryCommand(),
associateCommand,
new DeploymentsCommand(monitor)
//new DeploymentsCommand(monitor),
new AdminCommand()
);
await client.LoginAsync(TokenType.Bot, Config.ApplicationToken);