Fix list command and optimize check for user in channel

This commit is contained in:
hodasemi 2018-11-23 14:57:57 +01:00
parent a5a7dfef73
commit de1beb11e7
2 changed files with 47 additions and 35 deletions

View file

@ -42,13 +42,14 @@ impl serenity::framework::standard::Command for List {
if playlist.len() == 1 { "song" } else { "songs" } if playlist.len() == 1 { "song" } else { "songs" }
); );
let max_output = 3; let max_output = 5;
for (i, song) in playlist.iter().enumerate() { for (i, song) in playlist.iter().enumerate() {
if i < max_output { if i < max_output {
output += &format!("\t{}.\t{}\n", i + 1, song.name.clone()); output += &format!("\t{}.\t{}\n", i + 1, song.name.clone());
} else { } else {
output += &format!("\t... and {} more", playlist.len() - max_output); output += &format!("\t... and {} more", playlist.len() - max_output);
break;
} }
} }
} }

View file

@ -31,6 +31,7 @@ pub fn channel_contains_author(
ctx: &mut serenity::client::Context, ctx: &mut serenity::client::Context,
msg: &serenity::model::channel::Message, msg: &serenity::model::channel::Message,
) -> bool { ) -> bool {
let (guild_id, voice_channel_id_bot) = {
let manager_lock = ctx.data.lock().get::<VoiceManager>().cloned().unwrap(); let manager_lock = ctx.data.lock().get::<VoiceManager>().cloned().unwrap();
let mut manager = manager_lock.lock(); let mut manager = manager_lock.lock();
@ -50,7 +51,18 @@ pub fn channel_contains_author(
} }
}; };
if let Some(voice_channel_id_bot) = handler.channel_id { (
guild_id,
match handler.channel_id {
Some(id) => id,
None => {
println!("error getting channel_id for bot");
return false;
}
},
)
};
let author = &msg.author; let author = &msg.author;
let guild = match guild_id.to_guild_cached() { let guild = match guild_id.to_guild_cached() {
@ -76,7 +88,6 @@ pub fn channel_contains_author(
return false; return false;
} }
} }
}
true true
} }