From e73c05b819f21c49bda8f7956973763a23775f37 Mon Sep 17 00:00:00 2001 From: Noi Date: Thu, 10 Mar 2022 15:38:42 -0800 Subject: [PATCH] Implement help command --- ApplicationCommands/HelpCommands.cs | 61 ----------------------------- ApplicationCommands/HelpModule.cs | 49 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 61 deletions(-) delete mode 100644 ApplicationCommands/HelpCommands.cs create mode 100644 ApplicationCommands/HelpModule.cs diff --git a/ApplicationCommands/HelpCommands.cs b/ApplicationCommands/HelpCommands.cs deleted file mode 100644 index 6713639..0000000 --- a/ApplicationCommands/HelpCommands.cs +++ /dev/null @@ -1,61 +0,0 @@ -using BirthdayBot.Data; - -namespace BirthdayBot.ApplicationCommands; - -internal class HelpCommands : BotApplicationCommand { - private static readonly EmbedFieldBuilder _helpEmbedRegCommandsField; - private static readonly EmbedFieldBuilder _helpEmbedModCommandsField; - - static HelpCommands() { - _helpEmbedRegCommandsField = new EmbedFieldBuilder() { - Name = "Commands", - Value = $"`/set-birthday` - {RegistrationCommands.HelpSet}\n" + - $"`/set-timezone` - {RegistrationCommands.HelpZone}\n" + - $"`/remove-timezone` - {RegistrationCommands.HelpZoneDel}\n" + - $"`/remove-birthday` - {RegistrationCommands.HelpDel}\n" + - $"`/birthday` - {QueryCommands.HelpBirthdayFor}\n" + - $"`/recent`, `/upcoming` - {QueryCommands.HelpRecentUpcoming}" - - }; - _helpEmbedModCommandsField = new EmbedFieldBuilder() { - Name = "Moderator commands", - Value = - $"`/config` - {ModCommands.HelpConfig}\n" + - $"`/announce` - {ModCommands.HelpConfAnnounce}\n" + - $"`/blocking` - {ModCommands.HelpConfBlocking}\n" + - $"`/list-all` - {QueryCommands.HelpListAll}\n" + - $"`/override` - {RegistrationOverrideCommands.HelpOverride}\n" + - $"See also: `/config help`, `/announce help`, `/blocking help`." - }; - } - - public override IEnumerable GetCommands() => new ApplicationCommandProperties[] { - new SlashCommandBuilder() - .WithName("help").WithDescription("Show an overview of available commands.").Build() - }; - public override CommandResponder? GetHandlerFor(string commandName) => commandName switch { - "help" => CmdHelp, - _ => null, - }; - - private async Task CmdHelp(ShardInstance instance, GuildConfiguration gconf, SocketSlashCommand arg) { - string ver = -#if DEBUG - "DEBUG flag set"; -#else - "v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version!.ToString(3); -#endif - var result = new EmbedBuilder() - .WithAuthor("Help & About") - .WithFooter($"Birthday Bot {ver} - Shard {instance.ShardId:00} up {Program.BotUptime}", - instance.DiscordClient.CurrentUser.GetAvatarUrl()) - .WithDescription("Thank you for using Birthday Bot!\n" + - "Support, data policy, etc: https://noithecat.dev/bots/BirthdayBot\n" + - "This bot is provided for free, without any paywalls or exclusive paid features. If this bot has been useful to you, " + - "please consider taking a look at the author's Ko-fi: https://ko-fi.com/noithecat.") - .AddField(_helpEmbedRegCommandsField) - .AddField(_helpEmbedModCommandsField) - .Build(); - await arg.RespondAsync(embed: result); - } -} diff --git a/ApplicationCommands/HelpModule.cs b/ApplicationCommands/HelpModule.cs new file mode 100644 index 0000000..86b398a --- /dev/null +++ b/ApplicationCommands/HelpModule.cs @@ -0,0 +1,49 @@ +using Discord.Interactions; + +namespace BirthdayBot.ApplicationCommands; + +public class HelpModule : BotModuleBase { + private const string RegularCommandsField = + $"`/birthday` - {BirthdayModule.HelpCmdBirthday}\n" + + $"` ⤷get` - {BirthdayModule.HelpCmdGet}\n" + + $"` ⤷show-nearest` - {BirthdayModule.HelpCmdNearest}\n" + + $"` ⤷set date` - {BirthdayModule.HelpCmdSetDate}\n" + + $"` ⤷set timezone` - {BirthdayModule.HelpCmdSetZone}\n" + + $"` ⤷remove` - {BirthdayModule.HelpCmdRemove}"; + private const string ModCommandsField = + $"`/birthday export` - {BirthdayModule.HelpCmdExport}\n" + + $"`/config` - {ConfigModule.HelpCmdConfig}\n" + + $"` ⤷check` - {ConfigModule.HelpCmdCheck}\n" + + $"` ⤷announce` - {ConfigModule.HelpCmdAnnounce}\n" + + $"` ⤷` See also: `/config announce help`.\n" + + $"` ⤷role` - {ConfigModule.HelpCmdRole}\n" + + $"` ⤷set-birthday-role`, `⤷set-moderator-role`\n" + + $"`/override` - {BirthdayOverrideModule.HelpCmdOverride}\n" + + $"` ⤷set-birthday`, `⤷set-timezone`, `⤷remove`\n" + + "**Caution:** Skipping optional parameters may __remove__ their configuration."; + + [SlashCommand("help", "Show an overview of available commands.")] + public async Task CmdHelp() { + const string DMWarn = "Please note that this bot works in servers only. " + + "The bot will not respond to any of the following commands within a DM."; + + string ver = +#if DEBUG + "DEBUG flag set"; +#else + "v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version!.ToString(3); +#endif + var result = new EmbedBuilder() + .WithAuthor("Help & About") + .WithFooter($"Birthday Bot {ver} - Shard {Shard.ShardId:00} up {Program.BotUptime}", + Context.Client.CurrentUser.GetAvatarUrl()) + .WithDescription("Thank you for using Birthday Bot!\n" + + "Support, data policy, more info: https://noithecat.dev/bots/BirthdayBot\n\n" + + "This bot is provided for free, without any paywalls or exclusive paid features. If this bot has been useful to you, " + + "please consider making a small contribution via the author's Ko-fi: https://ko-fi.com/noithecat.") + .AddField("Commands", RegularCommandsField) + .AddField("Moderator commands", ModCommandsField) + .Build(); + await RespondAsync(text: (Context.Channel is IDMChannel ? DMWarn : null), embed: result).ConfigureAwait(false); + } +}