fixed playing greet on all voice actions

This commit is contained in:
jellywx 2021-03-15 23:38:05 +00:00
parent 35b3cb81c9
commit 4f2b57a9b3

View File

@ -136,9 +136,10 @@ impl EventHandler for Handler {
&self, &self,
ctx: Context, ctx: Context,
guild_id_opt: Option<GuildId>, guild_id_opt: Option<GuildId>,
_old: Option<VoiceState>, old: Option<VoiceState>,
new: VoiceState, new: VoiceState,
) { ) {
if old.is_none() {
if let (Some(guild_id), Some(user_channel)) = (guild_id_opt, new.channel_id) { if let (Some(guild_id), Some(user_channel)) = (guild_id_opt, new.channel_id) {
if let Some(guild) = ctx.cache.guild(guild_id).await { if let Some(guild) = ctx.cache.guild(guild_id).await {
let pool = ctx let pool = ctx
@ -196,6 +197,16 @@ SELECT name, id, plays, public, server_id, uploader_id
} }
} }
} }
}
}
struct LeaveInactive;
#[async_trait]
impl SongbirdEventHandler for LeaveInactive {
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
None
}
} }
async fn play_audio( async fn play_audio(
@ -239,7 +250,7 @@ async fn join_channel(
.get(&current_user) .get(&current_user)
.and_then(|voice_state| voice_state.channel_id); .and_then(|voice_state| voice_state.channel_id);
if current_voice_state == Some(channel_id) { let (call, res) = if current_voice_state == Some(channel_id) {
let call_opt = songbird.get(guild.id); let call_opt = songbird.get(guild.id);
if let Some(call) = call_opt { if let Some(call) = call_opt {
@ -249,7 +260,14 @@ async fn join_channel(
} }
} else { } else {
songbird.join(guild.id, channel_id).await songbird.join(guild.id, channel_id).await
} };
call.lock().await.add_global_event(
Event::Periodic(Duration::from_secs(300), None),
LeaveInactive {},
);
(call, res)
} }
// entry point // entry point