diff --git a/src/interactions/commands/chat/leaderboard.rs b/src/interactions/commands/chat/leaderboard.rs index f04ef67b..e1302da9 100644 --- a/src/interactions/commands/chat/leaderboard.rs +++ b/src/interactions/commands/chat/leaderboard.rs @@ -1,5 +1,3 @@ -use std::fmt::Write; - use twilight_interactions::command::{CommandModel, CreateCommand}; use crate::{ @@ -33,31 +31,22 @@ impl Leaderboard { } else { Member::list_by_xp_exclude_deleted(&ctx.bot.pool, guild_id, 99, &ctx.bot.cache).await? }; - let mut pages = Vec::new(); - let mut current_page = String::new(); - - for (idx, member) in lb.into_iter().enumerate() { - if idx % 9 == 0 && idx != 0 { - pages.push(current_page); - current_page = String::new(); - } - writeln!( - current_page, - "`#{}` <@{}> - {} XP", - idx + 1, - member.user_id, - member.xp - ) - .unwrap(); - } - pages.push(current_page); + let mut idx = 0; + let pages = lb.chunks(9).map(|chunk| { + chunk + .iter() + .map(|Member { user_id, xp, .. }| { + idx += 1; + format!("`#{idx}` <@{user_id}> - {xp} XP\n") + }) + .collect::() + }); let author_id = ctx.interaction.author_id().unwrap(); paginator::simple( &mut ctx, pages - .into_iter() .map(|p| { ( None, diff --git a/src/interactions/commands/chat/utils/trashcan.rs b/src/interactions/commands/chat/utils/trashcan.rs index dcf984cb..efaf5803 100644 --- a/src/interactions/commands/chat/utils/trashcan.rs +++ b/src/interactions/commands/chat/utils/trashcan.rs @@ -24,30 +24,22 @@ impl TrashCan { return Ok(()); } - let mut pages = Vec::new(); - let mut curr_page = String::new(); - - for (idx, item) in trashed.into_iter().enumerate() { - if idx % 50 == 0 && idx != 0 { - pages.push(curr_page); - curr_page = String::new(); - } - - let link = fmt_message_link(guild_id, item.channel_id, item.message_id); - curr_page.push_str(&format!( - "[{}]({})\n", - item.trash_reason - .unwrap_or_else(|| "No reason given.".to_string()), - link, - )); - } - - pages.push(curr_page); + let pages = trashed.chunks(50).map(|chunk| { + chunk + .iter() + .map(|msg| { + let reason = msg.trash_reason.as_deref().unwrap_or("No reason given."); + let link = fmt_message_link(guild_id, msg.channel_id, msg.message_id); + + format!("[{reason}]({link})\n") + }) + .collect::() + }); let author_id = ctx.interaction.author_id().unwrap(); paginator::simple( &mut ctx, - pages.into_iter().map(|page| (Some(page), None)).collect(), + pages.map(|page| (Some(page), None)).collect(), author_id, true, )