Skip to content

Commit

Permalink
Better handle subcommands in command list
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinegb committed Sep 20, 2024
1 parent e2dc4b3 commit eddb49a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ fn print_commands<U, E>(commands: &[poise::Command<U, E>]) {
fn command_string<U, E>(command: &poise::Command<U, E>) -> 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 {
Expand Down Expand Up @@ -140,13 +148,7 @@ fn print_commands<U, E>(commands: &[poise::Command<U, E>]) {
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);
}
}

Expand Down Expand Up @@ -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()?);
Expand Down

0 comments on commit eddb49a

Please sign in to comment.