refactor: move command parse errors to own file
This commit is contained in:
parent
9926bbbd8b
commit
ad6addc2fd
48
PluralKit.Bot/CommandMeta/CommandParseErrors.cs
Normal file
48
PluralKit.Bot/CommandMeta/CommandParseErrors.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using Humanizer;
|
||||||
|
|
||||||
|
using PluralKit.Core;
|
||||||
|
|
||||||
|
namespace PluralKit.Bot;
|
||||||
|
|
||||||
|
public partial class CommandTree
|
||||||
|
{
|
||||||
|
private async Task PrintCommandNotFoundError(Context ctx, params Command[] potentialCommands)
|
||||||
|
{
|
||||||
|
var commandListStr = CreatePotentialCommandList(potentialCommands);
|
||||||
|
await ctx.Reply(
|
||||||
|
$"{Emojis.Error} Unknown command `pk;{ctx.FullCommand().Truncate(100)}`. Perhaps you meant to use one of the following commands?\n{commandListStr}\n\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
||||||
|
}
|
||||||
|
private async Task PrintCommandExpectedError(Context ctx, params Command[] potentialCommands)
|
||||||
|
{
|
||||||
|
var commandListStr = CreatePotentialCommandList(potentialCommands);
|
||||||
|
await ctx.Reply(
|
||||||
|
$"{Emojis.Error} You need to pass a command. Perhaps you meant to use one of the following commands?\n{commandListStr}\n\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string CreatePotentialCommandList(params Command[] potentialCommands)
|
||||||
|
{
|
||||||
|
return string.Join("\n", potentialCommands.Select(cmd => $"- **pk;{cmd.Usage}** - *{cmd.Description}*"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task PrintCommandList(Context ctx, string subject, params Command[] commands)
|
||||||
|
{
|
||||||
|
var str = CreatePotentialCommandList(commands);
|
||||||
|
await ctx.Reply($"Here is a list of commands related to {subject}: \n{str}\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> CreateSystemNotFoundError(Context ctx)
|
||||||
|
{
|
||||||
|
var input = ctx.PopArgument();
|
||||||
|
if (input.TryParseMention(out var id))
|
||||||
|
{
|
||||||
|
// Try to resolve the user ID to find the associated account,
|
||||||
|
// so we can print their username.
|
||||||
|
var user = await ctx.Rest.GetUser(id);
|
||||||
|
if (user != null)
|
||||||
|
return $"Account **{user.Username}#{user.Discriminator}** does not have a system registered.";
|
||||||
|
return $"Account with ID `{id}` not found.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"System with ID {input.AsCode()} not found.";
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
using Humanizer;
|
|
||||||
|
|
||||||
using PluralKit.Core;
|
using PluralKit.Core;
|
||||||
|
|
||||||
namespace PluralKit.Bot;
|
namespace PluralKit.Bot;
|
||||||
@ -495,44 +493,4 @@ public partial class CommandTree
|
|||||||
// todo: maybe add the list of configuration keys here?
|
// todo: maybe add the list of configuration keys here?
|
||||||
return ctx.Reply($"{Emojis.Error} Could not find a setting with that name. Please see `pk;commands config` for the list of possible config settings.");
|
return ctx.Reply($"{Emojis.Error} Could not find a setting with that name. Please see `pk;commands config` for the list of possible config settings.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PrintCommandNotFoundError(Context ctx, params Command[] potentialCommands)
|
|
||||||
{
|
|
||||||
var commandListStr = CreatePotentialCommandList(potentialCommands);
|
|
||||||
await ctx.Reply(
|
|
||||||
$"{Emojis.Error} Unknown command `pk;{ctx.FullCommand().Truncate(100)}`. Perhaps you meant to use one of the following commands?\n{commandListStr}\n\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
|
||||||
}
|
|
||||||
private async Task PrintCommandExpectedError(Context ctx, params Command[] potentialCommands)
|
|
||||||
{
|
|
||||||
var commandListStr = CreatePotentialCommandList(potentialCommands);
|
|
||||||
await ctx.Reply(
|
|
||||||
$"{Emojis.Error} You need to pass a command. Perhaps you meant to use one of the following commands?\n{commandListStr}\n\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string CreatePotentialCommandList(params Command[] potentialCommands)
|
|
||||||
{
|
|
||||||
return string.Join("\n", potentialCommands.Select(cmd => $"- **pk;{cmd.Usage}** - *{cmd.Description}*"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task PrintCommandList(Context ctx, string subject, params Command[] commands)
|
|
||||||
{
|
|
||||||
var str = CreatePotentialCommandList(commands);
|
|
||||||
await ctx.Reply($"Here is a list of commands related to {subject}: \n{str}\nFor a full list of possible commands, see <https://pluralkit.me/commands>.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<string> CreateSystemNotFoundError(Context ctx)
|
|
||||||
{
|
|
||||||
var input = ctx.PopArgument();
|
|
||||||
if (input.TryParseMention(out var id))
|
|
||||||
{
|
|
||||||
// Try to resolve the user ID to find the associated account,
|
|
||||||
// so we can print their username.
|
|
||||||
var user = await ctx.Rest.GetUser(id);
|
|
||||||
if (user != null)
|
|
||||||
return $"Account **{user.Username}#{user.Discriminator}** does not have a system registered.";
|
|
||||||
return $"Account with ID `{id}` not found.";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"System with ID {input.AsCode()} not found.";
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user