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
use model::prelude::*;
use parking_lot::RwLock;
use serde_json::Value;
use std::{
    collections::HashMap,
    sync::Arc
};
use super::context::Context;
use ::client::bridge::gateway::event::*;

/// The core trait for handling events by serenity.
pub trait EventHandler {
    /// Dispatched when the cache gets full.
    /// 
    /// Provides the cached guilds' ids.
    #[cfg(feature = "cache")]
    fn cached(&self, _: Context, _: Vec<GuildId>) {}

    /// Dispatched when a channel is created.
    /// 
    /// Provides said channel's data.
    fn channel_create(&self, _: Context, _: Arc<RwLock<GuildChannel>>) {}

    /// Dispatched when a category is created.
    /// 
    /// Provides said category's data.
    fn category_create(&self, _: Context, _: Arc<RwLock<ChannelCategory>>) {}

    /// Dispatched when a category is deleted.
    /// 
    /// Provides said category's data.
    fn category_delete(&self, _: Context, _: Arc<RwLock<ChannelCategory>>) {}

    /// Dispatched when a private channel is created.
    /// 
    /// Provides said channel's data.
    fn private_channel_create(&self, _: Context, _: Arc<RwLock<PrivateChannel>>) {}

    /// Dispatched when a channel is deleted.
    /// 
    /// Provides said channel's data.
    fn channel_delete(&self, _: Context, _: Arc<RwLock<GuildChannel>>) {}

    /// Dispatched when a pin is added, deleted.
    /// 
    /// Provides said pin's data.
    fn channel_pins_update(&self, _: Context, _: ChannelPinsUpdateEvent) {}

    /// Dispatched when a user is added to a `Group`.
    /// 
    /// Provides the group's id and the user's data.
    fn channel_recipient_addition(&self, _: Context, _: ChannelId, _: User) {}

    /// Dispatched when a user is removed to a `Group`.
    /// 
    /// Provides the group's id and the user's data.
    fn channel_recipient_removal(&self, _: Context, _: ChannelId, _: User) {}

    /// Dispatched when a channel is updated.
    /// 
    /// Provides the old channel data, and the new data.
    #[cfg(feature = "cache")]
    fn channel_update(&self, _: Context, _: Option<Channel>, _: Channel) {}

    /// Dispatched when a channel is updated.
    /// 
    /// Provides the new data.
    #[cfg(not(feature = "cache"))]
    fn channel_update(&self, _: Context, _: Channel) {}

    /// Dispatched when a user is banned from a guild.
    /// 
    /// Provides the guild's id and the banned user's data.
    fn guild_ban_addition(&self, _: Context, _: GuildId, _: User) {}

    /// Dispatched when a user's ban is lifted from a guild.
    /// 
    /// /// Provides the guild's id and the lifted user's data.
    fn guild_ban_removal(&self, _: Context, _: GuildId, _: User) {}

    /// Dispatched when a guild is created; 
    /// or an existing guild's data is sent to us.
    /// 
    /// Provides the guild's data and whether the guild is new.
    #[cfg(feature = "cache")]
    fn guild_create(&self, _: Context, _: Guild, _: bool) {}

    /// Dispatched when a guild is created; 
    /// or an existing guild's data is sent to us.
    /// 
    /// Provides the guild's data.
    #[cfg(not(feature = "cache"))]
    fn guild_create(&self, _: Context, _: Guild) {}

    /// Dispatched when a guild is deleted.
    /// 
    /// Provides the partial data of the guild sent by discord,
    /// and the full data from the cache, if available.
    #[cfg(feature = "cache")]
    fn guild_delete(&self, _: Context, _: PartialGuild, _: Option<Arc<RwLock<Guild>>>) {}

    /// Dispatched when a guild is deleted.
    /// 
    /// Provides the partial data of the guild sent by discord.
    #[cfg(not(feature = "cache"))]
    fn guild_delete(&self, _: Context, _: PartialGuild) {}

    /* the emojis were updated. */

    /// Dispatched when the emojis are updated.
    /// 
    /// Provides the guild's id and the new state of the emojis in the guild.
    fn guild_emojis_update(&self, _: Context, _: GuildId, _: HashMap<EmojiId, Emoji>) {}

    /// Dispatched when a guild's integration is added, updated or removed.
    /// 
    /// Provides the guild's id.
    fn guild_integrations_update(&self, _: Context, _: GuildId) {}

    /// Dispatched when a user joins a guild.
    /// 
    /// Provides the guild's id and the user's member data.
    fn guild_member_addition(&self, _: Context, _: GuildId, _: Member) {}

    /// Dispatched when a user is removed (kicked).
    /// 
    /// Provides the guild's id, the user's data, and the user's member data if available.
    #[cfg(feature = "cache")]
    fn guild_member_removal(&self, _: Context, _: GuildId, _: User, _: Option<Member>) {}

    /// Dispatched when a user is removed (kicked).
    /// 
    /// Provides the guild's id, the user's data.
    #[cfg(not(feature = "cache"))]
    fn guild_member_removal(&self, _: Context, _: GuildId, _: User) {}

    /// Dispatched when a member is updated (e.g their nickname is updated)
    /// 
    /// Provides the member's old data (if available) and the new data.
    #[cfg(feature = "cache")]
    fn guild_member_update(&self, _: Context, _: Option<Member>, _: Member) {}

    /// Dispatched when a member is updated (e.g their nickname is updated)
    /// 
    /// Provides the new data.
    #[cfg(not(feature = "cache"))]
    fn guild_member_update(&self, _: Context, _: GuildMemberUpdateEvent) {}

