Skip to content

Commit

Permalink
fix help
Browse files Browse the repository at this point in the history
  • Loading branch information
cycle-five committed Jun 29, 2024
1 parent 116e507 commit b0a2532
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
20 changes: 12 additions & 8 deletions crack-core/src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ pub fn help_commands() -> [Command; 1] {

// Contains the built-in help command and surrounding infrastructure

use poise::serenity_prelude as serenity;
use poise::{serenity_prelude as serenity, CreateReply};
use std::fmt::Write as _;

// /// Optional configuration for how the help message from [`help()`] looks
Expand Down Expand Up @@ -553,13 +553,16 @@ async fn help_single_command(
format!("No such command `{}`", command_name)
};

// let reply = CreateReply::default()
// .content(reply)
// .ephemeral(config.ephemeral);

create_paged_embed(ctx, "Help".to_string(), "Help".to_string(), reply, 756).await?;
if reply.len() > 1000 {
let bot_name = ctx.cache().current_user().name.clone();
create_paged_embed(ctx, bot_name, "Help".to_string(), reply, 900).await?;
} else {
let reply = CreateReply::default()
.content(reply)
.ephemeral(config.ephemeral);
ctx.send(reply).await?;
}

// ctx.send(reply).await?;
Ok(())
}

Expand Down Expand Up @@ -685,6 +688,7 @@ async fn help_all_commands(
// .ephemeral(config.ephemeral);

// ctx.send(reply).await?;
create_paged_embed(ctx, "Help".to_string(), "Help".to_string(), menu, 756).await?;
let bot_name = ctx.cache().current_user().name.clone();
create_paged_embed(ctx, bot_name, "Help".to_string(), menu, 900).await?;
Ok(())
}
10 changes: 2 additions & 8 deletions crack-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,7 @@ pub async fn create_paged_embed(
content: String,
page_size: usize,
) -> Result<(), CrackedError> {
let formatted = format!(
r#"```markdown
{}
```"#,
content
);
let page_getter = create_page_getter_newline(&formatted, page_size);
let page_getter = create_page_getter_newline(&content, page_size);
let num_pages = content.len() / page_size + 1;
let page: Arc<RwLock<usize>> = Arc::new(RwLock::new(0));

Expand Down Expand Up @@ -678,7 +672,7 @@ pub fn create_page_getter_newline(
let chunks = split_string_into_chunks_newline(string, chunk_size);
move |page| {
let page = page % chunks.len();
chunks[page].clone()
format!("```markdown\n{}\n```", chunks[page].clone())
}
}

Expand Down

0 comments on commit b0a2532

Please sign in to comment.