fixed bot handler play

This commit is contained in:
2024-10-13 11:30:51 -04:00
parent 8ee7c524af
commit 0d39cb6a01

View File

@@ -56,7 +56,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
Ok(channel_id) => { Ok(channel_id) => {
log::debug!("<{guild_id}> Play command executed on {channel_id} with track: {track_url:?}"); log::debug!("<{guild_id}> Play command executed on {channel_id} with track: {track_url:?}");
// Handle the track url // Handle the track url
match play_track(ctx, manager, guild_id.to_owned(), track_url).await { match enqueue_track(ctx, manager, guild_id.to_owned(), track_url, true).await {
Ok(count) => { Ok(count) => {
let mut message = format!("Playing {} tracks", count); let mut message = format!("Playing {} tracks", count);
if count == 0 { if count == 0 {
@@ -79,11 +79,12 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
} }
} }
pub async fn play_track( pub async fn enqueue_track(
ctx: &Context, ctx: &Context,
manager: Arc<Songbird>, manager: Arc<Songbird>,
guild_id: GuildId, guild_id: GuildId,
track_url: &str, track_url: &str,
play_now: bool,
) -> SirenResult<i32> { ) -> SirenResult<i32> {
let mut track_count = 0; let mut track_count = 0;
if let Some(handler_lock) = manager.get(guild_id) { if let Some(handler_lock) = manager.get(guild_id) {
@@ -140,11 +141,7 @@ pub async fn play_track(
}; };
let track_handle: TrackHandle; let track_handle: TrackHandle;
let is_queue_empty = handler.queue().is_empty(); let is_queue_empty = handler.queue().is_empty();
if is_queue_empty {
track_handle = handler.play_input(input);
} else {
track_handle = handler.enqueue_input(input).await; track_handle = handler.enqueue_input(input).await;
}
// Set the volume // Set the volume
let _ = track_handle.set_volume(volume); let _ = track_handle.set_volume(volume);
let track_title = metadata.title.unwrap(); let track_title = metadata.title.unwrap();
@@ -159,6 +156,9 @@ pub async fn play_track(
); );
track_count += 1; track_count += 1;
} }
if play_now && !handler.queue().is_empty() {
handler.queue().resume();
}
} }
Ok(track_count) Ok(track_count)
} }