spectacles_model/guild/
role.rs

1use crate::snowflake::Snowflake;
2
3/// Represents a Discord Role.
4#[derive(Clone, Debug, Serialize, Deserialize)]
5pub struct Role {
6    /// The snowflake ID of this role.
7    pub id: Snowflake,
8    /// The name of this role.
9    pub name: String,
10    /// The hexadecimal color code for this role.
11    pub color: i32,
12    /// whether or not this role is hoisted.
13    #[serde(rename = "hoist")]
14    pub hoisted: bool,
15    /// The position of this role.
16    pub position: i32,
17    /// Whether or not this role is managed by an integration.
18    pub managed: bool,
19    /// Whether or not this role is mentionable.
20    pub mentionable: bool
21}
22
23/// Options for creating a role in a guild.
24#[derive(Clone, Debug, Deserialize, Serialize, Default)]
25pub struct CreateRoleOptions {
26    #[serde(skip_serializing_if = "Option::is_none")]
27    name: Option<String>,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    permissions: Option<i32>,
30    #[serde(skip_serializing_if = "Option::is_none")]
31    color: Option<i32>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    hoist: Option<bool>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    mentionable: Option<bool>,
36}
37
38impl CreateRoleOptions {
39    /// Sets the name of the role.
40    pub fn name(mut self, name: &str) -> Self {
41        self.name = Some(name.to_string());
42        self
43    }
44
45    /// Sets the permissions that this role should have.
46    pub fn permissions(mut self, perms: i32) -> Self {
47        self.permissions = Some(perms);
48        self
49    }
50
51    /// Sets the color of the role.
52    pub fn color(mut self, clr: i32) -> Self {
53        self.color = Some(clr);
54        self
55    }
56
57    /// Sets the hoisted status of this role.
58    pub fn hoisted(mut self, opt: bool) -> Self {
59        self.hoist = Some(opt);
60        self
61    }
62
63    /// Sets the mentionable status of this user.
64    pub fn mentionable(mut self, opt: bool) -> Self {
65        self.mentionable = Some(opt);
66        self
67    }
68}
69
70/// Options for modifying a role in a guild.
71#[derive(Clone, Debug, Deserialize, Serialize, Default)]
72pub struct ModifyRoleOptions {
73    #[serde(skip_serializing_if = "Option::is_none")]
74    name: Option<String>,
75    #[serde(skip_serializing_if = "Option::is_none")]
76    permissions: Option<i32>,
77    #[serde(skip_serializing_if = "Option::is_none")]
78    color: Option<i32>,
79    #[serde(skip_serializing_if = "Option::is_none")]
80    hoist: Option<bool>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    mentionable: Option<bool>,
83}
84
85impl ModifyRoleOptions {
86    /// Sets a new name for the role.
87    pub fn name(mut self, name: &str) -> Self {
88        self.name = Some(name.to_string());
89        self
90    }
91
92    /// Sets the new permissions for the role.
93    pub fn permissions(mut self, perms: i32) -> Self {
94        self.permissions = Some(perms);
95        self
96    }
97
98    /// Sets the new color of the role.
99    pub fn color(mut self, clr: i32) -> Self {
100        self.color = Some(clr);
101        self
102    }
103
104    /// Sets the hoist status of this role.
105    pub fn hoisted(mut self, opt: bool) -> Self {
106        self.hoist = Some(opt);
107        self
108    }
109
110    /// Sets the mentionable status of this role.
111    pub fn mentionable(mut self, opt: bool) -> Self {
112        self.mentionable = Some(opt);
113        self
114    }
115}
116
117/// Represents a packet sent by the gateway when a guild role is created/updated.
118#[derive(Clone, Debug, Serialize, Deserialize)]
119pub struct GuildRoleCreateOrUpdate {
120    /// The guild ID of the guild.
121    pub guild_id: Snowflake,
122    /// The role that was created.
123    pub role: Role
124}
125
126/// Represents a packet sent by the gateway when a guild role is deleted.
127#[derive(Clone, Debug, Serialize, Deserialize)]
128pub struct GuildRoleDelete {
129    /// The guild ID of the guild.
130    pub guild_id: Snowflake,
131    /// The role ID of the role that was deleted.
132    pub role_id: Snowflake
133}