Added event redirect to modules

This commit is contained in:
Sven Heidemann 2021-11-23 17:18:06 +01:00
parent 3806c36571
commit a8551f2f95
3 changed files with 184 additions and 47 deletions

View File

@ -8,4 +8,4 @@ class OnBulkMessageDeleteABC(ABC):
def __init__(self): pass
@abstractmethod
async def on_bulk_message_delete(self, message: discord.Message): pass
async def on_bulk_message_delete(self, messages: list[discord.Message]): pass

View File

@ -35,7 +35,7 @@ class ModuleServiceABC(ABC):
async def on_message_delete(self, message: discord.Message): pass
@abstractmethod
async def on_bulk_message_delete(self, message: discord.Message): pass
async def on_bulk_message_delete(self, messages: list[discord.Message]): pass
@abstractmethod
async def on_message_edit(self, before: discord.Message, after: discord.Message): pass

View File

@ -9,10 +9,52 @@ from cpl_core.logging import LoggerABC
from cpl_core.utils import String
from cpl_query.extension import List
from discord.ext import commands
from modules_core.abc.events.on_bulk_message_delete_abc import OnBulkMessageDeleteABC
from modules_core.abc.events.on_connect_abc import OnConnectABC
from modules_core.abc.events.on_disconnect_abc import OnDisconnectABC
from modules_core.abc.events.on_group_join_abc import OnGroupJoinABC
from modules_core.abc.events.on_group_remove_abc import OnGroupRemoveABC
from modules_core.abc.events.on_guild_available_abc import OnGuildAvailableABC
from modules_core.abc.events.on_guild_channel_create_abc import OnGuildChannelCreateABC
from modules_core.abc.events.on_guild_channel_delete_abc import OnGuildChannelDeleteABC
from modules_core.abc.events.on_guild_channel_pins_update_abc import OnGuildChannelPinsUpdateABC
from modules_core.abc.events.on_guild_channel_update_abc import OnGuildChannelUpdateABC
from modules_core.abc.events.on_guild_emojis_update_abc import OnGuildEmojisUpdateABC
from modules_core.abc.events.on_guild_integrations_update_abc import OnGuildIntegrationsUpdateABC
from modules_core.abc.events.on_guild_join_abc import OnGuildJoinABC
from modules_core.abc.events.on_guild_remove_abc import OnGuildRemoveABC
from modules_core.abc.events.on_guild_role_create_abc import OnGuildRoleCreateABC
from modules_core.abc.events.on_guild_role_delete_abc import OnGuildRoleDeleteABC
from modules_core.abc.events.on_guild_role_update_abc import OnGuildRoleUpdateABC
from modules_core.abc.events.on_guild_unavailable_abc import OnGuildUnavailableABC
from modules_core.abc.events.on_guild_update_abc import OnGuildUpdateABC
from modules_core.abc.events.on_invite_create_abc import OnInviteCreateABC
from modules_core.abc.events.on_invite_delete_abc import OnInviteDeleteABC
from modules_core.abc.events.on_member_ban_abc import OnMemberBanABC
from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC
from modules_core.abc.events.on_member_remove_abc import OnMemberRemoveABC
from modules_core.abc.events.on_member_unban_abc import OnMemberUnbanABC
from modules_core.abc.events.on_member_update_abc import OnMemberUpdateABC
from modules_core.abc.events.on_message_abc import OnMessageABC
from modules_core.abc.events.on_message_delete_abc import OnMessageDeleteABC
from modules_core.abc.events.on_message_edit_abc import OnMessageEditABC
from modules_core.abc.events.on_private_channel_create_abc import OnPrivateChannelCreateABC
from modules_core.abc.events.on_private_channel_delete_abc import OnPrivateChannelDeleteABC
from modules_core.abc.events.on_private_channel_pins_update_abc import OnPrivateChannelPinsUpdateABC
from modules_core.abc.events.on_private_channel_update_abc import OnPrivateChannelUpdateABC
from modules_core.abc.events.on_reaction_add_abc import OnReactionAddABC
from modules_core.abc.events.on_reaction_clear_abc import OnReactionClearABC
from modules_core.abc.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC
from modules_core.abc.events.on_reaction_remove_abc import OnReactionRemoveABC
from modules_core.abc.events.on_ready_abc import OnReadyABC
from modules_core.abc.events.on_relationship_add_abc import OnRelationshipAddABC
from modules_core.abc.events.on_relationship_remove_abc import OnRelationshipRemoveABC
from modules_core.abc.events.on_relationship_update_abc import OnRelationshipUpdateABC
from modules_core.abc.events.on_resume_abc import OnResumeABC
from modules_core.abc.events.on_typing_abc import OnTypingABC
from modules_core.abc.events.on_user_update_abc import OnUserUpdateABC
from modules_core.abc.events.on_voice_state_update_abc import OnVoiceStateUpdateABC
from modules_core.abc.events.on_webhooks_update_abc import OnWebhooksUpdateABC
from modules_core.abc.module_abc import ModuleABC
from modules_core.abc.module_service_abc import ModuleServiceABC
@ -39,8 +81,14 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC):
async def _handle_event(self, event: type, *args):
self._logger.debug(__name__, f'Start {event} modules')
modules = self._get_modules(event)
if modules.count() < 1:
self._logger.debug(__name__, f'Stopped {event} modules')
return
func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0])
for module in self._get_modules(event):
for module in modules:
func = getattr(module, func_name)
await func(*args)
@ -48,145 +96,234 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC):
@commands.Cog.listener()
async def on_connect(self):
self._logger.debug(__name__, f'Received on_connect')
await self._handle_event(OnConnectABC)
@commands.Cog.listener()
async def on_disconnect(self):
self._logger.debug(__name__, f'Received on_disconnect')
await self._handle_event(OnDisconnectABC)
async def on_ready(self):
self._logger.debug(__name__, f'Received on_ready')
await self._handle_event(OnReadyABC)
@commands.Cog.listener()
async def on_resume(self): pass
async def on_resume(self):
self._logger.debug(__name__, f'Received on_resume')
await self._handle_event(OnResumeABC)
@commands.Cog.listener()
async def on_error(self, event: str, *args, **kwargs): pass
async def on_error(self, event: str, *args, **kwargs):
self._logger.debug(__name__, f'Received on_error:\n\t{event}\n\t{args}\n\t{kwargs}')
await self._handle_event(OnReadyABC, event, *args, **kwargs)
@commands.Cog.listener()
async def on_typing(self, channel: discord.abc.Messageable, user: Union[discord.User, discord.Member], when: datetime): pass
async def on_typing(self, channel: discord.abc.Messageable, user: Union[discord.User, discord.Member], when: datetime):
self._logger.debug(__name__, f'Received on_typing:\n\t{channel}\n\t{user}\n\t{when}')
await self._handle_event(OnTypingABC, channel, user, when)
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
self._logger.debug(__name__, f'Received message:\n{message}:\n{message.content}')
self._logger.debug(__name__, f'Received on_message:\n\t{message}\n\t{message.content}')
await self._handle_event(OnMessageABC, message)
@commands.Cog.listener()
async def on_message_delete(self, message: discord.Message): pass
async def on_message_delete(self, message: discord.Message):
self._logger.debug(__name__, f'Received on_message_delete:\n\t{message}\n\t{message.content}')
await self._handle_event(OnMessageDeleteABC, message)
@commands.Cog.listener()
async def on_bulk_message_delete(self, message: discord.Message): pass
async def on_bulk_message_delete(self, messages: list[discord.Message]):
self._logger.debug(__name__, f'Received on_bulk_message_delete:\n\t{len(messages)}')
await self._handle_event(OnBulkMessageDeleteABC, messages)
@commands.Cog.listener()
async def on_message_edit(self, before: discord.Message, after: discord.Message): pass
async def on_message_edit(self, before: discord.Message, after: discord.Message):
self._logger.debug(__name__, f'Received on_message_edit:\n\t{before}\n\t{after}')
await self._handle_event(OnMessageEditABC, before, after)
@commands.Cog.listener()
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): pass
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
self._logger.debug(__name__, f'Received on_reaction_add:\n\t{reaction}\n\t{user}')
await self._handle_event(OnReactionAddABC, reaction, user)
@commands.Cog.listener()
async def on_reaction_remove(self, reaction: discord.Reaction, user: discord.User): pass
async def on_reaction_remove(self, reaction: discord.Reaction, user: discord.User):
self._logger.debug(__name__, f'Received on_reaction_remove:\n\t{reaction}\n\t{user}')
await self._handle_event(OnReactionRemoveABC, reaction, user)
@commands.Cog.listener()
async def on_reaction_clear(self, message: discord.Message, reactions: list[discord.Reaction]): pass
async def on_reaction_clear(self, message: discord.Message, reactions: list[discord.Reaction]):
self._logger.debug(__name__, f'Received on_reaction_reon_reaction_clearmove:\n\t{message}\n\t{len(reactions)}')
await self._handle_event(OnReactionClearABC, message, reactions)
@commands.Cog.listener()
async def on_reaction_clear_emoji(self, reaction: discord.Reaction): pass
async def on_reaction_clear_emoji(self, reaction: discord.Reaction):
self._logger.debug(__name__, f'Received on_reaction_clear_emoji:\n\t{reaction}')
await self._handle_event(OnReactionClearEmojiABC, reaction)
@commands.Cog.listener()
async def on_private_channel_delete(self, channel: discord.abc.PrivateChannel): pass
async def on_private_channel_delete(self, channel: discord.abc.PrivateChannel):
self._logger.debug(__name__, f'Received on_private_channel_delete:\n\t{channel}')
await self._handle_event(OnPrivateChannelDeleteABC, channel)
@commands.Cog.listener()
async def on_private_channel_create(self, channel: discord.abc.PrivateChannel): pass
async def on_private_channel_create(self, channel: discord.abc.PrivateChannel):
self._logger.debug(__name__, f'Received on_private_channel_create:\n\t{channel}')
await self._handle_event(OnPrivateChannelCreateABC, channel)
@commands.Cog.listener()
async def on_private_channel_update(self, before: discord.GroupChannel, after: discord.GroupChannel): pass
async def on_private_channel_update(self, before: discord.GroupChannel, after: discord.GroupChannel):
self._logger.debug(__name__, f'Received on_private_channel_update:\n\t{before}\n\t{after}')
await self._handle_event(OnPrivateChannelUpdateABC, before, after)
@commands.Cog.listener()
async def on_private_channel_pins_update(self, channel: discord.abc.PrivateChannel, list_pin: Optional[datetime]): pass
async def on_private_channel_pins_update(self, channel: discord.abc.PrivateChannel, list_pin: Optional[datetime]):
self._logger.debug(__name__, f'Received on_private_channel_pins_update:\n\t{channel}\n\t{list_pin}')
await self._handle_event(OnPrivateChannelPinsUpdateABC, channel, list_pin)
@commands.Cog.listener()
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel): pass
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel):
self._logger.debug(__name__, f'Received on_guild_channel_delete:\n\t{channel}')
await self._handle_event(OnGuildChannelDeleteABC, channel)
@commands.Cog.listener()
async def on_guild_channel_create(self, channel: discord.abc.GuildChannel): pass
async def on_guild_channel_create(self, channel: discord.abc.GuildChannel):
self._logger.debug(__name__, f'Received on_guild_channel_create:\n\t{channel}')
await self._handle_event(OnGuildChannelCreateABC, channel)
@commands.Cog.listener()
async def on_guild_channel_update(self, before: discord.abc.GuildChannel, after: discord.abc.GuildChannel): pass
async def on_guild_channel_update(self, before: discord.abc.GuildChannel, after: discord.abc.GuildChannel):
self._logger.debug(__name__, f'Received on_guild_channel_update:\n\t{before}\n\t{after}')
await self._handle_event(OnGuildChannelUpdateABC, before, after)
@commands.Cog.listener()
async def on_guild_channel_pins_update(self, channel: discord.abc.GuildChannel, list_pin: Optional[datetime]): pass
async def on_guild_channel_pins_update(self, channel: discord.abc.GuildChannel, list_pin: Optional[datetime]):
self._logger.debug(__name__, f'Received on_guild_channel_pins_update:\n\t{channel}\n\t{list_pin}')
await self._handle_event(OnGuildChannelPinsUpdateABC, channel, list_pin)
@commands.Cog.listener()
async def on_guild_integrations_update(self, guild: discord.Guild): pass
async def on_guild_integrations_update(self, guild: discord.Guild):
self._logger.debug(__name__, f'Received on_guild_integrations_update:\n\t{guild}')
await self._handle_event(OnGuildIntegrationsUpdateABC, guild)
@commands.Cog.listener()
async def on_webhooks_update(self, channel: discord.abc.GuildChannel): pass
async def on_webhooks_update(self, channel: discord.abc.GuildChannel):
self._logger.debug(__name__, f'Received on_webhooks_update:\n\t{channel}')
await self._handle_event(OnWebhooksUpdateABC, channel)
@commands.Cog.listener()
async def on_member_join(self, member: discord.Member): pass
async def on_member_join(self, member: discord.Member):
self._logger.debug(__name__, f'Received on_member_join:\n\t{member}')
await self._handle_event(OnMemberJoinABC, member)
@commands.Cog.listener()
async def on_member_remove(self, member: discord.Member): pass
async def on_member_remove(self, member: discord.Member):
self._logger.debug(__name__, f'Received on_member_remove:\n\t{member}')
await self._handle_event(OnMemberRemoveABC, member)
@commands.Cog.listener()
async def on_member_update(self, before: discord.Member, after: discord.Member): pass
async def on_member_update(self, before: discord.Member, after: discord.Member):
self._logger.debug(__name__, f'Received on_member_update:\n\t{before}\n\t{after}')
await self._handle_event(OnMemberUpdateABC, before, after)
@commands.Cog.listener()
async def on_user_update(self, before: discord.User, after: discord.User): pass
async def on_user_update(self, before: discord.User, after: discord.User):
self._logger.debug(__name__, f'Received on_user_update:\n\t{before}\n\t{after}')
await self._handle_event(OnUserUpdateABC, before, after)
@commands.Cog.listener()
async def on_guild_join(self, guild: discord.Guild): pass
async def on_guild_join(self, guild: discord.Guild):
self._logger.debug(__name__, f'Received on_guild_join:\n\t{guild}')
await self._handle_event(OnGuildJoinABC, guild)
@commands.Cog.listener()
async def on_guild_remove(self, guild: discord.Guild): pass
async def on_guild_remove(self, guild: discord.Guild):
self._logger.debug(__name__, f'Received on_guild_remove:\n\t{guild}')
await self._handle_event(OnGuildRemoveABC, guild)
@commands.Cog.listener()
async def on_guild_update(self, before: discord.Guild, after: discord.Guild): pass
async def on_guild_update(self, before: discord.Guild, after: discord.Guild):
self._logger.debug(__name__, f'Received on_guild_update:\n\t{before}\n\t{after}')
await self._handle_event(OnGuildUpdateABC, before, after)
@commands.Cog.listener()
async def on_guild_role_create(self, role: discord.Role): pass
async def on_guild_role_create(self, role: discord.Role):
self._logger.debug(__name__, f'Received on_guild_role_create:\n\t{role}')
await self._handle_event(OnGuildRoleCreateABC, role)
@commands.Cog.listener()
async def on_guild_role_delete(self, role: discord.Role): pass
async def on_guild_role_delete(self, role: discord.Role):
self._logger.debug(__name__, f'Received on_guild_role_delete:\n\t{role}')
await self._handle_event(OnGuildRoleDeleteABC, role)
@commands.Cog.listener()
async def on_guild_role_update(self, before: discord.Role, after: discord.Role): pass
async def on_guild_role_update(self, before: discord.Role, after: discord.Role):
self._logger.debug(__name__, f'Received on_guild_role_update:\n\t{before}\n\t{after}')
await self._handle_event(OnGuildRoleUpdateABC, before, after)
@commands.Cog.listener()
async def on_guild_emojis_update(self, guild: discord.Guild, before: Sequence[discord.Emoji], after: Sequence[discord.Emoji]): pass
async def on_guild_emojis_update(self, guild: discord.Guild, before: Sequence[discord.Emoji], after: Sequence[discord.Emoji]):
self._logger.debug(__name__, f'Received on_guild_emojis_update:\n\t{guild}\n\t{before}\n\t{after}')
await self._handle_event(OnGuildEmojisUpdateABC, guild, before, after)
@commands.Cog.listener()
async def on_guild_available(self, guild: discord.Guild): pass
async def on_guild_available(self, guild: discord.Guild):
self._logger.debug(__name__, f'Received on_guild_available:\n\t{guild}')
await self._handle_event(OnGuildAvailableABC, guild)
@commands.Cog.listener()
async def on_guild_unavailable(self, guild: discord.Guild): pass
async def on_guild_unavailable(self, guild: discord.Guild):
self._logger.debug(__name__, f'Received on_guild_unavailable:\n\t{guild}')
await self._handle_event(OnGuildUnavailableABC, guild)
@commands.Cog.listener()
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): pass
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
self._logger.debug(__name__, f'Received on_voice_state_update:\n\t{member}\n\t{before}\n\t{after}')
await self._handle_event(OnVoiceStateUpdateABC, member, before, after)
@commands.Cog.listener()
async def on_member_ban(self, guild: discord.Guild, user: discord.User): pass
async def on_member_ban(self, guild: discord.Guild, user: discord.User):
self._logger.debug(__name__, f'Received on_member_ban:\n\t{guild}\n\t{user}')
await self._handle_event(OnMemberBanABC, guild, user)
@commands.Cog.listener()
async def on_member_unban(self, guild: discord.Guild, user: discord.User): pass
async def on_member_unban(self, guild: discord.Guild, user: discord.User):
self._logger.debug(__name__, f'Received on_member_unban:\n\t{guild}\n\t{user}')
await self._handle_event(OnMemberUnbanABC, guild, user)
@commands.Cog.listener()
async def on_invite_create(self, invite: discord.Invite): pass
async def on_invite_create(self, invite: discord.Invite):
self._logger.debug(__name__, f'Received on_invite_create:\n\t{invite}')
await self._handle_event(OnInviteCreateABC, invite)
@commands.Cog.listener()
async def on_invite_delete(self, invite: discord.Invite): pass
async def on_invite_delete(self, invite: discord.Invite):
self._logger.debug(__name__, f'Received on_invite_create:\n\t{invite}')
await self._handle_event(OnInviteDeleteABC, invite)
@commands.Cog.listener()
async def on_group_join(self, chhanel: discord.GroupChannel, user: discord.User): pass
async def on_group_join(self, channel: discord.GroupChannel, user: discord.User):
self._logger.debug(__name__, f'Received on_group_join:\n\t{channel}\n\t{user}')
await self._handle_event(OnGroupJoinABC, channel, user)
@commands.Cog.listener()
async def on_group_remove(self, chhanel: discord.GroupChannel, user: discord.User): pass
async def on_group_remove(self, channel: discord.GroupChannel, user: discord.User):
self._logger.debug(__name__, f'Received on_group_remove:\n\t{channel}\n\t{user}')
await self._handle_event(OnGroupRemoveABC, channel, user)
@commands.Cog.listener()
async def on_relationship_add(self, relationship: discord.Relationship): pass
async def on_relationship_add(self, relationship: discord.Relationship):
self._logger.debug(__name__, f'Received on_relationship_add:\n\t{relationship}')
await self._handle_event(OnRelationshipAddABC, relationship)
@commands.Cog.listener()
async def on_relationship_remove(self, relationship: discord.Relationship): pass
async def on_relationship_remove(self, relationship: discord.Relationship):
self._logger.debug(__name__, f'Received on_relationship_remove:\n\t{relationship}')
await self._handle_event(OnRelationshipRemoveABC, relationship)
@commands.Cog.listener()
async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship): pass
async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship):
self._logger.debug(__name__, f'Received on_relationship_update:\n\t{before}\n\t{after}')
await self._handle_event(OnRelationshipUpdateABC, before, after)