RMusicBot/src/player/commands/list.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

2018-11-14 14:29:58 +00:00
use super::super::prelude::*;
2019-07-12 08:39:03 +00:00
use serenity::prelude::*;
use serenity::{
framework::standard::{macros::command, Args, CommandResult},
model::channel::Message,
};
#[command]
fn list(ctx: &mut Context, msg: &Message, _: Args) -> CommandResult {
if !channel_contains_author(ctx, msg) {
println!(
"user {} is not in the same voice channel as the bot",
msg.author.name
);
return Ok(());
2018-11-14 14:29:58 +00:00
}
2019-07-12 08:39:03 +00:00
let mut output = String::new();
let data = ctx.data.read();
let media = match data.get::<MediaData>() {
Ok(media) => media,
Err(_) => {
msg.channel_id.say("could not find media data");
2018-11-23 12:18:07 +00:00
return Ok(());
}
2019-07-12 08:39:03 +00:00
};
2018-11-23 12:18:07 +00:00
2019-07-12 08:39:03 +00:00
let playlist = media.playlist();
2018-11-14 14:29:58 +00:00
2019-07-12 08:39:03 +00:00
output += &format!(
"{} {} queued\n",
playlist.len(),
if playlist.len() == 1 { "song" } else { "songs" }
);
2018-11-14 14:29:58 +00:00
2019-07-12 08:39:03 +00:00
let max_output = 5;
2018-11-17 18:59:10 +00:00
2019-07-12 08:39:03 +00:00
for (i, song) in playlist.iter().enumerate() {
if i < max_output {
output += &format!("\t{}.\t{}\n", i + 1, song.name.clone());
} else {
output += &format!("\t... and {} more", playlist.len() - max_output);
break;
2018-11-14 14:29:58 +00:00
}
2019-07-12 08:39:03 +00:00
}
2018-11-14 14:29:58 +00:00
2019-07-12 08:39:03 +00:00
print_error!(msg.channel_id.say(output));
2018-11-14 14:29:58 +00:00
2019-07-12 08:39:03 +00:00
Ok(())
2018-11-14 14:29:58 +00:00
}