Reorganize help strings

This commit is contained in:
Noi 2022-03-10 15:37:34 -08:00
parent a58cedad88
commit ccb56ed243
4 changed files with 27 additions and 23 deletions

View file

@ -5,23 +5,23 @@ using System.Text;
namespace BirthdayBot.ApplicationCommands; namespace BirthdayBot.ApplicationCommands;
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[Group("birthday", "Commands relating to birthdays.")] [Group("birthday", HelpCmdBirthday)]
public class BirthdayModule : BotModuleBase { public class BirthdayModule : BotModuleBase {
public const string HelpExport = "Generates a text file with all known and available birthdays."; public const string HelpCmdBirthday = "Commands relating to birthdays.";
public const string HelpGet = "Gets a user's birthday."; public const string HelpCmdSetDate = "Sets or updates your birthday.";
public const string HelpRecentUpcoming = "Get a list of users who recently had or will have a birthday."; public const string HelpCmdSetZone = "Sets or updates your time zone if your birthday is already set.";
public const string HelpRemove = "Removes your birthday information from this bot."; public const string HelpCmdRemove = "Removes your birthday information from this bot.";
public const string HelpCmdGet = "Gets a user's birthday.";
public const string HelpCmdNearest = "Get a list of users who recently had or will have a birthday.";
public const string HelpCmdExport = "Generates a text file with all known and available birthdays.";
// Note that these methods have largely been copied to BirthdayOverrideModule. Changes here should be reflected there as needed. // Note that these methods have largely been copied to BirthdayOverrideModule. Changes here should be reflected there as needed.
[Group("set", "Subcommands for setting birthday information.")] [Group("set", "Subcommands for setting birthday information.")]
public class SubCmdsBirthdaySet : BotModuleBase { public class SubCmdsBirthdaySet : BotModuleBase {
public const string HelpSetBday = "Sets or updates your birthday."; [SlashCommand("date", HelpCmdSetDate)]
public const string HelpSetZone = "Sets or updates your time zone, when your birthday is already set.";
[SlashCommand("date", HelpSetBday)]
public async Task CmdSetBday([Summary(description: HelpOptDate)] string date, public async Task CmdSetBday([Summary(description: HelpOptDate)] string date,
[Summary(description: HelpOptPfxOptional + HelpOptZone)] string? zone = null) { [Summary(description: HelpOptZone)] string? zone = null) {
int inmonth, inday; int inmonth, inday;
try { try {
(inmonth, inday) = ParseDate(date); (inmonth, inday) = ParseDate(date);
@ -48,7 +48,7 @@ public class BirthdayModule : BotModuleBase {
(inzone == null ? "" : $", with time zone {inzone}") + ".").ConfigureAwait(false); (inzone == null ? "" : $", with time zone {inzone}") + ".").ConfigureAwait(false);
} }
[SlashCommand("zone", HelpSetZone)] [SlashCommand("timezone", HelpCmdSetZone)]
public async Task CmdSetZone([Summary(description: HelpOptZone)] string zone) { public async Task CmdSetZone([Summary(description: HelpOptZone)] string zone) {
var user = await ((SocketGuildUser)Context.User).GetConfigAsync().ConfigureAwait(false); var user = await ((SocketGuildUser)Context.User).GetConfigAsync().ConfigureAwait(false);
if (!user.IsKnown) { if (!user.IsKnown) {
@ -68,7 +68,7 @@ public class BirthdayModule : BotModuleBase {
} }
} }
[SlashCommand("remove", HelpRemove)] [SlashCommand("remove", HelpCmdRemove)]
public async Task CmdRemove() { public async Task CmdRemove() {
var user = await ((SocketGuildUser)Context.User).GetConfigAsync().ConfigureAwait(false); var user = await ((SocketGuildUser)Context.User).GetConfigAsync().ConfigureAwait(false);
if (user.IsKnown) { if (user.IsKnown) {
@ -100,7 +100,7 @@ public class BirthdayModule : BotModuleBase {
// "Recent and upcoming birthdays" // "Recent and upcoming birthdays"
// The 'recent' bit removes time zone ambiguity and spares us from extra time zone processing here // The 'recent' bit removes time zone ambiguity and spares us from extra time zone processing here
// TODO stop being lazy // TODO stop being lazy
[SlashCommand("show-nearest", HelpRecentUpcoming)] [SlashCommand("show-nearest", HelpCmdNearest)]
public async Task CmdShowNearest() { public async Task CmdShowNearest() {
if (!await HasMemberCacheAsync(Context.Guild).ConfigureAwait(false)) { if (!await HasMemberCacheAsync(Context.Guild).ConfigureAwait(false)) {
await RespondAsync(MemberCacheEmptyError, ephemeral: true); await RespondAsync(MemberCacheEmptyError, ephemeral: true);
@ -175,7 +175,7 @@ public class BirthdayModule : BotModuleBase {
} }
[RequireBotModerator] [RequireBotModerator]
[SlashCommand("export", HelpPfxModOnly + HelpExport)] [SlashCommand("export", HelpPfxModOnly + HelpCmdGet)]
public async Task CmdExport([Summary(description: "Specify whether to export the list in CSV format.")] bool asCsv = false) { public async Task CmdExport([Summary(description: "Specify whether to export the list in CSV format.")] bool asCsv = false) {
if (!await HasMemberCacheAsync(Context.Guild)) { if (!await HasMemberCacheAsync(Context.Guild)) {
await RespondAsync(MemberCacheEmptyError).ConfigureAwait(false); await RespondAsync(MemberCacheEmptyError).ConfigureAwait(false);
@ -229,7 +229,7 @@ public class BirthdayModule : BotModuleBase {
return result; return result;
} }
private Stream ListExportNormal(SocketGuild guild, IEnumerable<ListItem> list) { private static Stream ListExportNormal(SocketGuild guild, IEnumerable<ListItem> list) {
// Output: "● Mon-dd: (user ID) Username [ - Nickname: (nickname)]" // Output: "● Mon-dd: (user ID) Username [ - Nickname: (nickname)]"
var result = new MemoryStream(); var result = new MemoryStream();
var writer = new StreamWriter(result, Encoding.UTF8); var writer = new StreamWriter(result, Encoding.UTF8);
@ -250,7 +250,7 @@ public class BirthdayModule : BotModuleBase {
return result; return result;
} }
private Stream ListExportCsv(SocketGuild guild, IEnumerable<ListItem> list) { private static Stream ListExportCsv(SocketGuild guild, IEnumerable<ListItem> list) {
// Output: User ID, Username, Nickname, Month-Day, Month, Day // Output: User ID, Username, Nickname, Month-Day, Month, Day
var result = new MemoryStream(); var result = new MemoryStream();
var writer = new StreamWriter(result, Encoding.UTF8); var writer = new StreamWriter(result, Encoding.UTF8);

View file

@ -5,8 +5,9 @@ namespace BirthdayBot.ApplicationCommands;
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireBotModerator] [RequireBotModerator]
[Group("override", "Run certain commands on behalf of other users.")] [Group("override", HelpCmdOverride)]
public class BirthdayOverrideModule : BotModuleBase { public class BirthdayOverrideModule : BotModuleBase {
public const string HelpCmdOverride = "Commands to set options for other users.";
const string HelpOptOvTarget = "The user whose data to modify."; const string HelpOptOvTarget = "The user whose data to modify.";
// Note that these methods have largely been copied from BirthdayModule. Changes there should be reflected here as needed. // Note that these methods have largely been copied from BirthdayModule. Changes there should be reflected here as needed.

View file

@ -17,7 +17,6 @@ public abstract class BotModuleBase : InteractionModuleBase<SocketInteractionCon
protected const string MemberCacheEmptyError = ":warning: Please try the command again."; protected const string MemberCacheEmptyError = ":warning: Please try the command again.";
public const string AccessDeniedError = ":warning: You are not allowed to run this command."; public const string AccessDeniedError = ":warning: You are not allowed to run this command.";
protected const string HelpOptPfxOptional = "Optional: ";
protected const string HelpOptDate = "A date, including the month and day. For example, \"15 January\"."; protected const string HelpOptDate = "A date, including the month and day. For example, \"15 January\".";
protected const string HelpOptZone = "A 'tzdata'-compliant time zone name. See help for more details."; protected const string HelpOptZone = "A 'tzdata'-compliant time zone name. See help for more details.";

View file

@ -6,13 +6,18 @@ namespace BirthdayBot.ApplicationCommands;
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireBotModerator] [RequireBotModerator]
[Group("config", "Configure basic settings for the bot.")] [Group("config", HelpCmdConfig)]
public class ConfigModule : BotModuleBase { public class ConfigModule : BotModuleBase {
public const string HelpCmdConfig = "Configure basic settings for the bot.";
public const string HelpCmdAnnounce = "Settings regarding birthday announcements.";
public const string HelpCmdRole = "Settings for roles used by this bot.";
public const string HelpCmdCheck = "Test the bot's current configuration and show the results.";
const string HelpPofxBlankUnset = " Leave blank to unset."; const string HelpPofxBlankUnset = " Leave blank to unset.";
const string HelpOptChannel = "The corresponding channel to use."; const string HelpOptChannel = "The corresponding channel to use.";
const string HelpOptRole = "The corresponding role to use."; const string HelpOptRole = "The corresponding role to use.";
[Group("announce", HelpPfxModOnly + "Configure settings regarding birthday announcements.")] [Group("announce", HelpPfxModOnly + HelpCmdAnnounce)]
public class SubCmdsConfigAnnounce : BotModuleBase { public class SubCmdsConfigAnnounce : BotModuleBase {
[SlashCommand("help", "Show information regarding announcement messages.")] [SlashCommand("help", "Show information regarding announcement messages.")]
public async Task CmdAnnounceHelp() { public async Task CmdAnnounceHelp() {
@ -33,7 +38,6 @@ public class ConfigModule : BotModuleBase {
[SlashCommand("set-message", HelpPfxModOnly + "Modify the announcement message.")] [SlashCommand("set-message", HelpPfxModOnly + "Modify the announcement message.")]
public async Task CmdSetMessage() { public async Task CmdSetMessage() {
// TODO fully implement this // TODO fully implement this
// idea: ephemeral message prints on command use, then a modal appears. though maybe this isn't really possible...
await RespondAsync("Sorry, changing the announcement message via slash commands is not yet available. " + await RespondAsync("Sorry, changing the announcement message via slash commands is not yet available. " +
"Please use the corresponding text command.", ephemeral: true); "Please use the corresponding text command.", ephemeral: true);
} }
@ -47,7 +51,7 @@ public class ConfigModule : BotModuleBase {
} }
} }
[Group("role", HelpPfxModOnly + "Configure settings regarding roles used by this bot.")] [Group("role", HelpPfxModOnly + HelpCmdRole)]
public class SubCmdsConfigRole : BotModuleBase { public class SubCmdsConfigRole : BotModuleBase {
[SlashCommand("set-birthday-role", HelpPfxModOnly + "Set the role given to users having a birthday.")] [SlashCommand("set-birthday-role", HelpPfxModOnly + "Set the role given to users having a birthday.")]
public async Task CmdSetBRole([Summary(description: HelpOptRole)] SocketRole role) { public async Task CmdSetBRole([Summary(description: HelpOptRole)] SocketRole role) {
@ -67,7 +71,7 @@ public class ConfigModule : BotModuleBase {
} }
} }
[SlashCommand("check", HelpPfxModOnly + "Test the bot's current configuration and show the results.")] [SlashCommand("check", HelpPfxModOnly + HelpCmdCheck)]
public async Task CmdCheck() { public async Task CmdCheck() {
static string DoTestFor(string label, Func<bool> test) => $"{label}: { (test() ? ":white_check_mark: Yes" : ":x: No") }"; static string DoTestFor(string label, Func<bool> test) => $"{label}: { (test() ? ":white_check_mark: Yes" : ":x: No") }";
var result = new StringBuilder(); var result = new StringBuilder();