From fa74585d0d5130eef71a36b1a0054e92d2f0a04e Mon Sep 17 00:00:00 2001 From: Valdemar Erk Date: Sat, 16 Nov 2024 16:17:12 +0100 Subject: [PATCH 1/2] feat(util): add contexts to command builder --- twilight-util/src/builder/command.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/twilight-util/src/builder/command.rs b/twilight-util/src/builder/command.rs index 50884b1eeb..e5a1a3adc3 100644 --- a/twilight-util/src/builder/command.rs +++ b/twilight-util/src/builder/command.rs @@ -45,9 +45,12 @@ //! ``` use twilight_model::{ - application::command::{ - Command, CommandOption, CommandOptionChoice, CommandOptionChoiceValue, CommandOptionType, - CommandOptionValue, CommandType, + application::{ + command::{ + Command, CommandOption, CommandOptionChoice, CommandOptionChoiceValue, + CommandOptionType, CommandOptionValue, CommandType, + }, + interaction::InteractionContextType, }, channel::ChannelType, guild::Permissions, @@ -112,6 +115,15 @@ impl CommandBuilder { self } + /// Set the contexts of the command. + /// + /// Defaults to nothing. + pub fn contexts(mut self, contexts: impl IntoIterator) -> Self { + self.0.contexts = Some(contexts.into_iter().collect()); + + self + } + /// Set the default member permission required to run the command. /// /// Defaults to [`None`]. @@ -127,6 +139,7 @@ impl CommandBuilder { /// Set whether the command is available in DMs. /// /// Defaults to [`None`]. + #[deprecated(note = "use contexts instead")] #[allow(deprecated)] pub const fn dm_permission(mut self, dm_permission: bool) -> Self { self.0.dm_permission = Some(dm_permission); From eee612e16109f3156e043f4c8928eee0b9f9c6e9 Mon Sep 17 00:00:00 2001 From: Valdemar Erk Date: Sat, 16 Nov 2024 17:40:12 +0100 Subject: [PATCH 2/2] Also add integration types --- twilight-util/src/builder/command.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/twilight-util/src/builder/command.rs b/twilight-util/src/builder/command.rs index e5a1a3adc3..b4dc06df8e 100644 --- a/twilight-util/src/builder/command.rs +++ b/twilight-util/src/builder/command.rs @@ -55,6 +55,7 @@ use twilight_model::{ channel::ChannelType, guild::Permissions, id::{marker::GuildMarker, Id}, + oauth::ApplicationIntegrationType, }; use twilight_validate::command::{command as validate_command, CommandValidationError}; @@ -164,6 +165,18 @@ impl CommandBuilder { self } + /// Set the integration types for the command. + /// + /// Defaults to `None`. + pub fn integration_types( + mut self, + integration_types: impl IntoIterator, + ) -> Self { + self.0.integration_types = Some(integration_types.into_iter().collect()); + + self + } + /// Set the localization dictionary for the command name. /// /// Defaults to [`None`].