From c84895b7220f669e0dc402841dc771e0782b8c59 Mon Sep 17 00:00:00 2001 From: jude-lafitteIII Date: Fri, 15 May 2020 01:25:46 +0100 Subject: [PATCH] list command :) --- src/main.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2635efc..f8a7547 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,7 @@ lazy_static! { } #[group] -#[commands(info, help)] +#[commands(info, help, list_sounds)] struct AllUsers; #[group] @@ -825,18 +825,39 @@ INSERT INTO roles (guild_id, role) Ok(()) } -#[command] +#[command("list")] async fn list_sounds(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult { let pool = ctx.data.read().await - .get::().cloned().expect("Could not get SQLPool from data"); + .get::().cloned().expect("Could not get SQLPool from data"); let sounds; + let mut message_buffer; if args.rest() == "me" { sounds = Sound::get_user_sounds(*msg.author.id.as_u64(), pool).await?; + + message_buffer = "All your sounds: ".to_string(); } else { sounds = Sound::get_guild_sounds(*msg.guild_id.unwrap().as_u64(), pool).await?; + + message_buffer = "All sounds on this server: ".to_string(); + } + + for sound in sounds { + message_buffer.push_str(format!("**{}** ({}), ", sound.name, if sound.public { "🔓" } else { "🔒" }).as_str()); + + if message_buffer.len() > 2000 { + // send message + msg.channel_id.say(&ctx, message_buffer).await?; + + message_buffer = "".to_string(); + } + } + + if message_buffer.len() > 0 { + // send message + msg.channel_id.say(&ctx, message_buffer).await?; } Ok(())