Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions src/builder/create_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct CreateCommandOption<'a> {
min_length: Option<u16>,
#[serde(default)]
max_length: Option<u16>,
#[serde(skip_serializing_if = "<[_]>::is_empty")]
file_types: Cow<'a, [Cow<'a, str>]>,
#[serde(default)]
autocomplete: bool,
}
Expand Down Expand Up @@ -68,6 +70,7 @@ impl<'a> CreateCommandOption<'a> {
channel_types: Cow::default(),
choices: Cow::default(),
options: Cow::default(),
file_types: Cow::default(),
}
}

Expand Down Expand Up @@ -317,6 +320,21 @@ impl<'a> CreateCommandOption<'a> {
self
}

/// If the option is an [`Attachment`], sets the file types to filter for.
///
/// Can be `image`, `video`, `audio`, or any dot-prefixed extension such as `.pdf`. Maximum of
/// 10 types.
///
/// **Note**: This only matches against the file extension. See [File Type Filtering] for
/// details.
///
/// [`Attachment`]: crate::model::application::CommandOptionType::Attachment
/// [File Type Filtering]: https://docs.discord.com/developers/reference#file-type-filtering
pub fn file_types(mut self, file_types: impl Into<Cow<'a, [Cow<'a, str>]>>) -> Self {
self.file_types = file_types.into();
self
}

pub fn into_owned(self) -> CreateCommandOption<'static> {
let Self {
kind,
Expand All @@ -332,6 +350,7 @@ impl<'a> CreateCommandOption<'a> {
max_value,
min_length,
max_length,
file_types,
autocomplete,
} = self;
CreateCommandOption {
Expand Down Expand Up @@ -364,6 +383,9 @@ impl<'a> CreateCommandOption<'a> {
max_value,
min_length,
max_length,
file_types: Cow::Owned(
file_types.into_owned().into_iter().map(|f| f.into_owned().into()).collect(),
),
autocomplete,
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/builder/create_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,8 @@ pub struct CreateFileUpload<'a> {
min_values: u8,
max_values: u8,
required: bool,
#[serde(skip_serializing_if = "<[_]>::is_empty")]
file_types: Cow<'a, [Cow<'a, str>]>,
}

impl<'a> CreateFileUpload<'a> {
Expand All @@ -828,6 +830,7 @@ impl<'a> CreateFileUpload<'a> {
min_values: 1,
max_values: 1,
required: true,
file_types: Cow::default(),
}
}

Expand All @@ -850,20 +853,38 @@ impl<'a> CreateFileUpload<'a> {
self
}

/// Sets the file types to filter for.
///
/// Can be `image`, `video`, `audio`, or any dot-prefixed extension such as `.pdf`. Maximum of
/// 10 types.
///
/// **Note**: This only matches against the file extension. See [File Type Filtering] for
/// details.
///
/// [File Type Filtering]: https://docs.discord.com/developers/reference#file-type-filtering
pub fn file_types(mut self, file_types: impl Into<Cow<'a, [Cow<'a, str>]>>) -> Self {
self.file_types = file_types.into();
self
}

pub fn into_owned(self) -> CreateFileUpload<'static> {
let Self {
kind,
custom_id,
min_values,
max_values,
required,
file_types,
} = self;
CreateFileUpload {
kind,
custom_id: custom_id.into_owned().into(),
min_values,
max_values,
required,
file_types: Cow::Owned(
file_types.into_owned().into_iter().map(|f| f.into_owned().into()).collect(),
),
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/model/application/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ pub struct CommandOption {
/// Maximum permitted length for String options
#[serde(default)]
pub max_length: Option<u16>,
/// If the option is an [`Attachment`], the file types to filter for.
///
/// Can be `image`, `video`, `audio`, or any dot-prefixed extension such as `.pdf`. Maximum
/// of 10 types.
///
/// **Note**: This only matches against the file extension. See [File Type Filtering] for
/// details.
///
/// [`Attachment`]: CommandOptionType::Attachment
/// [File Type Filtering]: https://docs.discord.com/developers/reference#file-type-filtering
#[serde(default)]
pub file_types: FixedArray<FixedString>,
#[serde(default)]
pub autocomplete: bool,
}
Expand Down
Loading