aboutsummaryrefslogtreecommitdiffstats
path: root/src/commands/music.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-07-31 01:09:07 +0200
committersalmonik <salmonik@tuta.io>2026-07-31 01:09:07 +0200
commit3f1a4d113e71fc412ec05a319d5ffd5a3d7a78bc (patch)
treec0eefa2d0a04c6dab74b471536fe31e7f4d4b559 /src/commands/music.rs
parentfix: auto completion timing out before ready + fix preexisting warns (diff)
downloadsenator-sperma-3f1a4d113e71fc412ec05a319d5ffd5a3d7a78bc.tar.gz
senator-sperma-3f1a4d113e71fc412ec05a319d5ffd5a3d7a78bc.zip
fir auto completion and send file in the response body upon grajcuj file
Diffstat (limited to 'src/commands/music.rs')
-rw-r--r--src/commands/music.rs36
1 files changed, 34 insertions, 2 deletions
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(
253 }) 253 })
254 .ok_or_else(lang::err_not_in_voice)?; 254 .ok_or_else(lang::err_not_in_voice)?;
255 255
256 let file_reupload = file.as_ref().map(|f| (f.url.clone(), f.filename.clone()));
256 let src = resolve_source(ctx, melodia, file).await?; 257 let src = resolve_source(ctx, melodia, file).await?;
257 258
258 let call; 259 let call;
@@ -296,7 +297,7 @@ async fn play_impl(
296 .lock() 297 .lock()
297 .await 298 .await
298 .insert(guild_id.get(), handle); 299 .insert(guild_id.get(), handle);
299 ctx.say(lang::fmt_music_playing(&src.display_name)).await?; 300 send_music_msg(ctx, &src.display_name, file_reupload).await?;
300 return Ok(()); 301 return Ok(());
301 } 302 }
302 info!(url = %redact_url(&src.url), "downloading for compression"); 303 info!(url = %redact_url(&src.url), "downloading for compression");
@@ -365,7 +366,7 @@ async fn play_impl(
365 .await 366 .await
366 .insert(guild_id.get(), handle); 367 .insert(guild_id.get(), handle);
367 368
368 ctx.say(lang::fmt_music_playing(&src.display_name)).await?; 369 send_music_msg(ctx, &src.display_name, file_reupload).await?;
369 Ok(()) 370 Ok(())
370} 371}
371 372
@@ -412,6 +413,37 @@ pub async fn join(ctx: Context<'_>) -> Result<()> {
412 Ok(()) 413 Ok(())
413} 414}
414 415
416/// Send the "playing" message, optionally reuploading a user-provided file
417/// so other channel members can download it.
418async fn send_music_msg(
419 ctx: Context<'_>,
420 display_name: &str,
421 file_reupload: Option<(String, String)>,
422) -> Result<()> {
423 if let Some((url, filename)) = file_reupload {
424 match ctx.data().http_client.get(&url).send().await {
425 Ok(resp) => match resp.bytes().await {
426 Ok(bytes) => {
427 if ctx
428 .send(poise::CreateReply::default().content(lang::fmt_music_playing(display_name)).attachment(
429 serenity::CreateAttachment::bytes(bytes.to_vec(), filename.clone()),
430 ))
431 .await
432 .is_ok()
433 {
434 return Ok(());
435 }
436 error!("send_music_msg: ctx.send with attachment failed, falling back");
437 }
438 Err(e) => error!("send_music_msg: failed to read file bytes: {e}"),
439 },
440 Err(e) => error!("send_music_msg: failed to download file: {e}"),
441 }
442 }
443 ctx.say(lang::fmt_music_playing(display_name)).await?;
444 Ok(())
445}
446
415pub fn commands() -> Vec<poise::Command<Data, Error>> { 447pub fn commands() -> Vec<poise::Command<Data, Error>> {
416 vec![grajcuj(), stop(), join()] 448 vec![grajcuj(), stop(), join()]
417} 449}