Added event checks #114

This commit is contained in:
Sven Heidemann 2022-11-13 11:58:09 +01:00
parent e754a10241
commit 7173dee28d
2 changed files with 33 additions and 0 deletions

View File

@ -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_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_core.helper.command_checks import CommandChecks 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 from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -26,3 +27,4 @@ class CoreExtension(ApplicationExtensionABC):
message_service: MessageServiceABC = services.get_service(MessageServiceABC) message_service: MessageServiceABC = services.get_service(MessageServiceABC)
t: TranslatePipe = services.get_service(TranslatePipe) t: TranslatePipe = services.get_service(TranslatePipe)
CommandChecks.init(permissions, client_utils, message_service, t) CommandChecks.init(permissions, client_utils, message_service, t)
EventChecks.init(client_utils)

View File

@ -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)