aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/mod.rs
blob: 46bd57b31562297c185e18c598d9fa88dbcb6846 (plain)
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
use futures::stream::{self, StreamExt};
use serenity::{
    all::{
        ActionExecution, ApplicationId, AuditLogEntry, ChannelId, ChannelPinsUpdateEvent,
        CommandPermissions, CurrentUser, Emoji, EmojiId, Guild, GuildChannel, GuildId,
        GuildMemberUpdateEvent, GuildMembersChunkEvent, GuildScheduledEventUserAddEvent,
        GuildScheduledEventUserRemoveEvent, Integration, IntegrationId, Interaction,
        InviteCreateEvent, InviteDeleteEvent, Member, Message, MessageId, MessageUpdateEvent,
        PartialGuild, PartialGuildChannel, Presence, Reaction, Ready, ResumedEvent, Role, RoleId,
        Rule, ScheduledEvent, StageInstance, Sticker, StickerId, ThreadListSyncEvent, ThreadMember,
        ThreadMembersUpdateEvent, TypingStartEvent, UnavailableGuild, User, VoiceServerUpdateEvent,
        VoiceState,
    },
    async_trait,
    client::{Context, EventHandler},
    gateway::ShardStageUpdateEvent,
    http::RatelimitInfo,
};
use std::collections::HashMap;

mod presence_setter;
mod x500_mapper;

pub use self::{
    presence_setter::PresenceSetter,
    x500_mapper::{X500Mapper, X500MapperConfig},
};

/// An EventHandler that proxies events to each of its contained handlers concurrently (but not in
/// parallel).
pub struct MultiHandler(pub Vec<Box<dyn EventHandler>>);

macro_rules! define_multihandler_impl {
    (
        $(async fn $name:ident(&self, $($arg:ident : $argty:ty),* $(,)?);)*
    ) => {
        #[async_trait]
        impl EventHandler for MultiHandler {
            $(async fn $name(
                &self,
                $($arg: $argty),*
            ) {
                stream::iter(self.0.iter())
                    .for_each_concurrent(None, move |handler| {
                        handler.$name($($arg.clone()),*)
                    })
                    .await
            })*
        }
    };
}

