From 3f1a4d113e71fc412ec05a319d5ffd5a3d7a78bc Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 01:09:07 +0200 Subject: fir auto completion and send file in the response body upon grajcuj file --- src/commands/music.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/commands') diff --git a/src/commands/music.rs b/src/commands/music.rs index 05abb9c..6acac00 100644 --- a/src/commands/music.rs +++ b/src/commands/music.rs @@ -253,6 +253,7 @@ async fn play_impl( }) .ok_or_else(lang::err_not_in_voice)?; + let file_reupload = file.as_ref().map(|f| (f.url.clone(), f.filename.clone())); let src = resolve_source(ctx, melodia, file).await?; let call; @@ -296,7 +297,7 @@ async fn play_impl( .lock() .await .insert(guild_id.get(), handle); - ctx.say(lang::fmt_music_playing(&src.display_name)).await?; + send_music_msg(ctx, &src.display_name, file_reupload).await?; return Ok(()); } info!(url = %redact_url(&src.url), "downloading for compression"); @@ -365,7 +366,7 @@ async fn play_impl( .await .insert(guild_id.get(), handle); - ctx.say(lang::fmt_music_playing(&src.display_name)).await?; + send_music_msg(ctx, &src.display_name, file_reupload).await?; Ok(()) } @@ -412,6 +413,37 @@ pub async fn join(ctx: Context<'_>) -> Result<()> { Ok(()) } +/// Send the "playing" message, optionally reuploading a user-provided file +/// so other channel members can download it. +async fn send_music_msg( + ctx: Context<'_>, + display_name: &str, + file_reupload: Option<(String, String)>, +) -> Result<()> { + if let Some((url, filename)) = file_reupload { + match ctx.data().http_client.get(&url).send().await { + Ok(resp) => match resp.bytes().await { + Ok(bytes) => { + if ctx + .send(poise::CreateReply::default().content(lang::fmt_music_playing(display_name)).attachment( + serenity::CreateAttachment::bytes(bytes.to_vec(), filename.clone()), + )) + .await + .is_ok() + { + return Ok(()); + } + error!("send_music_msg: ctx.send with attachment failed, falling back"); + } + Err(e) => error!("send_music_msg: failed to read file bytes: {e}"), + }, + Err(e) => error!("send_music_msg: failed to download file: {e}"), + } + } + ctx.say(lang::fmt_music_playing(display_name)).await?; + Ok(()) +} + pub fn commands() -> Vec> { vec![grajcuj(), stop(), join()] } -- cgit v1.2.3