Skip to content

Commit d946753

Browse files
committed
Split built-in commands in help embed
1 parent efeb946 commit d946753

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/discord_bot/commands.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -463,24 +463,52 @@ async fn help(
463463
role_toggles.sort();
464464
tricks.sort();
465465

466+
let mut embed_builder = CreateEmbed::new().title("ProtoBot command help");
467+
468+
let mut built_in_commands = String::new();
469+
let mut built_in_commands_len = 0;
470+
let mut built_in_commands_embed_count: usize = 0;
471+
for command in commands {
472+
let next_command = format!("• **{}**: {}", command.name, command.description);
473+
let next_command_len = next_command.chars().count();
474+
475+
if built_in_commands_len + 1 + next_command_len > 1024 {
476+
let embed_name = if built_in_commands_embed_count == 0 {
477+
"Built-in commands:".to_owned()
478+
} else {
479+
format!("Built-in commands ({})", built_in_commands_embed_count + 1)
480+
};
481+
built_in_commands_embed_count += 1;
482+
embed_builder =
483+
embed_builder.field(embed_name, std::mem::take(&mut built_in_commands), false);
484+
built_in_commands_len = 0;
485+
}
486+
487+
if built_in_commands_len == 0 {
488+
built_in_commands = next_command;
489+
built_in_commands_len = next_command_len;
490+
} else {
491+
built_in_commands.push('\n');
492+
built_in_commands.push_str(&next_command);
493+
built_in_commands_len += 1 + next_command_len;
494+
}
495+
}
496+
497+
if built_in_commands_len > 0 {
498+
let embed_name = if built_in_commands_embed_count == 0 {
499+
"Built-in commands:".to_owned()
500+
} else {
501+
format!("Built-in commands ({})", built_in_commands_embed_count + 1)
502+
};
503+
embed_builder = embed_builder.field(embed_name, built_in_commands, false);
504+
}
505+
466506
message
467507
.channel_id
468508
.send_message(
469509
ctx,
470510
CreateMessage::new().reference_message(message).embed(
471-
CreateEmbed::new()
472-
.title("ProtoBot command help")
473-
.field(
474-
"Built-in commands:",
475-
commands
476-
.iter()
477-
.map(|command| {
478-
format!("• **{}**: {}", command.name, command.description)
479-
})
480-
.collect::<Vec<_>>()
481-
.join("\n"),
482-
false,
483-
)
511+
embed_builder
484512
.field(
485513
"Role toggles:",
486514
if role_toggles.is_empty() {

0 commit comments

Comments
 (0)