From bd33f22b3018ef681b616c78f439fcaea77a0132 Mon Sep 17 00:00:00 2001 From: Johannes Heuel Date: Fri, 16 Feb 2024 14:32:39 +0100 Subject: [PATCH] add new commands to published commands --- src/commands/mod.rs | 17 +++++++++++++++++ src/main.rs | 17 +++++------------ src/metadata.rs | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 8ba472b..134bd4c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -18,3 +18,20 @@ pub(crate) use resume::resume; mod stop; pub(crate) use stop::stop; + +use twilight_model::application::command::CommandType; +use twilight_util::builder::command::{CommandBuilder, StringBuilder}; + +pub(crate) fn get_chat_commands() -> Vec { + vec![ + CommandBuilder::new("join", "Join the channel", CommandType::ChatInput).build(), + CommandBuilder::new("leave", "Leave the channel", CommandType::ChatInput).build(), + CommandBuilder::new("pause", "Pause playing", CommandType::ChatInput).build(), + CommandBuilder::new("play", "Add a song to the queue", CommandType::ChatInput) + .option(StringBuilder::new("query", "URL of a song").required(true)) + .build(), + CommandBuilder::new("queue", "Print track queue", CommandType::ChatInput).build(), + CommandBuilder::new("resume", "Resume playing", CommandType::ChatInput).build(), + CommandBuilder::new("stop", "Stop playing", CommandType::ChatInput).build(), + ] +} diff --git a/src/main.rs b/src/main.rs index ff07403..4ff881c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,10 @@ use twilight_gateway::{ Intents, Shard, }; use twilight_http::Client as HttpClient; -use twilight_model::application::command::CommandType; use twilight_model::id::Id; use twilight_standby::Standby; -use twilight_util::builder::command::{CommandBuilder, StringBuilder}; + +use crate::commands::get_chat_commands; #[tokio::main] async fn main() -> Result<(), Box> { @@ -55,16 +55,9 @@ async fn main() -> Result<(), Box> { let application_id = Id::new(app_id); let interaction_client = http.interaction(application_id); - let commands = &[ - CommandBuilder::new("play", "Add a song to the queue", CommandType::ChatInput) - .option(StringBuilder::new("query", "URL of a song").required(true)) - .build(), - CommandBuilder::new("stop", "Stop playing", CommandType::ChatInput).build(), - CommandBuilder::new("join", "Join the channel", CommandType::ChatInput).build(), - CommandBuilder::new("leave", "Leave the channel", CommandType::ChatInput).build(), - ]; - interaction_client.set_global_commands(commands).await?; - + interaction_client + .set_global_commands(&get_chat_commands()) + .await?; let commands = interaction_client.global_commands().await?.models().await?; debug!("Global commands: {:?}", commands); diff --git a/src/metadata.rs b/src/metadata.rs index 90f304e..a1c9406 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -5,6 +5,7 @@ pub(crate) struct Metadata { pub(crate) title: Option, pub(crate) duration: Option, } + pub(crate) struct MetadataMap; impl TypeMapKey for MetadataMap { type Value = Metadata;