twilight_cache_any_backend/model/
emoji.rs

1use twilight_model::{
2    guild::Emoji,
3    id::{
4        marker::{EmojiMarker, GuildMarker, RoleMarker, UserMarker},
5        Id,
6    },
7};
8
9/// A cached emoji
10///
11/// It's the same as [`twilight_model::guild::Emoji`]
12/// except:
13///
14/// - `guild_id` field is added, making it possible to return a guild's emojis
15///
16/// - `user` field is changed to a user ID, as users are cached separately
17#[derive(Clone, Debug)]
18pub struct CachedEmoji {
19    pub guild_id: Id<GuildMarker>,
20    pub animated: bool,
21    pub available: bool,
22    pub id: Id<EmojiMarker>,
23    pub managed: bool,
24    pub name: String,
25    pub require_colons: bool,
26    pub roles: Vec<Id<RoleMarker>>,
27    pub user: Option<Id<UserMarker>>,
28}
29
30impl CachedEmoji {
31    /// Create a cached emoji from a given emoji and guild ID
32    #[must_use]
33    pub fn from_emoji(emoji: &Emoji, guild_id: Id<GuildMarker>) -> Self {
34        Self {
35            guild_id,
36            animated: emoji.animated,
37            available: emoji.available,
38            id: emoji.id,
39            managed: emoji.managed,
40            name: emoji.name.clone(),
41            require_colons: emoji.require_colons,
42            roles: emoji.roles.clone(),
43            user: emoji.user.as_ref().map(|user| user.id),
44        }
45    }
46}