forked from serenity-rs/serenity
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for sticker packs, guild stickers, and sticker routes (se…
…renity-rs#1395) This adds the following features: * Add/modify/delete guild stickers * Fetch sticker information * Fetch list of all nitro stickers * Sending stickers in message (up to 3) Breaking change as sticker module is moved out of the channel module and to the root model module. This also adds an additional `mime` and `mime_guess` dependencies as Discord requires the mime type on the file part when creating a sticker via multipart/form-data requests otherwise it will return a 500 Internal Server Error. This dependency is also used by `reqwest` internally.
- Loading branch information
Showing
39 changed files
with
1,350 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::http::AttachmentType; | ||
use crate::internal::prelude::*; | ||
|
||
/// A builder to create or edit a [`Sticker`] for use via a number of model methods. | ||
/// | ||
/// These are: | ||
/// | ||
/// - [`PartialGuild::create_sticker`] | ||
/// - [`Guild::create_sticker`] | ||
/// - [`GuildId::create_sticker`] | ||
/// | ||
/// [`Sticker`]: crate::model::sticker::Sticker | ||
/// [`PartialGuild::create_sticker`]: crate::model::guild::PartialGuild::create_sticker | ||
/// [`Guild::create_sticker`]: crate::model::guild::Guild::create_sticker | ||
/// [`GuildId::create_sticker`]: crate::model::id::GuildId::create_sticker | ||
#[derive(Clone, Debug, Default)] | ||
pub struct CreateSticker<'a>(pub HashMap<&'static str, Value>, pub Option<AttachmentType<'a>>); | ||
|
||
impl<'a> CreateSticker<'a> { | ||
/// The name of the sticker to set. | ||
/// | ||
/// **Note**: Must be between 2 and 30 characters long. | ||
pub fn name<S: ToString>(&mut self, name: S) -> &mut Self { | ||
self.0.insert("name", Value::from(name.to_string())); | ||
self | ||
} | ||
|
||
/// The description of the sticker. | ||
/// | ||
/// **Note**: If not empty, must be between 2 and 100 characters long. | ||
pub fn description<S: ToString>(&mut self, description: S) -> &mut Self { | ||
self.0.insert("description", Value::from(description.to_string())); | ||
self | ||
} | ||
|
||
/// The Discord name of a unicode emoji representing the sticker's expression. | ||
/// | ||
/// **Note**: Must be between 2 and 200 characters long. | ||
pub fn tags<S: ToString>(&mut self, tags: S) -> &mut Self { | ||
self.0.insert("tags", Value::from(tags.to_string())); | ||
self | ||
} | ||
|
||
/// The sticker file. | ||
/// | ||
/// **Note**: Must be a PNG, APNG, or Lottie JSON file, max 500 KB. | ||
pub fn file<T: Into<AttachmentType<'a>>>(&mut self, file: T) -> &mut Self { | ||
self.1 = Some(file.into()); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::internal::prelude::*; | ||
|
||
/// A builder to create or edit a [`Sticker`] for use via a number of model methods. | ||
/// | ||
/// These are: | ||
/// | ||
/// - [`Guild::edit_sticker`] | ||
/// - [`PartialGuild::edit_sticker`] | ||
/// - [`GuildId::edit_sticker`] | ||
/// - [`Sticker::edit`] | ||
/// | ||
/// [`Sticker`]: crate::model::sticker::Sticker | ||
/// [`PartialGuild::edit_sticker`]: crate::model::guild::PartialGuild::edit_sticker | ||
/// [`Guild::edit_sticker`]: crate::model::guild::Guild::edit_sticker | ||
/// [`GuildId::edit_sticker`]: crate::model::id::GuildId::edit_sticker | ||
/// [`Sticker::edit`]: crate::model::sticker::Sticker::edit | ||
#[derive(Clone, Debug, Default)] | ||
pub struct EditSticker(pub HashMap<&'static str, Value>); | ||
|
||
impl EditSticker { | ||
/// The name of the sticker to set. | ||
/// | ||
/// **Note**: Must be between 2 and 30 characters long. | ||
pub fn name<S: ToString>(&mut self, name: S) -> &mut Self { | ||
self.0.insert("name", Value::from(name.to_string())); | ||
self | ||
} | ||
|
||
/// The description of the sticker. | ||
/// | ||
/// **Note**: If not empty, must be between 2 and 100 characters long. | ||
pub fn description<S: ToString>(&mut self, description: S) -> &mut Self { | ||
self.0.insert("description", Value::from(description.to_string())); | ||
self | ||
} | ||
|
||
/// The Discord name of a unicode emoji representing the sticker's expression. | ||
/// | ||
/// **Note**: Must be between 2 and 200 characters long. | ||
pub fn tags<S: ToString>(&mut self, tags: S) -> &mut Self { | ||
self.0.insert("tags", Value::from(tags.to_string())); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.