diff --git a/src/music/music_manager.rs b/src/music/music_manager.rs index 50af08d..28678be 100644 --- a/src/music/music_manager.rs +++ b/src/music/music_manager.rs @@ -2,11 +2,12 @@ use crate::util::embed::Embed; use crate::util::user_util; use crate::util::user_util::get_vc_id; use crate::music::preview::Preview; -use lavalink_rs::{client::LavalinkClient, player_context::QueueMessage}; +use lavalink_rs::client::LavalinkClient; use lavalink_rs::model::search::SearchEngines; use lavalink_rs::model::track::TrackLoadData; +use lavalink_rs::model::ChannelId; use lavalink_rs::player_context::TrackInQueue; -use serenity::all::{Context, CreateEmbed, GuildId, UserId}; +use serenity::all::{Context, CreateEmbed, GuildId, Http, UserId}; use songbird::error::JoinError; use std::sync::Arc; @@ -49,12 +50,17 @@ pub async fn attempt_to_queue_song( // match handler { Ok((connection_info, _)) => { - llc.create_player_context( + let Ok(_) = llc + .create_player_context_with_data::<(ChannelId, std::sync::Arc)>( guild_id.get(), - connection_info - ) - .await - .unwrap(); + connection_info, + std::sync::Arc::new(( + ChannelId::from(connect_to.get()), + ctx.http.clone(), + )), + ).await else { + return Embed::create_error_respose(username, "error_title", "error_desc"); + }; } Err(_) => { @@ -140,15 +146,18 @@ pub async fn attempt_to_queue_song( } }; + // let q = player.get_queue(); + // q.append(tracks.into()); - let q = player.get_queue(); - q.append(tracks.into()); + let Ok(_) = player.play_now(&tracks[0].track).await else { + return Embed::create_error_respose(username, "Error playing", "Could not play track."); + }; - if let Ok(player_data) = player.get_player().await { - if player_data.track.is_none() && q.get_track(0).await.is_ok_and(|x| x.is_some()) { - player.skip(); - } - } + // if let Ok(player_data) = player.get_player().await { + // if player_data.track.is_none() && q.get_track(0).await.is_ok_and(|x| x.is_some()) { + // player.skip(); + // } + // } @@ -308,9 +317,11 @@ pub async fn leave(ctx: &Context, llc: &LavalinkClient, guild_id: &GuildId) -> R return Err(JoinError::NoSender); }; - let Ok(_) = llc.delete_player(guild_id.get()).await else { - return Err(JoinError::Dropped); - }; + if llc.get_player_context(guild_id.get()).is_some() { + let Ok(_) = llc.delete_player(guild_id.get()).await else { + return Err(JoinError::NoCall) + }; + } if songbird.get(GuildId::new(guild_id.get())).is_some() { let Ok(_) = songbird.remove(GuildId::new(guild_id.get())).await else {