diff --git a/kdb-bot/src/bot_core/core_extension/core_extension.py b/kdb-bot/src/bot_core/core_extension/core_extension.py index fba66dd7af..a482bcc3f9 100644 --- a/kdb-bot/src/bot_core/core_extension/core_extension.py +++ b/kdb-bot/src/bot_core/core_extension/core_extension.py @@ -8,6 +8,7 @@ from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.helper.command_checks import CommandChecks +from bot_core.helper.event_checks import EventChecks from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -26,3 +27,4 @@ class CoreExtension(ApplicationExtensionABC): message_service: MessageServiceABC = services.get_service(MessageServiceABC) t: TranslatePipe = services.get_service(TranslatePipe) CommandChecks.init(permissions, client_utils, message_service, t) + EventChecks.init(client_utils) diff --git a/kdb-bot/src/bot_core/helper/event_checks.py b/kdb-bot/src/bot_core/helper/event_checks.py new file mode 100644 index 0000000000..9d4e9ccbc2 --- /dev/null +++ b/kdb-bot/src/bot_core/helper/event_checks.py @@ -0,0 +1,31 @@ +from typing import Optional + +from cpl_translation import TranslatePipe +from discord.ext import commands +from discord.ext.commands import Context + +from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC +from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.exception.check_error import CheckError +from modules.permission.abc.permission_service_abc import PermissionServiceABC + + +class EventChecks: + _client_utils: Optional[ClientUtilsServiceABC] = None + + @classmethod + def init( + cls, + client_utils: ClientUtilsServiceABC, + ): + cls._client_utils = client_utils + + @classmethod + def check_is_ready(cls): + async def check_if_bot_is_ready_yet_and_respond(ctx: Context) -> bool: + result = await cls._client_utils.check_if_bot_is_ready_yet_and_respond(ctx) + if not result: + raise CheckError(f'Bot is not ready') + return result + + return commands.check(check_if_bot_is_ready_yet_and_respond)