From 5cdf2834cc91a65647d0e77fa0703e5981671b33 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 13 Nov 2022 12:01:34 +0100 Subject: [PATCH] Added is ready check to events #114 --- .../modules/auto_role/events/auto_role_on_raw_reaction_add.py | 2 ++ .../auto_role/events/auto_role_on_raw_reaction_remove.py | 2 ++ kdb-bot/src/modules/base/events/base_on_member_join_event.py | 2 ++ kdb-bot/src/modules/base/events/base_on_member_remove_event.py | 2 ++ kdb-bot/src/modules/base/events/base_on_message_event.py | 2 ++ .../src/modules/base/events/base_on_voice_state_update_event.py | 2 ++ kdb-bot/src/modules/level/events/level_on_message_event.py | 2 ++ .../modules/level/events/level_on_voice_state_update_event.py | 2 ++ 8 files changed, 16 insertions(+) diff --git a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py index f86de1f064..5893d4638e 100644 --- a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py +++ b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py @@ -3,6 +3,7 @@ from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent +from bot_core.helper.event_checks import EventChecks from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from modules.auto_role.helper.reaction_handler import ReactionHandler @@ -26,6 +27,7 @@ class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC): self._auto_roles = auto_roles self._reaction_handler = reaction_handler + @EventChecks.check_is_ready() async def on_raw_reaction_add(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f'Module {type(self)} started') diff --git a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py index 309366762e..49899a0e5d 100644 --- a/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py +++ b/kdb-bot/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py @@ -3,6 +3,7 @@ from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent +from bot_core.helper.event_checks import EventChecks from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from modules.auto_role.helper.reaction_handler import ReactionHandler @@ -26,6 +27,7 @@ class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC): self._auto_roles = auto_roles self._reaction_handler = reaction_handler + @EventChecks.check_is_ready() async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): self._logger.debug(__name__, f'Module {type(self)} started') diff --git a/kdb-bot/src/modules/base/events/base_on_member_join_event.py b/kdb-bot/src/modules/base/events/base_on_member_join_event.py index ebd5116e4f..72dcebce21 100644 --- a/kdb-bot/src/modules/base/events/base_on_member_join_event.py +++ b/kdb-bot/src/modules/base/events/base_on_member_join_event.py @@ -9,6 +9,7 @@ from cpl_discord.events import OnMemberJoinABC from cpl_translation import TranslatePipe from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.helper.event_checks import EventChecks from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC @@ -91,6 +92,7 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC): except Exception as e: self._logger.error(__name__, f'Cannot get user {member.id}', e) + @EventChecks.check_is_ready() async def on_member_join(self, member: discord.Member): self._logger.debug(__name__, f'Module {type(self)} started') self._check_for_known_user(member) diff --git a/kdb-bot/src/modules/base/events/base_on_member_remove_event.py b/kdb-bot/src/modules/base/events/base_on_member_remove_event.py index b3d36b8a72..e9987fc604 100644 --- a/kdb-bot/src/modules/base/events/base_on_member_remove_event.py +++ b/kdb-bot/src/modules/base/events/base_on_member_remove_event.py @@ -8,6 +8,7 @@ from cpl_discord.events import OnMemberRemoveABC from cpl_translation import TranslatePipe from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.helper.event_checks import EventChecks from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC @@ -59,6 +60,7 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC): except Exception as e: self._logger.error(__name__, f'Cannot get user {member.id}', e) + @EventChecks.check_is_ready() async def on_member_remove(self, member: discord.Member): self._logger.debug(__name__, f'Module {type(self)} started') await self._remove_user(member) diff --git a/kdb-bot/src/modules/base/events/base_on_message_event.py b/kdb-bot/src/modules/base/events/base_on_message_event.py index 7f6cb926ef..2d562c663b 100644 --- a/kdb-bot/src/modules/base/events/base_on_message_event.py +++ b/kdb-bot/src/modules/base/events/base_on_message_event.py @@ -5,6 +5,7 @@ from cpl_core.database.context import DatabaseContextABC from cpl_discord.events import OnMessageABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.helper.event_checks import EventChecks from bot_core.helper.log_message_helper import LogMessageHelper from bot_core.logging.message_logger import MessageLogger from bot_data.abc.client_repository_abc import ClientRepositoryABC @@ -70,6 +71,7 @@ class BaseOnMessageEvent(OnMessageABC): self._logger.debug(__name__, f'User {user} sent message. xp: from {old_xp} to {user.xp}') + @EventChecks.check_is_ready() async def on_message(self, message: discord.Message): self._logger.debug(__name__, f'Module {type(self)} started') self._logger.info(__name__, f'Received message: {LogMessageHelper.get_log_string(message)}') diff --git a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py b/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py index 5869d44672..176977a968 100644 --- a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py +++ b/kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py @@ -7,6 +7,7 @@ from cpl_core.database.context import DatabaseContextABC from cpl_core.logging import LoggerABC from cpl_discord.events import OnVoiceStateUpdateABC +from bot_core.helper.event_checks import EventChecks from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC @@ -83,6 +84,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): except Exception as e: self._logger.error(__name__, f'Ontime validation failed', e) + @EventChecks.check_is_ready() async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): self._logger.debug(__name__, f'Module {type(self)} started') self._logger.trace(__name__, f'Detected on_voice_state_update {member.id} from {before} to {after}') diff --git a/kdb-bot/src/modules/level/events/level_on_message_event.py b/kdb-bot/src/modules/level/events/level_on_message_event.py index cd69622e07..293fb08f31 100644 --- a/kdb-bot/src/modules/level/events/level_on_message_event.py +++ b/kdb-bot/src/modules/level/events/level_on_message_event.py @@ -1,6 +1,7 @@ import discord from cpl_discord.events import OnMessageABC +from bot_core.helper.event_checks import EventChecks from bot_core.logging.message_logger import MessageLogger from modules.level.service.level_service import LevelService @@ -16,6 +17,7 @@ class LevelOnMessageEvent(OnMessageABC): self._logger = logger self._level = level + @EventChecks.check_is_ready() async def on_message(self, message: discord.Message): self._logger.debug(__name__, f'Module {type(self)} started') await self._level.check_level(message.author) diff --git a/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py b/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py index c9127e0376..910e570a26 100644 --- a/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py +++ b/kdb-bot/src/modules/level/events/level_on_voice_state_update_event.py @@ -2,6 +2,7 @@ import discord from cpl_core.logging import LoggerABC from cpl_discord.events import OnVoiceStateUpdateABC +from bot_core.helper.event_checks import EventChecks from modules.level.service.level_service import LevelService @@ -18,6 +19,7 @@ class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC): self._logger.info(__name__, f'Module {type(self)} loaded') + @EventChecks.check_is_ready() async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): self._logger.debug(__name__, f'Module {type(self)} started') await self._level.check_level(member)