1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use serde::{Deserialize, Serialize};
use crate::types::Snowflake;
/// [Allowed Mentions Structure](https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mentions-structure)
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AllowedMentions {
/// An array of [allowed mention types](https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mention-types) to parse from the content.
pub parse: Vec<AllowedMentionTypes>,
/// Array of role_ids to mention (Max size of 100)
pub roles: Vec<Snowflake>,
/// Array of user_ids to mention (Max size of 100)
pub users: Vec<Snowflake>,
/// For replies, whether to mention the author of the message being replied to (default false)
pub replied_user: bool,
}
/// [Allowed Mention Types](https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mention-types)
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum AllowedMentionTypes {
/// Role mentions in the content
Roles,
/// User mentions in the content
Users,
/// `@everyone` and `@here`
Everyone,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
pub fn serializes() {
let allowed_mentions = AllowedMentions {
parse: vec![AllowedMentionTypes::Roles],
roles: vec![],
users: vec![],
replied_user: false,
};
println!(
"{}",
serde_json::to_string_pretty(&allowed_mentions).unwrap()
);
}
}