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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#[cfg(feature = "client")]
use serde::Deserialize;
use serde::Serialize;
use crate::models::{
Channel, ClientUser, DmChannel, Guild, Invite, Member, Message, PartialEmoji, PartialGuild,
Presence, Relationship, Role, User,
};
/// Extra information about member removal.
#[derive(Debug, Serialize)]
#[cfg_attr(feature = "client", derive(Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MemberRemoveInfo {
/// The guild was deleted. Note that this is never sent in `member_remove` events.
Delete,
/// The member left on their own.
Leave,
/// The member was kicked.
Kick {
/// The ID of the moderator that kicked the member.
moderator_id: u64,
},
// TODO: Ban should include ban info
/// The member was banned.
Ban {
/// The ID of the moderator that banned the member.
moderator_id: u64,
},
}
/// An unacknowledged channel.
#[derive(Debug, Serialize)]
#[cfg_attr(feature = "client", derive(Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct UnackedChannel {
/// The ID of the channel.
pub channel_id: u64,
/// The ID of the last message acknowledged in the channel. If this is `None`, then no messages
/// have been acknowledged.
pub last_message_id: Option<u64>,
/// A list of message IDs that have mentioned you since the last time you acknowledged this
/// channel.
pub mentions: Vec<u64>,
}
/// An outbound websocket message sent by harmony, received by the client.
#[derive(Debug, Serialize)]
#[cfg_attr(feature = "client", derive(Deserialize))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[serde(tag = "event", content = "data", rename_all = "snake_case")]
#[allow(clippy::large_enum_variant)]
pub enum OutboundMessage {
/// Sent by harmony when a client first connects to it.
Hello,
/// Ping, sent by harmony to the client.
Ping,
/// Pong, sent by harmony to respond to client's ping event.
Pong,
/// Ready, sent by harmony when it is ready to send and receive events.
Ready {
/// The ID of the current session.
session_id: String,
/// The client user of the current session.
user: ClientUser,
/// A list of guilds that the session's user is a member of.
guilds: Vec<Guild>,
/// A list of DM channels that the session's user is a member of.
dm_channels: Vec<DmChannel>,
/// A list of channels or guilds favorited and shown in the user's home sidebar.
favorites: Vec<u64>,
/// An initial array of all presences observed by the user.
presences: Vec<Presence>,
/// A list of relationships associated with the user.
relationships: Vec<Relationship>,
/// A list of unacknowledged messages, organized by channel ID.
unacked: Vec<UnackedChannel>,
/// A list of resolved message data for unacknowledged messages where the client user is
/// mentioned, limited to 100 messages.
inbox: Vec<Message>,
},
/// Sent by harmony when an observable user is updated.
UserUpdate {
/// The user before it was updated.
before: User,
/// The user after it was updated.
after: User,
},
/// Sent by harmony when an observable user is deleted.
UserDelete {
/// The ID of the user that was deleted.
user_id: u64,
},
/// Sent by harmony when the client joins or creates a guild. Note that this does not include
/// guilds received from the `Ready` event, those must be accounted for separately.
GuildCreate {
/// The guild that was joined or created.
guild: Guild,
/// A custom nonce for this guild. This is a random string that if used, a message with the
/// same nonce will be dispatched by the websocket, indicating that the guild was created.
///
/// This is only used once and it is not stored.
nonce: Option<String>,
},
/// Sent by harmony when information about a guild is updated.
GuildUpdate {
/// The updated guild before modifications
before: PartialGuild,
/// The updated guild after modifications
after: PartialGuild,
},
/// Sent by harmony when the client leaves or deletes a guild.
GuildRemove {
/// The ID of the guild that was left or deleted.
guild_id: u64,
/// Extra information about the guild deletion.
#[serde(flatten)]
info: MemberRemoveInfo,
},
/// Sent by harmony when a channel is acknowledged ("marked as read")
ChannelAck {
/// The ID of the channel that was acknowledged.
channel_id: u64,
/// New messages up to this ID can be considered acknowledged.
last_message_id: u64,
},
/// Sent by harmony when a channel is created. This could be any type of channel, including
/// guild channels, DM channels, and group DM channels.
ChannelCreate {
/// The channel that was created.
channel: Channel,
/// A custom nonce for this channel. This is a random string that if used, a message with
/// the same nonce will be dispatched by the websocket, indicating that the channel was
/// created.
///
/// This is only used once, and it is not stored.
nonce: Option<String>,
},
/// Sent by harmony when a channel is modified.
ChannelUpdate {
/// The channel before it was modified.
before: Channel,
/// The channel after modifications.
after: Channel,
},
/// Sent by harmony when a channel is deleted.
ChannelDelete {
/// The ID of the channel that was deleted.
channel_id: u64,
/// The ID of the guild that the channel was deleted in, if any.
guild_id: Option<u64>,
},
/// Sent by harmony when a role is created within a guild.
RoleCreate {
/// The role that was created.
role: Role,
},
/// Sent by harmony when a role is updated.
RoleUpdate {
/// The role before it was modified.
before: Role,
/// The role after it was modified.
after: Role,
},
/// Sent by harmony when role positions are updated.
RolePositionsUpdate {
/// The ID of the guild that the role positions were updated in.
guild_id: u64,
/// A list of role IDs in the order that they should be displayed.
role_ids: Vec<u64>,
},
/// Sent by harmny when a role is deleted.
RoleDelete {
/// The ID of the guild the role was in.
guild_id: u64,
/// The ID of the role that was deleted.
role_id: u64,
},
/// Sent by harmony when a member joins a guild. The guild ID can be retrieved from
/// accessing `member.guild_id`.
MemberJoin {
/// Information about the member that joined the guild.
member: Member,
/// The invite used to join the guild, if any.
invite: Option<Invite>,
},
/// Sent by harmony when a member in a guild is updated. The guild ID can be retrieved from
/// accessing `before.guild_id` or `after.guild_id`.
MemberUpdate {
/// The member before it was modified.
before: Member,
/// The member after it was modified.
after: Member,
},
/// Sent by harmony when a member is removed from a guild. This can be due to a member leaving,
/// being kicked, or being banned.
MemberRemove {
/// The ID of the guild that the member was removed from.
guild_id: u64,
/// The ID of the member that was removed.
user_id: u64,
/// Extra information about the removal.
#[serde(flatten)]
info: MemberRemoveInfo,
},
/// Sent by harmony when a message is sent.
MessageCreate {
/// The message that was sent by a user.
message: Message,
/// A custom nonce for this message. This is a random string that if used, a message with the
/// same nonce will be dispatched by the websocket, indicating that the message was sent.
///
/// This is only used once and it is not stored.
nonce: Option<String>,
},
/// Sent by harmony when a message is updated.
MessageUpdate {
/// The message before it was modified.
before: Message,
/// The message after it was modified.
after: Message,
},
/// Sent by harmony when a message is deleted.
MessageDelete {
/// The ID of the channel that the message was deleted in.
channel_id: u64,
/// The ID of the message that was deleted.
message_id: u64,
},
/// Sent by harmony when a user starts typing.
TypingStart {
/// The ID of the channel that the user is typing in.
channel_id: u64,
/// The ID of the user that is typing.
user_id: u64,
},
/// Sent by harmony when a user stops typing. This is not always sent.
TypingStop {
/// The ID of the channel that the user stopped typing in.
channel_id: u64,
/// The ID of the user that stopped typing.
user_id: u64,
},
/// Sent by harmony when a user adds a reaction to a message.
ReactionAdd {
/// The ID of the channel that the reaction was added in.
channel_id: u64,
/// The ID of the message that the reaction was added to.
message_id: u64,
/// The ID of the user that added the reaction.
user_id: u64,
/// The emoji that was added.
emoji: PartialEmoji,
},
/// Sent by harmony when a user removes a reaction from a message.
ReactionRemove {
/// The ID of the channel that the reaction was removed in.
channel_id: u64,
/// The ID of the message that the reaction was removed from.
message_id: u64,
/// The ID of the user that removed the reaction.
user_id: u64,
/// The ID of the moderator that forced the removal of the reaction. This is `None` if the
/// user removed the reaction themselves.
moderator_id: Option<u64>,
/// The emoji that was removed.
emoji: PartialEmoji,
},
/// Sent by harmony when reactions are removed from a message in bulk.
ReactionRemoveBulk {
/// The ID of the channel that the reactions were removed in.
channel_id: u64,
/// The ID of the message that the reactions were removed from.
message_id: u64,
/// The ID of the moderator that removed the reactions.
moderator_id: u64,
/// The emoji that was removed. If this is `None`, then all reactions were removed.
emoji: Option<PartialEmoji>,
},
/// Sent by harmony when a user updates their presence.
PresenceUpdate {
/// The presence after it was updated. The user ID can be retrieved from accessing
/// `presence.user_id`.
presence: Presence,
},
/// Sent by harmony when a relationship is created. If a relationship already exists, this
/// should be treated as an update and replace it.
RelationshipCreate {
/// The relationship that was created.
relationship: Relationship,
},
/// Sent by harmony when a relationship is removed.
RelationshipRemove {
/// The ID of the user that the relationship was removed with.
user_id: u64,
},
}