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>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>2.0.1</Version>
<Version>2.1.0</Version>
<PackageId>BirthdayBot</PackageId>
<Authors>NoiTheCat</Authors>
<Product>BirthdayBot</Product>

View file

@ -17,12 +17,9 @@ namespace BirthdayBot.UserInterface
#else
public const string CommandPrefix = "bb.";
#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 ParameterError = ":x: Incorrect number of parameters. Be sure you have not added spaces"
+ " 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 parameters.";
public const string ParameterError = ":x: Invalid usage. Refer to how to use the command and try again.";
public const string NoParameterError = ":x: This command does not accept any parameters.";
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);

View file

@ -49,8 +49,7 @@ namespace BirthdayBot.UserInterface
Value = $"{cpfx}config`\n"
+ $" » Edit bot configuration. See `{CommandPrefix}help-config`.\n"
+ ListingCommands.DocList.Export() + "\n"
+ $"{cpfx}override (user ping or ID) (command w/ parameters)`\n"
+ " » Perform certain commands on behalf of another user."
+ ManagerCommands.DocOverride.Export()
};
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 NodaTime;
using System;
@ -11,6 +12,8 @@ namespace BirthdayBot.UserInterface
{
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 readonly Dictionary<string, ConfigSubcommand> _subcommands;
@ -46,6 +49,12 @@ namespace BirthdayBot.UserInterface
("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)
{
// Ignore those without the proper permissions.
@ -267,7 +276,7 @@ namespace BirthdayBot.UserInterface
{
if (param.Length != 2)
{
await reqChannel.SendMessageAsync(GenericError);
await reqChannel.SendMessageAsync(ParameterError + ConfErrorPostfix);
return;
}
@ -313,7 +322,7 @@ namespace BirthdayBot.UserInterface
{
if (param.Length != 2)
{
await reqChannel.SendMessageAsync(GenericError);
await reqChannel.SendMessageAsync(ParameterError + ConfErrorPostfix);
return;
}
@ -323,7 +332,7 @@ namespace BirthdayBot.UserInterface
else if (parameter == "off") modSet = false;
else
{
await reqChannel.SendMessageAsync(GenericError);
await reqChannel.SendMessageAsync(":x: Expected `on` or `off` as a parameter." + ConfErrorPostfix);
return;
}
@ -373,7 +382,7 @@ namespace BirthdayBot.UserInterface
if (param.Length != 3)
{
await reqChannel.SendMessageAsync(GenericError);
await reqChannel.SendMessageAsync(ParameterError, embed: DocOverride.UsageEmbed);
return;
}
@ -381,13 +390,13 @@ namespace BirthdayBot.UserInterface
ulong user = 0;
if (!TryGetUserId(param[1], out user))
{
await reqChannel.SendMessageAsync(BadUserError);
await reqChannel.SendMessageAsync(BadUserError, embed: DocOverride.UsageEmbed);
return;
}
var overuser = reqChannel.Guild.GetUser(user);
if (overuser == null)
{
await reqChannel.SendMessageAsync(BadUserError);
await reqChannel.SendMessageAsync(BadUserError, embed: DocOverride.UsageEmbed);
return;
}
@ -408,7 +417,7 @@ namespace BirthdayBot.UserInterface
CommandHandler action = null;
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;
}