Fix list command and optimize check for user in channel
This commit is contained in:
parent
a5a7dfef73
commit
de1beb11e7
2 changed files with 47 additions and 35 deletions
|
@ -42,13 +42,14 @@ impl serenity::framework::standard::Command for List {
|
|||
if playlist.len() == 1 { "song" } else { "songs" }
|
||||
);
|
||||
|
||||
let max_output = 3;
|
||||
let max_output = 5;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,50 +31,61 @@ pub fn channel_contains_author(
|
|||
ctx: &mut serenity::client::Context,
|
||||
msg: &serenity::model::channel::Message,
|
||||
) -> bool {
|
||||
let manager_lock = ctx.data.lock().get::<VoiceManager>().cloned().unwrap();
|
||||
let (guild_id, voice_channel_id_bot) = {
|
||||
let manager_lock = ctx.data.lock().get::<VoiceManager>().cloned().unwrap();
|
||||
|
||||
let mut manager = manager_lock.lock();
|
||||
let guild_id = match guild_id(msg.channel_id) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
println!("error getting guild_id");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
let handler = match handler(guild_id, &mut manager) {
|
||||
Some(handler) => handler,
|
||||
None => {
|
||||
println!("error getting handler");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(voice_channel_id_bot) = handler.channel_id {
|
||||
let author = &msg.author;
|
||||
|
||||
let guild = match guild_id.to_guild_cached() {
|
||||
Some(guild) => guild,
|
||||
let mut manager = manager_lock.lock();
|
||||
let guild_id = match guild_id(msg.channel_id) {
|
||||
Some(guild_id) => guild_id,
|
||||
None => {
|
||||
println!("error getting guild from cache");
|
||||
println!("error getting guild_id");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
let guild_lock = guild.read();
|
||||
|
||||
let voice_state = match guild_lock.voice_states.get(&author.id) {
|
||||
Some(state) => state,
|
||||
let handler = match handler(guild_id, &mut manager) {
|
||||
Some(handler) => handler,
|
||||
None => {
|
||||
println!("error getting voice state from user {}", author.name);
|
||||
return false;
|
||||
println!("error getting handler");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(voice_channel_id_user) = voice_state.channel_id {
|
||||
if voice_channel_id_bot != voice_channel_id_user {
|
||||
return false;
|
||||
}
|
||||
(
|
||||
guild_id,
|
||||
match handler.channel_id {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
println!("error getting channel_id for bot");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
)
|
||||
};
|
||||
|
||||
let author = &msg.author;
|
||||
|
||||
let guild = match guild_id.to_guild_cached() {
|
||||
Some(guild) => guild,
|
||||
None => {
|
||||
println!("error getting guild from cache");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
let guild_lock = guild.read();
|
||||
|
||||
let voice_state = match guild_lock.voice_states.get(&author.id) {
|
||||
Some(state) => state,
|
||||
None => {
|
||||
println!("error getting voice state from user {}", author.name);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(voice_channel_id_user) = voice_state.channel_id {
|
||||
if voice_channel_id_bot != voice_channel_id_user {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue