WIP: tried some stuff, still not playing. I suspect that lavalink does not get connected properly

This commit is contained in:
moonleay 2024-05-21 03:04:55 +02:00
parent 880e81646d
commit 6d4319e9e5
Signed by: moonleay
GPG key ID: 82667543CCD715FB

View file

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