autoleave empty voice channels

This commit is contained in:
jellywx 2020-11-13 14:26:06 +00:00
parent c92c0d2207
commit 580bbb5105

View File

@ -289,8 +289,28 @@ impl EventHandler for Handler {
old: Option<VoiceState>,
new: VoiceState,
) {
if let (Some(guild_id), Some(user_channel)) = (guild_id_opt, new.channel_id) {
if old.is_none() {
if let Some(past_state) = old {
if let (Some(guild_id), None) = (guild_id_opt, new.channel_id) {
if let Some(channel_id) = past_state.channel_id {
if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx).await
{
if channel.members(&ctx).await.map(|m| m.len()).unwrap_or(0) <= 1 {
let voice_manager_lock = ctx
.data
.read()
.await
.get::<VoiceManager>()
.cloned()
.expect("Could not get VoiceManager from data");
let mut voice_manager = voice_manager_lock.lock().await;
voice_manager.leave(guild_id);
}
}
}
}
} else if let (Some(guild_id), Some(user_channel)) = (guild_id_opt, new.channel_id) {
if let Some(guild) = ctx.cache.guild(guild_id).await {
let pool = ctx
.data
@ -351,7 +371,6 @@ SELECT name, id, plays, public, server_id, uploader_id
}
}
}
}
}
async fn play_audio(