diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-27 18:18:07 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-27 18:18:07 +0100 |
| commit | bab3f614f8b42545fdb0101c4e353c87e0966d47 (patch) | |
| tree | c257bc4712bba088bea2eab42d93b07e9cfed89c /src/main.rs | |
| parent | music: add per-guild queue with now/next/last, skip and queue (diff) | |
| download | senator-sperma-bab3f614f8b42545fdb0101c4e353c87e0966d47.tar.gz senator-sperma-bab3f614f8b42545fdb0101c4e353c87e0966d47.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | src/main.rs | 39 |
1 files changed, 38 insertions, 1 deletions
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 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::collections::{HashMap, HashSet}; |
| 2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
| 3 | use std::time::{Duration, Instant}; | 3 | use std::time::{Duration, Instant}; |
| 4 | 4 | ||
| @@ -236,6 +236,43 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { | |||
| 236 | 236 | ||
| 237 | poise::builtins::register_globally(ctx, &framework.options().commands).await?; | 237 | poise::builtins::register_globally(ctx, &framework.options().commands).await?; |
| 238 | 238 | ||
| 239 | // Discord keeps global commands that disappear from the | ||
| 240 | // registration payload. Delete leftovers from renamed or | ||
| 241 | // removed commands so the move under `/music` is visible. | ||
| 242 | let expected: HashSet<String> = framework | ||
| 243 | .options() | ||
| 244 | .commands | ||
| 245 | .iter() | ||
| 246 | .map(|command| { | ||
| 247 | command | ||
| 248 | .context_menu_name | ||
| 249 | .clone() | ||
| 250 | .unwrap_or_else(|| command.name.clone()) | ||
| 251 | }) | ||
| 252 | .collect(); | ||
| 253 | match ctx.http.get_global_commands().await { | ||
| 254 | Ok(existing) => { | ||
| 255 | for command in existing { | ||
| 256 | if !expected.contains(&command.name) { | ||
| 257 | match ctx.http.delete_global_command(command.id).await { | ||
| 258 | Ok(()) => tracing::info!( | ||
| 259 | command = %command.name, | ||
| 260 | "removed stale global command" | ||
| 261 | ), | ||
| 262 | Err(e) => tracing::warn!( | ||
| 263 | command = %command.name, | ||
| 264 | error = %e, | ||
| 265 | "failed to remove stale global command" | ||
| 266 | ), | ||
| 267 | } | ||
| 268 | } | ||
| 269 | } | ||
| 270 | } | ||
| 271 | Err(e) => { | ||
| 272 | tracing::warn!(error = %e, "could not list global commands for cleanup") | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 239 | events::handle_ready(ctx).await.map_err(|e| { | 276 | events::handle_ready(ctx).await.map_err(|e| { |
| 240 | tracing::error!("on_ready handler: {e}"); | 277 | tracing::error!("on_ready handler: {e}"); |
| 241 | e | 278 | e |
