fix: send correct error message if a parsed command is not implemented, etc

This commit is contained in:
dusk 2025-01-05 02:21:23 +09:00
parent 2027da40ad
commit 1a781014bd
No known key found for this signature in database
7 changed files with 31 additions and 33 deletions

View file

@ -10,14 +10,16 @@ public partial class CommandTree
{ {
case "fun_thunder": case "fun_thunder":
return ctx.Execute<Fun>(null, m => m.Thunder(ctx)); return ctx.Execute<Fun>(null, m => m.Thunder(ctx));
default: case "help":
// don't send an "invalid command" response if the guild has those turned off return ctx.Execute<Help>(Help, m => m.HelpRoot(ctx));
if (ctx.GuildConfig != null && ctx.GuildConfig!.InvalidCommandResponseEnabled != true) case "help_commands":
return Task.CompletedTask; return ctx.Reply("For the list of commands, see the website: <https://pluralkit.me/commands>");
case "help_proxy":
// remove compiler warning
return ctx.Reply( 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")) if (ctx.Match("system", "s"))
return HandleSystemCommand(ctx); return HandleSystemCommand(ctx);
@ -50,13 +52,6 @@ public partial class CommandTree
return ctx.Execute<ImportExport>(Import, m => m.Import(ctx)); return ctx.Execute<ImportExport>(Import, m => m.Import(ctx));
if (ctx.Match("export")) if (ctx.Match("export"))
return ctx.Execute<ImportExport>(Export, m => m.Export(ctx)); 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")) if (ctx.Match("explain"))
return ctx.Execute<Help>(Explain, m => m.Explain(ctx)); return ctx.Execute<Help>(Explain, m => m.Explain(ctx));
if (ctx.Match("message", "msg", "messageinfo")) if (ctx.Match("message", "msg", "messageinfo"))

View file

@ -57,8 +57,12 @@ public class Context
} }
catch (PKError e) catch (PKError e)
{ {
// todo: not this // don't send an "invalid command" response if the guild has those turned off
Reply($"{Emojis.Error} {e.Message}"); if (!(GuildConfig != null && GuildConfig!.InvalidCommandResponseEnabled != true))
{
// todo: not this
Reply($"{Emojis.Error} {e.Message}");
}
throw; throw;
} }
} }

View file

@ -4,7 +4,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
[command!( [command!(
["thunder"], ["thunder"],
"fun_thunder", "fun_thunder",
"Shows the help command" "fun thunder"
)] )]
.into_iter() .into_iter()
} }

View file

@ -11,7 +11,12 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!( command!(
[help, "commands"], [help, "commands"],
"help_commands", "help_commands",
"Commands" "help commands"
),
command!(
[help, "proxy"],
"help_proxy",
"help proxy"
), ),
] ]
.into_iter() .into_iter()

View file

@ -14,7 +14,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
), ),
command!([system, new], "system_new", "Creates a new system"), command!([system, new], "system_new", "Creates a new system"),
command!( command!(
[system, new, FullString], [system, new, SystemRef],
"system_new", "system_new",
"Creates a new system" "Creates a new system"
), ),

View file

@ -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 last token is a common incorrect unquote (multi-member names etc)
// todo: check if this is a system name in pk;s command // todo: check if this is a system name in pk;s command
return CommandResult::Err { 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)) => { Err(Some(short_circuit)) => {

View file

@ -18,6 +18,9 @@ pub enum Token {
MemberRef, MemberRef,
MemberPrivacyTarget, MemberPrivacyTarget,
/// System reference
SystemRef,
PrivacyLevel, PrivacyLevel,
// currently not included in command definitions // currently not included in command definitions
@ -32,13 +35,7 @@ pub enum TokenMatchResult {
} }
// move this somewhere else // move this somewhere else
lazy_static::lazy_static!( const MEMBER_PRIVACY_TARGETS: &[&str] = &["visibility", "name", "todo"];
static ref MEMBER_PRIVACY_TARGETS: Vec<SmolStr> = [
"visibility",
"name",
"todo",
].into_iter().map(SmolStr::new_static).collect();
);
impl Token { impl Token {
pub fn try_match(&self, input: Option<SmolStr>) -> TokenMatchResult { pub fn try_match(&self, input: Option<SmolStr>) -> TokenMatchResult {
@ -66,12 +63,9 @@ impl Token {
} }
Self::MultiValue(_) => todo!(), Self::MultiValue(_) => todo!(),
Self::FullString => return TokenMatchResult::Match(Some(input)), Self::FullString => return TokenMatchResult::Match(Some(input)),
Self::SystemRef => return TokenMatchResult::Match(Some(input)),
Self::MemberRef => return TokenMatchResult::Match(Some(input)), Self::MemberRef => return TokenMatchResult::Match(Some(input)),
Self::MemberPrivacyTarget Self::MemberPrivacyTarget if MEMBER_PRIVACY_TARGETS.contains(&input.trim()) => {
if MEMBER_PRIVACY_TARGETS
.iter()
.any(|target| target.eq(input.trim())) =>
{
return TokenMatchResult::Match(Some(input)) return TokenMatchResult::Match(Some(input))
} }
Self::MemberPrivacyTarget => {} Self::MemberPrivacyTarget => {}
@ -107,4 +101,4 @@ impl ToToken for [&str] {
fn to_token(&self) -> Token { fn to_token(&self) -> Token {
Token::Value(self.into_iter().map(|s| s.to_smolstr()).collect()) Token::Value(self.into_iter().map(|s| s.to_smolstr()).collect())
} }
} }