reset loop state on leave/stop

This commit is contained in:
2024-06-18 15:49:58 +02:00
parent c0d9f6cad5
commit dbaf1a1374
7 changed files with 51 additions and 19 deletions

View File

@@ -1,6 +1,26 @@
use crate::state::State;
use std::error::Error;
use twilight_model::gateway::payload::incoming::InteractionCreate;
use crate::state::{State, StateRef};
use std::{error::Error, sync::Arc};
use twilight_model::{
gateway::payload::incoming::InteractionCreate,
id::{marker::GuildMarker, Id},
};
pub(crate) async fn leave_channel(
guild_id: Id<GuildMarker>,
state: Arc<StateRef>,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
// stop playing
if let Some(call_lock) = state.songbird.get(guild_id) {
let call = call_lock.lock().await;
call.queue().stop();
}
// leave the voice channel
state.songbird.leave(guild_id).await?;
// reset guild settings
state.guild_settings.remove(&guild_id);
Ok(())
}
pub(crate) async fn leave(
interaction: Box<InteractionCreate>,
@@ -16,6 +36,8 @@ pub(crate) async fn leave(
let Some(guild_id) = interaction.guild_id else {
return Ok(());
};
state.songbird.leave(guild_id).await?;
leave_channel(guild_id, Arc::clone(&state)).await?;
Ok(())
}