define_multihandler_impl! {
    async fn command_permissions_update(&self, ctx: Context, permission: CommandPermissions);
    async fn auto_moderation_rule_create(&self, ctx: Context, rule: Rule);
    async fn auto_moderation_rule_update(&self, ctx: Context, rule: Rule);
    async fn auto_moderation_rule_delete(&self, ctx: Context, rule: Rule);
    async fn auto_moderation_action_execution(&self, ctx: Context, execution: ActionExecution);
    async fn cache_ready(&self, ctx: Context, guilds: Vec<GuildId>);
    async fn shards_ready(&self, ctx: Context, total_shards: u32);
    async fn channel_create(&self, ctx: Context, channel: GuildChannel);
    async fn category_create(&self, ctx: Context, category: GuildChannel);
    async fn category_delete(&self, ctx: Context, category: GuildChannel);
    async fn channel_delete(
        &self,
        ctx: Context,
        channel: GuildChannel,
        messages: Option<Vec<Message>>,
    );
    async fn channel_pins_update(&self, ctx: Context, pin: ChannelPinsUpdateEvent);
    async fn channel_update(&self, ctx: Context, old: Option<GuildChannel>, new: GuildChannel);
    async fn guild_audit_log_entry_create(
        &self,
        ctx: Context,
        entry: AuditLogEntry,
        guild_id: GuildId,
    );
    async fn guild_ban_addition(&self, ctx: Context, guild_id: GuildId, banned_user: User);
    async fn guild_ban_removal(&self, ctx: Context, guild_id: GuildId, unbanned_user: User);
    async fn guild_create(&self, ctx: Context, guild: Guild, is_new: Option<bool>);
    async fn guild_delete(&self, ctx: Context, incomplete: UnavailableGuild, full: Option<Guild>);
    async fn guild_emojis_update(
        &self,
        ctx: Context,
        guild_id: GuildId,
        current_state: HashMap<EmojiId, Emoji>,
    );
    async fn guild_integrations_update(&self, ctx: Context, guild_id: GuildId);
    async fn guild_member_addition(&self, ctx: Context, new_member: Member);
    async fn guild_member_removal(
        &self,
        ctx: Context,
        guild_id: GuildId,
        user: User,
        member_data_if_available: Option<Member>,
    );
    async fn guild_member_update(
        &self,
        ctx: Context,
        old_if_available: Option<Member>,
        new: Option<Member>,
        event: GuildMemberUpdateEvent,
    );
    async fn guild_members_chunk(&self, ctx: Context, chunk: GuildMembersChunkEvent);
    async fn guild_role_create(&self, ctx: Context, new: Role);
    async fn guild_role_delete(
        &self,
        ctx: Context,
        guild_id: GuildId,
        removed_role_id: RoleId,
        removed_role_data_if_available: Option<Role>,
    );
    async fn guild_role_update(
        &self,
        ctx: Context,
        old_data_if_available: Option<Role>,
        new: Role,
    );
    async fn guild_stickers_update(
        &self,
        ctx: Context,
        guild_id: GuildId,
        current_state: HashMap<StickerId, Sticker>,
    );
    async fn guild_update(
        &self,
        ctx: Context,
        old_data_if_available: Option<Guild>,
        new_data: PartialGuild,
    );
    async fn invite_create(&self, ctx: Context, data: InviteCreateEvent);
    async fn invite_delete(&self, ctx: Context, data: InviteDeleteEvent);
    async fn message(&self, ctx: Context, new_message: Message);
    async fn message_delete(
        &self,
        ctx: Context,
        channel_id: ChannelId,
        deleted_message_id: MessageId,
        guild_id: Option<GuildId>,
    );
    async fn message_delete_bulk(
        &self,
        ctx: Context,
        channel_id: ChannelId,
        multiple_deleted_messages_ids: Vec<MessageId>,
        guild_id: Option<GuildId>,
    );
    async fn message_update(
        &self,
        ctx: Context,
        old_if_available: Option<Message>,
        new: Option<Message>,
        event: MessageUpdateEvent,
    );
    async fn reaction_add(&self, ctx: Context, add_reaction: Reaction);
    async fn reaction_remove(&self, ctx: Context, removed_reaction: Reaction);
    async fn reaction_remove_all(
        &self,
        ctx: Context,
        channel_id: ChannelId,
        removed_from_message_id: MessageId,
    );
    async fn reaction_remove_emoji(&self, ctx: Context, removed_reactions: Reaction);
    async fn presence_replace(&self, ctx: Context, presences: Vec<Presence>);
    async fn presence_update(&self, ctx: Context, new_data: Presence);
    async fn ready(&self, ctx: Context, data_about_bot: Ready);
    async fn resume(&self, ctx: Context, event: ResumedEvent);
    async fn shard_stage_update(&self, ctx: Context, event: ShardStageUpdateEvent);
    async fn typing_start(&self, ctx: Context, event: TypingStartEvent);
    async fn user_update(&self, ctx: Context, old_data: Option<CurrentUser>, new: CurrentUser);
    async fn voice_server_update(&self, ctx: Context, event: VoiceServerUpdateEvent);
    async fn voice_state_update(&self, ctx: Context, old: Option<VoiceState>, new: VoiceState);
    async fn voice_channel_status_update(
        &self,
        ctx: Context,
        old: Option<String>,
        status: Option<String>,
        id: ChannelId,
        guild_id: GuildId,
    );
    async fn webhook_update(
        &self,
        ctx: Context,
        guild_id: GuildId,
        belongs_to_channel_id: ChannelId,
    );
    async fn interaction_create(&self, ctx: Context, interaction: Interaction);
    async fn integration_create(&self, ctx: Context, integration: Integration);
    async fn integration_update(&self, ctx: Context, integration: Integration);
    async fn integration_delete(
        &self,
        ctx: Context,
        integration_id: IntegrationId,
        guild_id: GuildId,
        application_id: Option<ApplicationId>,
    );
    async fn stage_instance_create(&self, ctx: Context, stage_instance: StageInstance);
    async fn stage_instance_update(&self, ctx: Context, stage_instance: StageInstance);
    async fn stage_instance_delete(&self, ctx: Context, stage_instance: StageInstance);
    async fn thread_create(&self, ctx: Context, thread: GuildChannel);
    async fn thread_update(&self, ctx: Context, old: Option<GuildChannel>, new: GuildChannel);
    async fn thread_delete(
        &self,
        ctx: Context,
        thread: PartialGuildChannel,
        full_thread_data: Option<GuildChannel>,
    );
    async fn thread_list_sync(&self, ctx: Context, thread_list_sync: ThreadListSyncEvent);
    async fn thread_member_update(&self, ctx: Context, thread_member: ThreadMember);
    async fn thread_members_update(
        &self,
        ctx: Context,
        thread_members_update: ThreadMembersUpdateEvent,
    );
    async fn guild_scheduled_event_create(&self, ctx: Context, event: ScheduledEvent);
    async fn guild_scheduled_event_update(&self, ctx: Context, event: ScheduledEvent);
    async fn guild_scheduled_event_delete(&self, ctx: Context, event: ScheduledEvent);
    async fn guild_scheduled_event_user_add(
        &self,
        ctx: Context,
        subscribed: GuildScheduledEventUserAddEvent,
    );
    async fn guild_scheduled_event_user_remove(
        &self,
        ctx: Context,
        unsubscribed: GuildScheduledEventUserRemoveEvent,
    );
    async fn ratelimit(&self, data: RatelimitInfo);
}