autoleave empty voice channels
This commit is contained in:
parent
c92c0d2207
commit
580bbb5105
101
src/main.rs
101
src/main.rs
@ -289,62 +289,81 @@ impl EventHandler for Handler {
|
|||||||
old: Option<VoiceState>,
|
old: Option<VoiceState>,
|
||||||
new: VoiceState,
|
new: VoiceState,
|
||||||
) {
|
) {
|
||||||
if let (Some(guild_id), Some(user_channel)) = (guild_id_opt, new.channel_id) {
|
if let Some(past_state) = old {
|
||||||
if old.is_none() {
|
if let (Some(guild_id), None) = (guild_id_opt, new.channel_id) {
|
||||||
if let Some(guild) = ctx.cache.guild(guild_id).await {
|
if let Some(channel_id) = past_state.channel_id {
|
||||||
let pool = ctx
|
if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx).await
|
||||||
.data
|
{
|
||||||
.read()
|
if channel.members(&ctx).await.map(|m| m.len()).unwrap_or(0) <= 1 {
|
||||||
.await
|
let voice_manager_lock = ctx
|
||||||
.get::<MySQL>()
|
.data
|
||||||
.cloned()
|
.read()
|
||||||
.expect("Could not get SQLPool from data");
|
.await
|
||||||
|
.get::<VoiceManager>()
|
||||||
|
.cloned()
|
||||||
|
.expect("Could not get VoiceManager from data");
|
||||||
|
|
||||||
let guild_data_opt = GuildData::get_from_id(guild, pool.clone()).await;
|
let mut voice_manager = voice_manager_lock.lock().await;
|
||||||
|
|
||||||
if let Some(guild_data) = guild_data_opt {
|
voice_manager.leave(guild_id);
|
||||||
if guild_data.allow_greets {
|
}
|
||||||
let join_id_res = sqlx::query!(
|
}
|
||||||
"
|
}
|
||||||
|
}
|
||||||
|
} 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
|
||||||
|
.read()
|
||||||
|
.await
|
||||||
|
.get::<MySQL>()
|
||||||
|
.cloned()
|
||||||
|
.expect("Could not get SQLPool from data");
|
||||||
|
|
||||||
|
let guild_data_opt = GuildData::get_from_id(guild, pool.clone()).await;
|
||||||
|
|
||||||
|
if let Some(guild_data) = guild_data_opt {
|
||||||
|
if guild_data.allow_greets {
|
||||||
|
let join_id_res = sqlx::query!(
|
||||||
|
"
|
||||||
SELECT join_sound_id
|
SELECT join_sound_id
|
||||||
FROM users
|
FROM users
|
||||||
WHERE user = ? AND join_sound_id IS NOT NULL
|
WHERE user = ? AND join_sound_id IS NOT NULL
|
||||||
",
|
",
|
||||||
new.user_id.as_u64()
|
new.user_id.as_u64()
|
||||||
)
|
)
|
||||||
.fetch_one(&pool)
|
.fetch_one(&pool)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Ok(join_id_record) = join_id_res {
|
if let Ok(join_id_record) = join_id_res {
|
||||||
let join_id = join_id_record.join_sound_id;
|
let join_id = join_id_record.join_sound_id;
|
||||||
|
|
||||||
let mut sound = sqlx::query_as_unchecked!(
|
let mut sound = sqlx::query_as_unchecked!(
|
||||||
Sound,
|
Sound,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, plays, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
",
|
",
|
||||||
join_id
|
join_id
|
||||||
)
|
)
|
||||||
.fetch_one(&pool)
|
.fetch_one(&pool)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let voice_manager_lock = ctx
|
||||||
|
.data
|
||||||
|
.read()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.get::<VoiceManager>()
|
||||||
|
.cloned()
|
||||||
|
.expect("Could not get VoiceManager from data");
|
||||||
|
|
||||||
let voice_manager_lock = ctx
|
let mut voice_manager = voice_manager_lock.lock().await;
|
||||||
.data
|
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.get::<VoiceManager>()
|
|
||||||
.cloned()
|
|
||||||
.expect("Could not get VoiceManager from data");
|
|
||||||
|
|
||||||
let mut voice_manager = voice_manager_lock.lock().await;
|
if let Some(handler) = voice_manager.join(guild_id, user_channel) {
|
||||||
|
let _audio =
|
||||||
if let Some(handler) = voice_manager.join(guild_id, user_channel) {
|
play_audio(&mut sound, guild_data, handler, pool).await;
|
||||||
let _audio =
|
|
||||||
play_audio(&mut sound, guild_data, handler, pool).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user