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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use iso8601_timestamp::Timestamp;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use crate::{attachment::Attachment, embed::Embed, member::Member, user::User};
/// Channel message
#[derive(Deserialize, Debug, Clone)]
pub struct Message {
/// Unique message ID
#[serde(rename = "_id")]
pub id: String,
/// Unique value generated by client sending this message
pub nonce: Option<String>,
/// ID of the channel this message was sent in
pub channel: String,
/// ID of the user that sent this message
pub author: String,
/// Message content
pub content: Option<String>,
/// System message
pub system: Option<SystemMessage>,
/// Array of attachments
pub attachments: Option<Vec<Attachment>>,
/// Time at which this message was last edited
pub edited: Option<Timestamp>,
/// Attached embeds to this message
pub embeds: Option<Vec<Embed>>,
/// Array of user ids mentioned in this message
pub mentions: Option<Vec<String>>,
/// Array of message ids this message is replying to
pub replies: Option<Vec<String>>,
/// Hashmap of emoji IDs to array of user IDs
#[serde(default)]
pub reactions: HashMap<String, HashSet<String>>,
/// Information about how this message should be interacted with
#[serde(default)]
pub interactions: Interactions,
/// Name and / or avatar overrides for this message
pub masquerade: Option<Masquerade>,
}
///Partial channel message
#[derive(Deserialize, Debug, Clone)]
pub struct PartialMessage {
/// Unique message ID
#[serde(rename = "_id")]
pub id: Option<String>,
/// Unique value generated by client sending this message
pub nonce: Option<String>,
/// ID of the channel this message was sent in
pub channel: Option<String>,
/// ID of the user that sent this message
pub author: Option<String>,
/// Message content
pub content: Option<String>,
/// System message
pub system: Option<SystemMessage>,
/// Array of attachments
pub attachments: Option<Vec<Attachment>>,
/// Time at which this message was last edited
pub edited: Option<Timestamp>,
/// Attached embeds to this message
pub embeds: Option<Vec<Embed>>,
/// Array of user ids mentioned in this message
pub mentions: Option<Vec<String>>,
/// Array of message ids this message is replying to
pub replies: Option<Vec<String>>,
/// Hashmap of emoji IDs to array of user IDs
pub reactions: Option<HashMap<String, HashSet<String>>>,
/// Information about how this message should be interacted with
pub interactions: Option<Interactions>,
/// Name and / or avatar overrides for this message
pub masquerade: Option<Masquerade>,
}
/// Information to guide interactions on this message
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Interactions {
/// Reactions which should always appear and be distinct
#[serde(skip_serializing_if = "Option::is_none", default)]
pub reactions: Option<HashSet<String>>,
/// Whether reactions should be restricted to the given list
#[serde(default)]
pub restrict_reactions: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Masquerade {
/// Replace the display name shown on this message
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// Replace the avatar shown on this message (URL to image file)
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
/// Replace the display role colour shown on this message
///
/// Must have `ManageRole` permission to use
///
/// This can be any valid CSS colour
#[serde(skip_serializing_if = "Option::is_none")]
pub colour: Option<String>,
}
/// System message type
#[derive(Deserialize, Debug, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum SystemMessage {
Text { content: String },
UserAdded { id: String, by: String },
UserRemove { id: String, by: String },
UserJoined { id: String },
UserLeft { id: String },
UserKicked { id: String },
UserBanned { id: String },
ChannelRenamed { name: String, by: String },
ChannelDescriptionChanged { by: String },
ChannelIconChanged { by: String },
ChannelOwnershipChanged { from: String, to: String },
}
/// Sort used for retrieving messages
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum MessageSort {
/// Sort by the most relevant messages
Relevance,
/// Sort by the newest messages first
Latest,
/// Sort by the oldest messages first
Oldest,
}
/// Appended Information
#[derive(Deserialize, Debug, Clone)]
pub struct AppendMessage {
/// Additional embeds to include in this message
pub embeds: Option<Vec<Embed>>,
}
/// Response used when multiple messages are fetched
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum BulkMessageResponse {
JustMessages(
/// List of messages
Vec<Message>,
),
MessagesAndUsers {
/// List of messages
messages: Vec<Message>,
/// List of users
users: Vec<User>,
/// List of members
members: Option<Vec<Member>>,
},
}
/// Representation of a message reply before it is sent
#[derive(Serialize, Clone, Debug)]
pub struct Reply {
/// Message ID
pub id: String,
/// Whether this reply should mention the message's author
pub mention: bool,
}