diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 7c4d557..4fc3295 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -7,6 +7,9 @@ pub(crate) use leave::leave; mod pause; pub(crate) use pause::pause; +mod skip; +pub(crate) use skip::skip; + mod play; pub(crate) use play::play; diff --git a/src/commands/skip.rs b/src/commands/skip.rs new file mode 100644 index 0000000..dac7c57 --- /dev/null +++ b/src/commands/skip.rs @@ -0,0 +1,45 @@ +use crate::state::State; +use std::error::Error; +use twilight_model::{ + gateway::payload::incoming::InteractionCreate, + http::interaction::{InteractionResponse, InteractionResponseType}, +}; +use twilight_util::builder::InteractionResponseDataBuilder; + +pub(crate) async fn skip( + interaction: Box, + state: State, +) -> Result<(), Box> { + tracing::debug!( + "skip command in guild {:?} in channel {:?} by {:?}", + interaction.guild_id, + interaction.channel, + interaction.author(), + ); + + let Some(guild_id) = interaction.guild_id else { + return Ok(()); + }; + + if let Some(call_lock) = state.songbird.get(guild_id) { + let call = call_lock.lock().await; + call.queue().skip()?; + } + + let interaction_response_data = InteractionResponseDataBuilder::new() + .content("Skipped the next track") + .build(); + + let response = InteractionResponse { + kind: InteractionResponseType::ChannelMessageWithSource, + data: Some(interaction_response_data), + }; + + state + .http + .interaction(interaction.application_id) + .create_response(interaction.id, &interaction.token, &response) + .await?; + + Ok(()) +} diff --git a/src/handler.rs b/src/handler.rs index 662acfc..51a3c2f 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,5 +1,5 @@ use crate::commands::queue::{build_action_row, build_queue_embeds, TRACKS_PER_PAGE}; -use crate::commands::{delete, join, leave, pause, play, queue, resume, stop}; +use crate::commands::{delete, join, leave, pause, play, queue, resume, skip, stop}; use crate::state::State; use futures::Future; use std::error::Error; @@ -19,6 +19,7 @@ enum InteractionCommand { Play(String), Stop, Pause, + Skip, Resume, Leave, Join, @@ -108,6 +109,9 @@ impl Handler { InteractionCommand::Pause => { spawn(pause(interaction, Arc::clone(&self.state))) } + InteractionCommand::Skip => { + spawn(skip(interaction, Arc::clone(&self.state))) + } InteractionCommand::Resume => { spawn(resume(interaction, Arc::clone(&self.state))) } @@ -191,6 +195,7 @@ fn parse_interaction_command(command: &CommandData) -> InteractionCommand { } "stop" => InteractionCommand::Stop, "pause" => InteractionCommand::Pause, + "skip" => InteractionCommand::Skip, "resume" => InteractionCommand::Resume, "leave" => InteractionCommand::Leave, "join" => InteractionCommand::Join,