spectacles_model/message/
emoji.rs

1use crate::{Snowflake, User};
2
3/// A Discord emote than can be used to react to messages.
4#[derive(Serialize, Deserialize, Debug, Clone, Default)]
5pub struct Emoji {
6    /// The ID of the emoji.
7    pub id: Option<Snowflake>,
8    /// The name of the emoji.
9    pub name: String,
10    /// The roles that the emoji is whitelisted to.
11    #[serde(default)]
12    pub roles: Vec<Snowflake>,
13    /// The user who created this emoji.
14    #[serde(default)]
15    pub user: Option<User>,
16    /// Whether or not this emoji must be wrapped in colons.
17    #[serde(default)]
18    pub require_colons: Option<bool>,
19    /// Whether or not this emoji is managed.
20    #[serde(default)]
21    pub managed: Option<bool>,
22    /// Whether or not this emoji is animated.
23    #[serde(default)]
24    pub animated: Option<bool>
25}
26
27/// A reaction on a message.
28#[derive(Serialize, Deserialize, Debug, Clone, Default)]
29pub struct MessageReaction {
30    /// The times that this reaction has been clicked.
31    pub count: i32,
32    /// Whether or not the current user has reacted on this message.
33    pub me: bool,
34    /// Emoji information.
35    pub emoji: Emoji
36}
37
38/// Query for getting the users who reacted to a message.
39#[derive(Serialize, Deserialize, Debug, Clone, Default)]
40pub struct GetReactionsOptions {
41    #[serde(skip_serializing_if = "Option::is_none")]
42    before: Option<Snowflake>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    after: Option<Snowflake>,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    limit: Option<i32>,
47}
48
49impl GetReactionsOptions {
50    /// Get users before this message ID.
51    pub fn before(mut self, id: Snowflake) -> Self {
52        self.before = Some(id);
53        self
54    }
55
56    /// Get users after this message ID.
57    pub fn after(mut self, id: Snowflake) -> Self {
58        self.after = Some(id);
59        self
60    }
61
62    /// Sets the maximum # of users to return.
63    pub fn limit(mut self, num: i32) -> Self {
64        self.limit = Some(num);
65        self
66    }
67}
68
69#[derive(Serialize, Deserialize, Debug, Clone, Default)]
70pub struct CreateEmojiOptions {
71    name: String,
72    image: String,
73    roles: Vec<Snowflake>,
74}
75
76impl CreateEmojiOptions {
77    /// Sets the name of this emoji.
78    pub fn name(mut self, text: &str) -> Self {
79        self.name = text.to_string();
80        self
81    }
82
83    /// Sets the image for this emoji.
84    /// Discord requires that the image is base64 encoded, in the format listed [here.](https://discordapp.com/developers/docs/resources/user#avatar-data)
85    pub fn image(mut self, text: &str) -> Self {
86        self.image = text.to_string();
87        self
88    }
89
90    /// Sets the roles for which will this emoji will be whitelisted.
91    pub fn roles(mut self, rls: Vec<Snowflake>) -> Self {
92        self.roles = rls;
93        self
94    }
95}
96
97#[derive(Serialize, Deserialize, Debug, Clone, Default)]
98pub struct ModifyEmojiOptions {
99    #[serde(skip_serializing_if = "Option::is_none")]
100    name: Option<String>,
101    #[serde(skip_serializing_if = "Option::is_none")]
102    roles: Option<Vec<Snowflake>>,
103}
104
105impl ModifyEmojiOptions {
106    /// Sets the new name for this emoji.
107    pub fn name(mut self, name: &str) -> Self {
108        self.name = Some(name.to_string());
109        self
110    }
111
112    /// Sets the roles for which will this emoji will be whitelisted.
113    pub fn roles(mut self, rls: Vec<Snowflake>) -> Self {
114        self.roles = Some(rls);
115        self
116    }
117}
118
119/// The gateway event emitted when a guild's emojis are updated.
120#[derive(Serialize, Deserialize, Debug, Clone, Default)]
121pub struct GuildEmojisUpdate {
122    /// The guild ID that the emojis belong to.
123    pub guild_id: Snowflake,
124    /// The collion of guild emojis.
125    pub emojis: Vec<Emoji>
126}