0.3 - Checks in Befehlen als Decorators (#114) #115
@ -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)
|
||||
|
31
kdb-bot/src/bot_core/helper/event_checks.py
Normal file
31
kdb-bot/src/bot_core/helper/event_checks.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user