improve play messages
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-06-05 19:10:54 +02:00
parent d25fa48575
commit 1acab1254b
2 changed files with 33 additions and 4 deletions

View File

@@ -8,7 +8,6 @@ use std::{error::Error, ops::Sub, time::Duration};
use tokio::process::Command; use tokio::process::Command;
use tracing::debug; use tracing::debug;
use twilight_model::application::interaction::Interaction; use twilight_model::application::interaction::Interaction;
use twilight_model::channel::message::MessageFlags;
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType}; use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
use twilight_util::builder::InteractionResponseDataBuilder; use twilight_util::builder::InteractionResponseDataBuilder;
use url::Url; use url::Url;
@@ -25,8 +24,7 @@ pub(crate) async fn play(
); );
let interaction_response_data = InteractionResponseDataBuilder::new() let interaction_response_data = InteractionResponseDataBuilder::new()
.content("Adding tracks to the queue ...") .content(format!("Adding track(s) to queue: {}", query))
.flags(MessageFlags::EPHEMERAL)
.build(); .build();
let response = InteractionResponse { let response = InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource, kind: InteractionResponseType::ChannelMessageWithSource,
@@ -63,10 +61,17 @@ pub(crate) async fn play(
vec![query] vec![query]
}; };
if let Some(call_lock) = state.songbird.get(guild_id) {
let call = call_lock.lock().await;
call.queue().resume()?;
}
let mut tracks_added = vec![];
for url in urls { for url in urls {
let mut src = YoutubeDl::new(reqwest::Client::new(), url.to_string()); let mut src = YoutubeDl::new(reqwest::Client::new(), url.to_string());
if let Ok(metadata) = src.aux_metadata().await { if let Ok(metadata) = src.aux_metadata().await {
debug!("metadata: {:?}", metadata); debug!("metadata: {:?}", metadata);
tracks_added.push(metadata.title.clone());
if let Some(call_lock) = state.songbird.get(guild_id) { if let Some(call_lock) = state.songbird.get(guild_id) {
let mut call = call_lock.lock().await; let mut call = call_lock.lock().await;
@@ -88,6 +93,30 @@ pub(crate) async fn play(
} }
} }
} }
let mut content = String::new();
let num_tracks_added = tracks_added.len();
match num_tracks_added {
0 => {}
1 => {
content = format!(
"Added {} to queue",
tracks_added.first().unwrap().clone().unwrap()
);
}
_ => {
content = format!("Added {} tracks to queue:\n", num_tracks_added);
for track in tracks_added.into_iter().take(num_tracks_added.max(3)) {
content.push_str(&format!("{}\n", track.unwrap()));
}
}
}
state
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.content(Some(&content))
.unwrap()
.await?;
Ok(()) Ok(())
} }

View File

@@ -27,7 +27,7 @@ pub(crate) async fn resume(
} }
let interaction_response_data = InteractionResponseDataBuilder::new() let interaction_response_data = InteractionResponseDataBuilder::new()
.content("Resumed the track") .content("Resumed playing")
.flags(MessageFlags::EPHEMERAL) .flags(MessageFlags::EPHEMERAL)
.build(); .build();