Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(util): add contexts and integration types to command builder #2386

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions twilight-util/src/builder/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@
//! ```

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,
id::{marker::GuildMarker, Id},
oauth::ApplicationIntegrationType,
};
use twilight_validate::command::{command as validate_command, CommandValidationError};

Expand Down Expand Up @@ -112,6 +116,15 @@ impl CommandBuilder {
self
}

/// Set the contexts of the command.
///
/// Defaults to nothing.
pub fn contexts(mut self, contexts: impl IntoIterator<Item = InteractionContextType>) -> Self {
self.0.contexts = Some(contexts.into_iter().collect());

self
}

/// Set the default member permission required to run the command.
///
/// Defaults to [`None`].
Expand All @@ -127,6 +140,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);
Expand All @@ -151,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<Item = ApplicationIntegrationType>,
) -> Self {
self.0.integration_types = Some(integration_types.into_iter().collect());

self
}

/// Set the localization dictionary for the command name.
///
/// Defaults to [`None`].
Expand Down