#[cfg(feature = "model")]
use crate::builder::EditSticker;
#[cfg(feature = "model")]
use crate::http::Http;
#[cfg(feature = "model")]
use crate::internal::prelude::*;
use crate::model::id::{GuildId, StickerId, StickerPackId};
#[cfg(feature = "model")]
use crate::model::prelude::*;
use crate::model::user::User;
use crate::model::utils::comma_separated_string;
pub mod sticker_id;
pub mod sticker_item;
pub mod sticker_pack;
pub use self::sticker_id::*;
pub use self::sticker_item::*;
pub use self::sticker_pack::*;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Sticker {
pub id: StickerId,
pub pack_id: Option<StickerPackId>,
pub name: String,
pub description: Option<String>,
#[serde(with = "comma_separated_string")]
pub tags: Vec<String>,
#[serde(rename = "type")]
pub kind: StickerType,
pub format_type: StickerFormatType,
#[serde(default)]
pub available: bool,
pub guild_id: Option<GuildId>,
pub user: Option<User>,
pub sort_value: Option<u64>,
}
#[cfg(feature = "model")]
impl Sticker {
#[inline]
pub async fn delete(&self, http: impl AsRef<Http>) -> Result<()> {
if let Some(guild_id) = self.guild_id {
guild_id.delete_sticker(&http, self.id).await
} else {
Err(Error::Model(ModelError::DeleteNitroSticker))
}
}
#[inline]
pub async fn edit<F>(&self, http: impl AsRef<Http>, f: F) -> Result<Sticker>
where
F: FnOnce(&mut EditSticker) -> &mut EditSticker,
{
if let Some(guild_id) = self.guild_id {
guild_id.edit_sticker(&http, self.id, f).await
} else {
Err(Error::Model(ModelError::DeleteNitroSticker))
}
}
#[inline]
#[must_use]
pub fn image_url(&self) -> Option<String> {
sticker_url(self.id, self.format_type)
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum StickerType {
Standard = 1,
Guild = 2,
Unknown = !0,
}
enum_number!(StickerType {
Standard,
Guild
});
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[non_exhaustive]
pub enum StickerFormatType {
Png = 1,
Apng = 2,
Lottie = 3,
Unknown = !0,
}
enum_number!(StickerFormatType {
Png,
Apng,
Lottie
});
#[cfg(feature = "model")]
fn sticker_url(sticker_id: StickerId, sticker_format_type: StickerFormatType) -> Option<String> {
let ext = match sticker_format_type {
StickerFormatType::Png | StickerFormatType::Apng => "png",
StickerFormatType::Lottie => "json",
StickerFormatType::Unknown => return None,
};
Some(cdn!("/stickers/{}.{}", sticker_id.0, ext))
}