diff options
| author | salmonik <salmonik@tuta.io> | 2026-09-09 13:25:45 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-09-09 13:25:45 +0200 |
| commit | f512d9d22dc3b57bd53834c393304081e9fd4faa (patch) | |
| tree | 9e959541f4a01c650b31d8b0fb9d6e6118230853 /src/commands/music.rs | |
| parent | assistant replies to the message (diff) | |
| download | senator-sperma-f512d9d22dc3b57bd53834c393304081e9fd4faa.tar.gz senator-sperma-f512d9d22dc3b57bd53834c393304081e9fd4faa.zip | |
message-contextual /grajcuj
Signed-off-by: salmonik <salmonik@tuta.io>
Diffstat (limited to '')
| -rw-r--r-- | src/commands/music.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/commands/music.rs b/src/commands/music.rs index 019a015..e528bf5 100644 --- a/src/commands/music.rs +++ b/src/commands/music.rs | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | use poise::serenity_prelude as serenity; | 1 | use poise::serenity_prelude as serenity; |
| 2 | use super::utilities::{FileType, extract_urls, file_type}; | ||
| 3 | |||
| 2 | use tracing::{error, info}; | 4 | use tracing::{error, info}; |
| 3 | 5 | ||
| 4 | use super::autocomplete::audio_file; | 6 | use super::autocomplete::audio_file; |
| @@ -459,6 +461,26 @@ async fn send_music_msg( | |||
| 459 | Ok(()) | 461 | Ok(()) |
| 460 | } | 462 | } |
| 461 | 463 | ||
| 464 | /// Right-click a message → play the first audio file, or first URL if no audio files. | ||
| 465 | #[poise::command(context_menu_command = "Odtwórz")] | ||
| 466 | pub async fn message_grajcuj(ctx: Context<'_>, message: serenity::Message) -> Result<()> { | ||
| 467 | // Files > links: prefer audio attachments first. | ||
| 468 | if let Some(att) = message | ||
| 469 | .attachments | ||
| 470 | .iter() | ||
| 471 | .find(|a| file_type(&a.filename) == FileType::Audio) | ||
| 472 | { | ||
| 473 | return play_impl(ctx, None, Some(att.clone()), false).await; | ||
| 474 | } | ||
| 475 | // Fallback: first URL in message content. | ||
| 476 | if let Some(url) = extract_urls(&message.content).into_iter().next() { | ||
| 477 | return play_impl(ctx, Some(url), None, false).await; | ||
| 478 | } | ||
| 479 | ctx.say(lang::L_MUSIC_NO_AUDIO_ATTACHMENTS).await?; | ||
| 480 | Ok(()) | ||
| 481 | } | ||
| 482 | |||
| 483 | |||
| 462 | pub fn commands() -> Vec<poise::Command<Data, Error>> { | 484 | pub fn commands() -> Vec<poise::Command<Data, Error>> { |
| 463 | vec![grajcuj(), stop(), join()] | 485 | vec![grajcuj(), stop(), join(), message_grajcuj()] |
| 464 | } | 486 | } |
