aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/mod.rs
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-01-15 23:36:04 -0600
committerNathan Ringo <nathan@remexre.com>2024-01-15 23:36:04 -0600
commit54f497163f57dacd8d621a2a3c89e1f06ac370d0 (patch)
treebc58027e740cef37c902d1f67cd97115fd5127be /src/handlers/mod.rs
parentea90b5ce89b9babb4ebc86de523efc7fa9631281 (diff)
Start splitting up handlers.
Diffstat (limited to 'src/handlers/mod.rs')
-rw-r--r--src/handlers/mod.rs226
1 files changed, 226 insertions, 0 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
new file mode 100644
index 0000000..f2b8a4f
--- /dev/null
+++ b/src/handlers/mod.rs
@@ -0,0 +1,226 @@
+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};
+
+/// 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);
+}