From 7173dee28d9e778e08ea8f5ef14a355e6e77ff73 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 13 Nov 2022 11:58:09 +0100 Subject: [PATCH] Added event checks #114 --- .../bot_core/core_extension/core_extension.py | 2 ++ kdb-bot/src/bot_core/helper/event_checks.py | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 kdb-bot/src/bot_core/helper/event_checks.py 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 fba66dd7..a482bcc3 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 00000000..9d4e9ccb --- /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)