mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
fix: send correct error message if a parsed command is not implemented, etc
This commit is contained in:
parent
2027da40ad
commit
1a781014bd
7 changed files with 31 additions and 33 deletions
|
|
@ -10,14 +10,16 @@ public partial class CommandTree
|
|||
{
|
||||
case "fun_thunder":
|
||||
return ctx.Execute<Fun>(null, m => m.Thunder(ctx));
|
||||
default:
|
||||
// don't send an "invalid command" response if the guild has those turned off
|
||||
if (ctx.GuildConfig != null && ctx.GuildConfig!.InvalidCommandResponseEnabled != true)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// remove compiler warning
|
||||
case "help":
|
||||
return ctx.Execute<Help>(Help, m => m.HelpRoot(ctx));
|
||||
case "help_commands":
|
||||
return ctx.Reply("For the list of commands, see the website: <https://pluralkit.me/commands>");
|
||||
case "help_proxy":
|
||||
return ctx.Reply(
|
||||
$"{Emojis.Error} Unknown command {ctx.PeekArgument().AsCode()}. For a list of possible commands, see <https://pluralkit.me/commands>.");
|
||||
"The proxy help page has been moved! See the website: https://pluralkit.me/guide#proxying");
|
||||
default:
|
||||
// remove compiler warning
|
||||
return ctx.Reply($"{Emojis.Error} Parsed command {ctx.Parameters.Callback().AsCode()} not implemented in PluralKit.Bot!");
|
||||
}
|
||||
if (ctx.Match("system", "s"))
|
||||
return HandleSystemCommand(ctx);
|
||||
|
|
@ -50,13 +52,6 @@ public partial class CommandTree
|
|||
return ctx.Execute<ImportExport>(Import, m => m.Import(ctx));
|
||||
if (ctx.Match("export"))
|
||||
return ctx.Execute<ImportExport>(Export, m => m.Export(ctx));
|
||||
if (ctx.Match("help", "h"))
|
||||
if (ctx.Match("commands"))
|
||||
return ctx.Reply("For the list of commands, see the website: <https://pluralkit.me/commands>");
|
||||
else if (ctx.Match("proxy"))
|
||||
return ctx.Reply(
|
||||
"The proxy help page has been moved! See the website: https://pluralkit.me/guide#proxying");
|
||||
else return ctx.Execute<Help>(Help, m => m.HelpRoot(ctx));
|
||||
if (ctx.Match("explain"))
|
||||
return ctx.Execute<Help>(Explain, m => m.Explain(ctx));
|
||||
if (ctx.Match("message", "msg", "messageinfo"))
|
||||
|
|
|
|||
|
|
@ -57,8 +57,12 @@ public class Context
|
|||
}
|
||||
catch (PKError e)
|
||||
{
|
||||
// todo: not this
|
||||
Reply($"{Emojis.Error} {e.Message}");
|
||||
// don't send an "invalid command" response if the guild has those turned off
|
||||
if (!(GuildConfig != null && GuildConfig!.InvalidCommandResponseEnabled != true))
|
||||
{
|
||||
// todo: not this
|
||||
Reply($"{Emojis.Error} {e.Message}");
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
[command!(
|
||||
["thunder"],
|
||||
"fun_thunder",
|
||||
"Shows the help command"
|
||||
"fun thunder"
|
||||
)]
|
||||
.into_iter()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
command!(
|
||||
[help, "commands"],
|
||||
"help_commands",
|
||||
"Commands"
|
||||
"help commands"
|
||||
),
|
||||
command!(
|
||||
[help, "proxy"],
|
||||
"help_proxy",
|
||||
"help proxy"
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
),
|
||||
command!([system, new], "system_new", "Creates a new system"),
|
||||
command!(
|
||||
[system, new, FullString],
|
||||
[system, new, SystemRef],
|
||||
"system_new",
|
||||
"Creates a new system"
|
||||
),
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ fn parse_command(input: String) -> CommandResult {
|
|||
// todo: check if last token is a common incorrect unquote (multi-member names etc)
|
||||
// todo: check if this is a system name in pk;s command
|
||||
return CommandResult::Err {
|
||||
error: "Command not found.".to_string(),
|
||||
error: format!("Unknown command `{input}`. For a list of possible commands, see <https://pluralkit.me/commands>."),
|
||||
};
|
||||
}
|
||||
Err(Some(short_circuit)) => {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ pub enum Token {
|
|||
MemberRef,
|
||||
MemberPrivacyTarget,
|
||||
|
||||
/// System reference
|
||||
SystemRef,
|
||||
|
||||
PrivacyLevel,
|
||||
|
||||
// currently not included in command definitions
|
||||
|
|
@ -32,13 +35,7 @@ pub enum TokenMatchResult {
|
|||
}
|
||||
|
||||
// move this somewhere else
|
||||
lazy_static::lazy_static!(
|
||||
static ref MEMBER_PRIVACY_TARGETS: Vec<SmolStr> = [
|
||||
"visibility",
|
||||
"name",
|
||||
"todo",
|
||||
].into_iter().map(SmolStr::new_static).collect();
|
||||
);
|
||||
const MEMBER_PRIVACY_TARGETS: &[&str] = &["visibility", "name", "todo"];
|
||||
|
||||
impl Token {
|
||||
pub fn try_match(&self, input: Option<SmolStr>) -> TokenMatchResult {
|
||||
|
|
@ -66,12 +63,9 @@ impl Token {
|
|||
}
|
||||
Self::MultiValue(_) => todo!(),
|
||||
Self::FullString => return TokenMatchResult::Match(Some(input)),
|
||||
Self::SystemRef => return TokenMatchResult::Match(Some(input)),
|
||||
Self::MemberRef => return TokenMatchResult::Match(Some(input)),
|
||||
Self::MemberPrivacyTarget
|
||||
if MEMBER_PRIVACY_TARGETS
|
||||
.iter()
|
||||
.any(|target| target.eq(input.trim())) =>
|
||||
{
|
||||
Self::MemberPrivacyTarget if MEMBER_PRIVACY_TARGETS.contains(&input.trim()) => {
|
||||
return TokenMatchResult::Match(Some(input))
|
||||
}
|
||||
Self::MemberPrivacyTarget => {}
|
||||
|
|
@ -107,4 +101,4 @@ impl ToToken for [&str] {
|
|||
fn to_token(&self) -> Token {
|
||||
Token::Value(self.into_iter().map(|s| s.to_smolstr()).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue