From eddb49a7754ac22f1dff80265760f4c12e45751f Mon Sep 17 00:00:00 2001 From: Valentine Briese Date: Fri, 20 Sep 2024 12:15:40 -0700 Subject: [PATCH] Better handle subcommands in command list --- src/main.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9da0f98..f0036c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,14 @@ fn print_commands(commands: &[poise::Command]) { fn command_string(command: &poise::Command) -> String { let mut string = String::new(); + for subcommand in &command.subcommands { + string += &command_string(subcommand); + } + + if !command.subcommands.is_empty() { + return string; + } + string += &format!("- `/{}", command.qualified_name); for parameter in &command.parameters { @@ -140,13 +148,7 @@ fn print_commands(commands: &[poise::Command]) { string += &format!("\n### {category}\n\n"); for command in category_commands { - for subcommand in &command.subcommands { - string += &command_string(subcommand); - } - - if command.subcommands.is_empty() { - string += &command_string(command); - } + string += &command_string(command); } } @@ -234,10 +236,10 @@ async fn main( }) .setup(|ctx, _ready, framework| { Box::pin(async move { - start_activity_loop(ctx.clone()); - info!("Activity loop started"); // Omit `category` argument on a command to hide from list print_commands(&framework.options().commands); + start_activity_loop(ctx.clone()); + info!("Activity loop started"); poise::builtins::register_globally(ctx, &framework.options().commands).await?; info!("Commands registered"); octocrab::initialise(Octocrab::builder().personal_token(github_pat).build()?);