aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/commands/music.rs28
-rw-r--r--src/main.rs39
2 files changed, 45 insertions, 22 deletions
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>;
15// ── Source classification ────────────────────────────────────────── 15// ── Source classification ──────────────────────────────────────────
16 16
17/// Music playback and queue management. 17/// Music playback and queue management.
18#[poise::command(slash_command, subcommands("grajcuj", "skip", "queue"))] 18#[poise::command(
19 slash_command,
20 subcommands("grajcuj", "skip", "queue", "stop", "join")
21)]
19pub async fn music(_ctx: Context<'_>) -> Result<()> { 22pub async fn music(_ctx: Context<'_>) -> Result<()> {
20 Ok(()) 23 Ok(())
21} 24}
@@ -29,25 +32,8 @@ pub async fn grajcuj(
29 melodia: Option<String>, 32 melodia: Option<String>,
30 #[description = "Bezpośredni plik z twojego systemu"] file: Option<serenity::Attachment>, 33 #[description = "Bezpośredni plik z twojego systemu"] file: Option<serenity::Attachment>,
31 #[description = "Chujowa kompresja!?"] compressed: Option<bool>, 34 #[description = "Chujowa kompresja!?"] compressed: Option<bool>,
32 #[description = "Gdzie dodać utwór w kolejce (domyślnie: last)"] position: Option< 35 #[description = "Gdzie dodać utwór w kolejce (domyślnie: last)"]
33 QueuePosition, 36 position: Option<QueuePosition>,
34 >,
35) -> Result<()> {
36 play_command(ctx, melodia, file, compressed, position).await
37}
38
39/// Play music from Copyparty, URL, or file upload (top-level alias)
40#[poise::command(slash_command, rename = "grajcuj")]
41pub async fn grajcuj_top(
42 ctx: Context<'_>,
43 #[description = "Plik do odtworzenia"]
44 #[autocomplete = "audio_file"]
45 melodia: Option<String>,
46 #[description = "Bezpośredni plik z twojego systemu"] file: Option<serenity::Attachment>,
47 #[description = "Chujowa kompresja!?"] compressed: Option<bool>,
48 #[description = "Gdzie dodać utwór w kolejce (domyślnie: last)"] position: Option<
49 QueuePosition,
50 >,
51) -> Result<()> { 37) -> Result<()> {
52 play_command(ctx, melodia, file, compressed, position).await 38 play_command(ctx, melodia, file, compressed, position).await
53} 39}
@@ -404,5 +390,5 @@ pub async fn message_grajcuj(ctx: Context<'_>, message: serenity::Message) -> Re
404} 390}
405 391
406pub fn commands() -> Vec<poise::Command<Data, Error>> { 392pub fn commands() -> Vec<poise::Command<Data, Error>> {
407 vec![music(), grajcuj_top(), stop(), join(), message_grajcuj()] 393 vec![music(), message_grajcuj()]
408} 394}
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 @@
1use std::collections::HashMap; 1use std::collections::{HashMap, HashSet};
2use std::sync::Arc; 2use std::sync::Arc;
3use std::time::{Duration, Instant}; 3use 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