From 4cf17263d11ae0416fb2fd8a72e30b7fd458537d Mon Sep 17 00:00:00 2001 From: dusk Date: Sat, 11 Jan 2025 23:11:15 +0900 Subject: [PATCH] feat(commands): only show max N amount of suggestions --- crates/commands/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/commands/src/lib.rs b/crates/commands/src/lib.rs index 22a1e6a4..b82813ed 100644 --- a/crates/commands/src/lib.rs +++ b/crates/commands/src/lib.rs @@ -17,6 +17,9 @@ use tree::TreeBranch; pub use commands::Command; pub use token::*; +// todo: this should come from the bot probably +const MAX_SUGGESTIONS: usize = 7; + lazy_static::lazy_static! { pub static ref COMMAND_TREE: TreeBranch = { let mut tree = TreeBranch::empty(); @@ -109,7 +112,7 @@ pub fn parse_command(prefix: String, input: String) -> CommandResult { let possible_commands = local_tree.possible_commands(2); if !possible_commands.is_empty() { error.push_str(" Perhaps you meant to use one of the commands below:\n"); - for command in possible_commands { + for command in possible_commands.iter().take(MAX_SUGGESTIONS) { if !command.show_in_suggestions { continue } writeln!(&mut error, "- **{prefix}{command}** - *{}*", command.help) .expect("oom");