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>); 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); 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>, ); async fn channel_pins_update(&self, ctx: Context, pin: ChannelPinsUpdateEvent); async fn channel_update(&self, ctx: Context, old: Option, 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); async fn guild_delete(&self, ctx: Context, incomplete: UnavailableGuild, full: Option); async fn guild_emojis_update( &self, ctx: Context, guild_id: GuildId, current_state: HashMap, ); 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, ); async fn guild_member_update( &self, ctx: Context, old_if_available: Option, new: Option, 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, ); async fn guild_role_update( &self, ctx: Context, old_data_if_available: Option, new: Role, ); async fn guild_stickers_update( &self, ctx: Context, guild_id: GuildId, current_state: HashMap, ); async fn guild_update( &self, ctx: Context, old_data_if_available: Option, 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, ); async fn message_delete_bulk( &self, ctx: Context, channel_id: ChannelId, multiple_deleted_messages_ids: Vec, guild_id: Option, ); async fn message_update( &self, ctx: Context, old_if_available: Option, new: Option, 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); 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, new: CurrentUser); async fn voice_server_update(&self, ctx: Context, event: VoiceServerUpdateEvent); async fn voice_state_update(&self, ctx: Context, old: Option, new: VoiceState); async fn voice_channel_status_update( &self, ctx: Context, old: Option, status: Option, 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, ); 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, new: GuildChannel); async fn thread_delete( &self, ctx: Context, thread: PartialGuildChannel, full_thread_data: Option, ); 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); }