    /// Dispatched when the data for offline members was requested.
    /// 
    /// Provides the guild's id and the data. 
    fn guild_members_chunk(&self, _: Context, _: GuildId, _: HashMap<UserId, Member>) {}

    /// Dispatched when a role is created.
    /// 
    /// Provides the guild's id and the new role's data.
    fn guild_role_create(&self, _: Context, _: GuildId, _: Role) {}

    /// Dispatched when a role is deleted.
    /// 
    /// Provides the guild's id, the role's id and its data if available.
    #[cfg(feature = "cache")]
    fn guild_role_delete(&self, _: Context, _: GuildId, _: RoleId, _: Option<Role>) {}

    /// Dispatched when a role is deleted.
    /// 
    /// Provides the guild's id, the role's id.
    #[cfg(not(feature = "cache"))]
    fn guild_role_delete(&self, _: Context, _: GuildId, _: RoleId) {}

    /// Dispatched when a role is updated.
    /// 
    /// Provides the guild's id, the role's old (if available) and new data.
    #[cfg(feature = "cache")]
    fn guild_role_update(&self, _: Context, _: GuildId, _: Option<Role>, _: Role) {}

    /// Dispatched when a role is updated.
    /// 
    /// Provides the guild's id and the role's new data.
    #[cfg(not(feature = "cache"))]
    fn guild_role_update(&self, _: Context, _: GuildId, _: Role) {}

    /// Dispatched when a guild became unavailable.
    /// 
    /// Provides the guild's id. 
    fn guild_unavailable(&self, _: Context, _: GuildId) {}

    /// Dispatched when the guild is updated.
    /// 
    /// Provides the guild's old full data (if available) and the new, albeit partial data.
    #[cfg(feature = "cache")]
    fn guild_update(&self, _: Context, _: Option<Arc<RwLock<Guild>>>, _: PartialGuild) {}

    /// Dispatched when the guild is updated.
    /// 
    /// Provides the guild's new, albeit partial data.
    #[cfg(not(feature = "cache"))]
    fn guild_update(&self, _: Context, _: PartialGuild) {}

    /// Dispatched when a message is created.
    /// 
    /// Provides the message's data.
    fn message(&self, _: Context, _: Message) {}

    /// Dispatched when a message is deleted.
    /// 
    /// Provides the channel's id and the message's id.
    fn message_delete(&self, _: Context, _: ChannelId, _: MessageId) {}

    /// Dispatched when multiple messages were deleted at once.
    /// 
    /// Provides the channel's id and the deleted messages' ids.
    fn message_delete_bulk(&self, _: Context, _: ChannelId, _: Vec<MessageId>) {}

    /// Dispatched when a new reaction is attached to a message.
    /// 
    /// Provides the reaction's data.
    fn reaction_add(&self, _: Context, _: Reaction) {}

    /// Dispatched when a reaction is dettached from a message.
    /// 
    /// Provides the reaction's data.
    fn reaction_remove(&self, _: Context, _: Reaction) {}

    /// Dispatched when all reactions of a message are dettached from a message.
    /// 
    /// Provides the channel's id and the message's id.
    fn reaction_remove_all(&self, _: Context, _: ChannelId, _: MessageId) {}

    /// Dispatched when a message is updated.
    /// 
    /// Provides the new data of the message.
    fn message_update(&self, _: Context, _: MessageUpdateEvent) {}

    fn presence_replace(&self, _: Context, _: Vec<Presence>) {}

    /// Dispatched when a user's presence is updated (i.e off -> on).
    /// 
    /// Provides the presence's new data.
    fn presence_update(&self, _: Context, _: PresenceUpdateEvent) {}

    /// Dispatched upon startup.
    /// 
    /// Provides data about the bot and the guilds it's in.
    fn ready(&self, _: Context, _: Ready) {}

    /// Dispatched upon reconnection.
    fn resume(&self, _: Context, _: ResumedEvent) {}

    /// Dispatched when a shard's connection stage is updated
    /// 
    /// Provides the context of the shard and the event information about the update.
    fn shard_stage_update(&self, _: Context, _: ShardStageUpdateEvent) {}

    /// Dispatched when a user starts typing.
    fn typing_start(&self, _: Context, _: TypingStartEvent) {}

    /// Dispatched when an unknown event was sent from discord.
    /// 
    /// Provides the event's name and its unparsed data.
    fn unknown(&self, _: Context, _: String, _: Value) {}

    /// Dispatched when the bot's data is updated.
    /// 
    /// Provides the old and new data.
    #[cfg(feature = "cache")]
    fn user_update(&self, _: Context, _: CurrentUser, _: CurrentUser) {}

    /// Dispatched when the bot's data is updated.
    /// 
    /// Provides the new data.
    #[cfg(not(feature = "cache"))]
    fn user_update(&self, _: Context, _: CurrentUser) {}

    /// Dispatched when a guild's voice server was updated (or changed to another one).
    /// 
    /// Provides the voice server's data.
    fn voice_server_update(&self, _: Context, _: VoiceServerUpdateEvent) {}

    /// Dispatched when a user joins, leaves or moves a voice channel.
    /// 
    /// Provides the guild's id (if available) and 
    /// the new state of the guild's voice channels.
    fn voice_state_update(&self, _: Context, _: Option<GuildId>, _: VoiceState) {}

    /// Dispatched when a guild's webhook is updated.
    /// 
    /// Provides the guild's id and the channel's id the webhook belongs in.
    fn webhook_update(&self, _: Context, _: GuildId, _: ChannelId) {}
}