From bab3f614f8b42545fdb0101c4e353c87e0966d47 Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 27 Oct 2026 18:18:07 +0100 Subject: music: group playback commands under /music Graduate grajcuj/skip/queue/stop/join into the /music parent and drop the top-level names. On startup, reconcile global slash commands and delete any that are no longer registered, since Discord otherwise keeps stale commands after a rename or move. Docs updated for the new command layout and queue semantics. --- src/commands/music.rs | 28 +++++++--------------------- src/main.rs | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/commands/music.rs b/src/commands/music.rs index 8841329..26e655e 100644 --- a/src/commands/music.rs +++ b/src/commands/music.rs @@ -15,7 +15,10 @@ type Context<'a> = poise::Context<'a, Data, Error>; // ── Source classification ────────────────────────────────────────── /// Music playback and queue management. -#[poise::command(slash_command, subcommands("grajcuj", "skip", "queue"))] +#[poise::command( + slash_command, + subcommands("grajcuj", "skip", "queue", "stop", "join") +)] pub async fn music(_ctx: Context<'_>) -> Result<()> { Ok(()) } @@ -29,25 +32,8 @@ pub async fn grajcuj( melodia: Option, #[description = "Bezpośredni plik z twojego systemu"] file: Option, #[description = "Chujowa kompresja!?"] compressed: Option, - #[description = "Gdzie dodać utwór w kolejce (domyślnie: last)"] position: Option< - QueuePosition, - >, -) -> Result<()> { - play_command(ctx, melodia, file, compressed, position).await -} - -/// Play music from Copyparty, URL, or file upload (top-level alias) -#[poise::command(slash_command, rename = "grajcuj")] -pub async fn grajcuj_top( - ctx: Context<'_>, - #[description = "Plik do odtworzenia"] - #[autocomplete = "audio_file"] - melodia: Option, - #[description = "Bezpośredni plik z twojego systemu"] file: Option, - #[description = "Chujowa kompresja!?"] compressed: Option, - #[description = "Gdzie dodać utwór w kolejce (domyślnie: last)"] position: Option< - QueuePosition, - >, + #[description = "Gdzie dodać utwór w kolejce (domyślnie: last)"] + position: Option, ) -> Result<()> { play_command(ctx, melodia, file, compressed, position).await } @@ -404,5 +390,5 @@ pub async fn message_grajcuj(ctx: Context<'_>, message: serenity::Message) -> Re } pub fn commands() -> Vec> { - vec![music(), grajcuj_top(), stop(), join(), message_grajcuj()] + vec![music(), message_grajcuj()] } diff --git a/src/main.rs b/src/main.rs index 4e308b8..8d11d76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -236,6 +236,43 @@ async fn main() -> Result<(), Box> { poise::builtins::register_globally(ctx, &framework.options().commands).await?; + // Discord keeps global commands that disappear from the + // registration payload. Delete leftovers from renamed or + // removed commands so the move under `/music` is visible. + let expected: HashSet = framework + .options() + .commands + .iter() + .map(|command| { + command + .context_menu_name + .clone() + .unwrap_or_else(|| command.name.clone()) + }) + .collect(); + match ctx.http.get_global_commands().await { + Ok(existing) => { + for command in existing { + if !expected.contains(&command.name) { + match ctx.http.delete_global_command(command.id).await { + Ok(()) => tracing::info!( + command = %command.name, + "removed stale global command" + ), + Err(e) => tracing::warn!( + command = %command.name, + error = %e, + "failed to remove stale global command" + ), + } + } + } + } + Err(e) => { + tracing::warn!(error = %e, "could not list global commands for cleanup") + } + } + events::handle_ready(ctx).await.map_err(|e| { tracing::error!("on_ready handler: {e}"); e -- cgit v1.2.3