Improved error messages under manager commands

This commit is contained in:
Noi 2020-06-03 19:20:18 -07:00
parent 1137777092
commit fbbc675ab0
4 changed files with 21 additions and 16 deletions

View file

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<Version>2.0.1</Version> <Version>2.1.0</Version>
<PackageId>BirthdayBot</PackageId> <PackageId>BirthdayBot</PackageId>
<Authors>NoiTheCat</Authors> <Authors>NoiTheCat</Authors>
<Product>BirthdayBot</Product> <Product>BirthdayBot</Product>

View file

@ -17,12 +17,9 @@ namespace BirthdayBot.UserInterface
#else #else
public const string CommandPrefix = "bb."; public const string CommandPrefix = "bb.";
#endif #endif
[Obsolete]
public const string GenericError = ":x: Invalid usage. Consult the help command.";
public const string BadUserError = ":x: Unable to find user. Specify their `@` mention or their ID."; public const string BadUserError = ":x: Unable to find user. Specify their `@` mention or their ID.";
public const string ParameterError = ":x: Incorrect number of parameters. Be sure you have not added spaces" public const string ParameterError = ":x: Invalid usage. Refer to how to use the command and try again.";
+ " where the bot is not expecting them or that all required information has been provided."; public const string NoParameterError = ":x: This command does not accept any parameters.";
public const string NoParameterError = ":x: This command does not accept parameters.";
public const string InternalError = ":x: An internal bot error occurred. The bot maintainer has been notified of the issue."; public const string InternalError = ":x: An internal bot error occurred. The bot maintainer has been notified of the issue.";
public delegate Task CommandHandler(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser); public delegate Task CommandHandler(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser);

View file

@ -49,8 +49,7 @@ namespace BirthdayBot.UserInterface
Value = $"{cpfx}config`\n" Value = $"{cpfx}config`\n"
+ $" » Edit bot configuration. See `{CommandPrefix}help-config`.\n" + $" » Edit bot configuration. See `{CommandPrefix}help-config`.\n"
+ ListingCommands.DocList.Export() + "\n" + ListingCommands.DocList.Export() + "\n"
+ $"{cpfx}override (user ping or ID) (command w/ parameters)`\n" + ManagerCommands.DocOverride.Export()
+ " » Perform certain commands on behalf of another user."
}; };
var helpRegular = new EmbedBuilder().AddField(cmdField).AddField(cmdModField); var helpRegular = new EmbedBuilder().AddField(cmdField).AddField(cmdModField);

View file

@ -1,4 +1,5 @@
using Discord; using BirthdayBot.BackgroundServices;
using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using NodaTime; using NodaTime;
using System; using System;
@ -11,6 +12,8 @@ namespace BirthdayBot.UserInterface
{ {
internal class ManagerCommands : CommandsCommon internal class ManagerCommands : CommandsCommon
{ {
private static readonly string ConfErrorPostfix =
$" Refer to the `{CommandPrefix}help-config` command for information on this command's usage.";
private delegate Task ConfigSubcommand(string[] param, SocketTextChannel reqChannel); private delegate Task ConfigSubcommand(string[] param, SocketTextChannel reqChannel);
private readonly Dictionary<string, ConfigSubcommand> _subcommands; private readonly Dictionary<string, ConfigSubcommand> _subcommands;
@ -46,6 +49,12 @@ namespace BirthdayBot.UserInterface
("status", CmdStatus) ("status", CmdStatus)
}; };
#region Documentation
public static readonly CommandDocumentation DocOverride =
new CommandDocumentation(new string[] { "override (user ping or ID) (command w/ parameters)" },
"Perform certain commands on behalf of another user.", null);
#endregion
private async Task CmdConfigDispatch(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser) private async Task CmdConfigDispatch(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
{ {
// Ignore those without the proper permissions. // Ignore those without the proper permissions.
@ -267,7 +276,7 @@ namespace BirthdayBot.UserInterface
{ {
if (param.Length != 2) if (param.Length != 2)
{ {
await reqChannel.SendMessageAsync(GenericError); await reqChannel.SendMessageAsync(ParameterError + ConfErrorPostfix);
return; return;
} }
@ -313,7 +322,7 @@ namespace BirthdayBot.UserInterface
{ {
if (param.Length != 2) if (param.Length != 2)
{ {
await reqChannel.SendMessageAsync(GenericError); await reqChannel.SendMessageAsync(ParameterError + ConfErrorPostfix);
return; return;
} }
@ -323,7 +332,7 @@ namespace BirthdayBot.UserInterface
else if (parameter == "off") modSet = false; else if (parameter == "off") modSet = false;
else else
{ {
await reqChannel.SendMessageAsync(GenericError); await reqChannel.SendMessageAsync(":x: Expected `on` or `off` as a parameter." + ConfErrorPostfix);
return; return;
} }
@ -373,7 +382,7 @@ namespace BirthdayBot.UserInterface
if (param.Length != 3) if (param.Length != 3)
{ {
await reqChannel.SendMessageAsync(GenericError); await reqChannel.SendMessageAsync(ParameterError, embed: DocOverride.UsageEmbed);
return; return;
} }
@ -381,13 +390,13 @@ namespace BirthdayBot.UserInterface
ulong user = 0; ulong user = 0;
if (!TryGetUserId(param[1], out user)) if (!TryGetUserId(param[1], out user))
{ {
await reqChannel.SendMessageAsync(BadUserError); await reqChannel.SendMessageAsync(BadUserError, embed: DocOverride.UsageEmbed);
return; return;
} }
var overuser = reqChannel.Guild.GetUser(user); var overuser = reqChannel.Guild.GetUser(user);
if (overuser == null) if (overuser == null)
{ {
await reqChannel.SendMessageAsync(BadUserError); await reqChannel.SendMessageAsync(BadUserError, embed: DocOverride.UsageEmbed);
return; return;
} }
@ -408,7 +417,7 @@ namespace BirthdayBot.UserInterface
CommandHandler action = null; CommandHandler action = null;
if (!_usercommands.TryGetValue(cmdsearch, out action)) if (!_usercommands.TryGetValue(cmdsearch, out action))
{ {
await reqChannel.SendMessageAsync($":x: `{cmdsearch}` is not an overridable command."); await reqChannel.SendMessageAsync($":x: `{cmdsearch}` is not an overridable command.", embed: DocOverride.UsageEmbed);
return; return;
} }