diff --git a/src/bot/commands/mod.rs b/src/bot/commands/mod.rs index 6c08f02..4d5e4a0 100644 --- a/src/bot/commands/mod.rs +++ b/src/bot/commands/mod.rs @@ -44,6 +44,21 @@ pub async fn respond_message( } } +pub async fn update_message( + ctx: &Context, + command: &ApplicationCommandInteraction, + options: EmbedMessageOptions, +) { + if let Err(why) = command + .edit_original_interaction_response(&ctx.http, |message| { + message.embed(|embed| make_embed_message(embed, options)) + }) + .await + { + error!("Error sending message: {:?}", why); + } +} + pub async fn defer_message( ctx: &Context, command: &ApplicationCommandInteraction, diff --git a/src/bot/commands/music/join.rs b/src/bot/commands/music/join.rs index e65339f..105ba99 100644 --- a/src/bot/commands/music/join.rs +++ b/src/bot/commands/music/join.rs @@ -5,7 +5,7 @@ use serenity::{ }; use crate::{ - bot::commands::{defer_message, respond_message, CommandOutput}, + bot::commands::{defer_message, respond_message, update_message, CommandOutput}, session::manager::{SessionCreateError, SessionManager}, utils::embed::{EmbedBuilder, Status}, }; @@ -92,13 +92,13 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu return; } - defer_message(&ctx, &command, true).await; + defer_message(&ctx, &command, false).await; if let Some(session) = &session_opt { if let Err(why) = session.update_owner(&ctx, command.user.id).await { // Need to link first if let SessionCreateError::NoSpotifyError = why { - respond_message( + update_message( &ctx, &command, EmbedBuilder::new() @@ -107,7 +107,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu .description("You need to link your Spotify account. Use or go to [the accounts website](https://account.spoticord.com/) to get started.") .status(Status::Error) .build(), - true, ) .await; @@ -115,7 +114,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu } // Any other error - respond_message( + update_message( &ctx, &command, EmbedBuilder::new() @@ -124,7 +123,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu .description("An error occured while joining the channel. Please try again later.") .status(Status::Error) .build(), - true, ) .await; @@ -138,7 +136,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu { // Need to link first if let SessionCreateError::NoSpotifyError = why { - respond_message( + update_message( &ctx, &command, EmbedBuilder::new() @@ -147,7 +145,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu .description("You need to link your Spotify account. Use or go to [the accounts website](https://account.spoticord.com/) to get started.") .status(Status::Error) .build(), - true, ) .await; @@ -155,7 +152,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu } // Any other error - respond_message( + update_message( &ctx, &command, EmbedBuilder::new() @@ -164,7 +161,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu .description("An error occured while joining the channel. Please try again later.") .status(Status::Error) .build(), - true, ) .await; @@ -172,7 +168,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu }; } - respond_message( + update_message( &ctx, &command, EmbedBuilder::new() @@ -182,7 +178,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu .footer("Spotify will automatically start playing on Spoticord") .status(Status::Success) .build(), - false, ) .await; }) diff --git a/src/bot/events.rs b/src/bot/events.rs index 40188e1..34fe4d9 100644 --- a/src/bot/events.rs +++ b/src/bot/events.rs @@ -35,8 +35,6 @@ impl EventHandler for Handler { // INTERACTION_CREATE event, emitted when the bot receives an interaction (slash command, button, etc.) async fn interaction_create(&self, ctx: Context, interaction: Interaction) { - trace!("interaction_create START"); - if let Interaction::ApplicationCommand(command) = interaction { // Commands must only be executed inside of guilds @@ -72,7 +70,5 @@ impl EventHandler for Handler { command_manager.execute_command(&ctx, command).await; } - - trace!("interaction_create END"); } } diff --git a/src/session/mod.rs b/src/session/mod.rs index 8935f19..4a175cd 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -282,6 +282,8 @@ impl SpoticordSession { } }; + trace!("Received IPC message: {:?}", msg); + match msg { // Sink requests playback to start/resume IpcPacket::StartPlayback => { @@ -338,7 +340,7 @@ impl SpoticordSession { let track_id = SpotifyId::from_uri(&track).unwrap(); let was_none = ipc_instance - .update_playback(duration_ms, position_ms, true) + .update_playback(duration_ms, position_ms, false) .await; if was_none {