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

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

View file

@ -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()

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, FullString],
[system, new, SystemRef],
"system_new",
"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 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)) => {

View file

@ -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())
}
}
}