Merge pull request '0.3 - Checks in Befehlen als Decorators (#114)' (#115) from #114 into 0.3

Reviewed-on: sh-edraft.de/kd_discord_bot#115
Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com>
Closes #114
This commit is contained in:
Ebola-Chan 2022-11-14 21:49:59 +01:00
commit ce73145dbb
28 changed files with 238 additions and 212 deletions

View File

@ -12,6 +12,7 @@ from bot.startup_migration_extension import StartupMigrationExtension
from bot.startup_module_extension import StartupModuleExtension from bot.startup_module_extension import StartupModuleExtension
from bot.startup_settings_extension import StartupSettingsExtension from bot.startup_settings_extension import StartupSettingsExtension
from bot_api.app_api_extension import AppApiExtension from bot_api.app_api_extension import AppApiExtension
from bot_core.core_extension.core_extension import CoreExtension
from modules.boot_log.boot_log_extension import BootLogExtension from modules.boot_log.boot_log_extension import BootLogExtension
from modules.database.database_extension import DatabaseExtension from modules.database.database_extension import DatabaseExtension
@ -31,6 +32,7 @@ class Program:
.use_extension(BootLogExtension) \ .use_extension(BootLogExtension) \
.use_extension(DatabaseExtension) \ .use_extension(DatabaseExtension) \
.use_extension(AppApiExtension) \ .use_extension(AppApiExtension) \
.use_extension(CoreExtension) \
.use_startup(Startup) .use_startup(Startup)
self.app: Application = await app_builder.build_async() self.app: Application = await app_builder.build_async()
await self.app.run_async() await self.app.run_async()

View File

@ -17,6 +17,9 @@ class ClientUtilsServiceABC(ABC):
@abstractmethod @abstractmethod
def get_client(self, dc_ic: int, guild_id: int): pass def get_client(self, dc_ic: int, guild_id: int): pass
@abstractmethod
async def check_if_bot_is_ready_yet(self) -> bool: pass
@abstractmethod @abstractmethod
async def check_if_bot_is_ready_yet_and_respond(self, ctx: Context) -> bool: pass async def check_if_bot_is_ready_yet_and_respond(self, ctx: Context) -> bool: pass

View File

@ -0,0 +1,30 @@
from cpl_core.application import ApplicationExtensionABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_translation import TranslatePipe
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
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
class CoreExtension(ApplicationExtensionABC):
def __init__(self):
ApplicationExtensionABC.__init__(self)
async def run(self, config: ConfigurationABC, services: ServiceProviderABC):
feature_flags: FeatureFlagsSettings = config.get_configuration(FeatureFlagsSettings)
if not feature_flags.get_flag(FeatureFlagsEnum.core_module):
return
permissions: PermissionServiceABC = services.get_service(PermissionServiceABC)
client_utils: ClientUtilsServiceABC = services.get_service(ClientUtilsServiceABC)
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)

View File

@ -0,0 +1,7 @@
from discord.ext.commands import CommandError
class CheckError(CommandError):
def __init__(self, message, *args):
CommandError.__init__(self, message, *args)

View File

@ -0,0 +1,76 @@
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 CommandChecks:
_permissions: Optional[PermissionServiceABC] = None
_client_utils: Optional[ClientUtilsServiceABC] = None
_message_service: Optional[MessageServiceABC] = None
_t: Optional[TranslatePipe] = None
@classmethod
def init(
cls,
permissions: PermissionServiceABC,
client_utils: ClientUtilsServiceABC,
message_service: MessageServiceABC,
translate: TranslatePipe,
):
cls._permissions = permissions
cls._client_utils = client_utils
cls._message_service = message_service
cls._t = translate
@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)
@classmethod
def check_is_member_admin(cls):
async def check_is_member_admin(ctx: Context):
has_permission = cls._permissions.is_member_admin(ctx.author)
if not has_permission:
await cls._message_service.send_ctx_msg(ctx, cls._t.transform('common.no_permission_message'))
raise CheckError(f'Member {ctx.author.name} is not admin')
return has_permission
return commands.check(check_is_member_admin)
@classmethod
def check_is_member_technician(cls):
async def check_is_member_technician(ctx: Context):
has_permission = cls._permissions.is_member_technician(ctx.author)
if not has_permission:
await cls._message_service.send_ctx_msg(ctx, cls._t.transform('common.no_permission_message'))
raise CheckError(f'Member {ctx.author.name} is not technician')
return has_permission
return commands.check(check_is_member_technician)
@classmethod
def check_is_member_moderator(cls):
async def check_is_member_moderator(ctx: Context):
has_permission = cls._permissions.is_member_moderator(ctx.author)
if not has_permission:
await cls._message_service.send_ctx_msg(ctx, cls._t.transform('common.no_permission_message'))
raise CheckError(f'Member {ctx.author.name} is not moderator')
return has_permission
return commands.check(check_is_member_moderator)

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() -> bool:
result = await cls._client_utils.check_if_bot_is_ready()
if not result:
raise CheckError(f'Bot is not ready')
return result
return commands.check(check_if_bot_is_ready)

View File

@ -59,14 +59,20 @@ class ClientUtilsService(ClientUtilsServiceABC):
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id) client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
return client return client
async def check_if_bot_is_ready_yet_and_respond(self, ctx: Context) -> bool: async def check_if_bot_is_ready_yet(self) -> bool:
if self._config.get_configuration('IS_READY') == 'true': if self._config.get_configuration('IS_READY') == 'true':
return True return True
self._logger.debug(__name__, f'Bot is not ready yet {self._t.transform("common.errors.bot_not_ready_yet")}') self._logger.debug(__name__, f'Bot is not ready yet {self._t.transform("common.errors.bot_not_ready_yet")}')
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.errors.bot_not_ready_yet'), without_tracking=True)
return False return False
async def check_if_bot_is_ready_yet_and_respond(self, ctx: Context) -> bool:
result = await self.check_if_bot_is_ready_yet()
if not result:
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.errors.bot_not_ready_yet'), without_tracking=True)
return result
async def presence_game(self, t_key: str): async def presence_game(self, t_key: str):
if not self._feature_flags.get_flag(FeatureFlagsEnum.presence): if not self._feature_flags.get_flag(FeatureFlagsEnum.presence):
return return

View File

@ -13,6 +13,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
@ -56,16 +57,10 @@ class AutoRoleGroup(DiscordCommandABC):
@auto_role.command(alias='auto-roles') @auto_role.command(alias='auto-roles')
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def list(self, ctx: Context, wait: int = None): async def list(self, ctx: Context, wait: int = None):
self._logger.debug(__name__, f'Received command auto-role list {ctx}') self._logger.debug(__name__, f'Received command auto-role list {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command auto-role list')
return
if ctx.guild is None: if ctx.guild is None:
return return
@ -95,16 +90,10 @@ class AutoRoleGroup(DiscordCommandABC):
@auto_role.command() @auto_role.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def add(self, ctx: Context, channel: discord.TextChannel, message_id: str): async def add(self, ctx: Context, channel: discord.TextChannel, message_id: str):
self._logger.debug(__name__, f'Received command auto-role add {ctx} {message_id}') self._logger.debug(__name__, f'Received command auto-role add {ctx} {message_id}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command auto-role add')
return
message = List(discord.Message, [message async for message in channel.history(limit=50)]).where(lambda m: m.id == int(message_id)).single_or_default() message = List(discord.Message, [message async for message in channel.history(limit=50)]).where(lambda m: m.id == int(message_id)).single_or_default()
if message is None: if message is None:
@ -142,16 +131,10 @@ class AutoRoleGroup(DiscordCommandABC):
@auto_role.command() @auto_role.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def remove(self, ctx: Context, auto_role: int): async def remove(self, ctx: Context, auto_role: int):
self._logger.debug(__name__, f'Received command auto-role remove {ctx} {auto_role}') self._logger.debug(__name__, f'Received command auto-role remove {ctx} {auto_role}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command auto-role remove')
return
auto_role_from_db = self._auto_roles.find_auto_role_by_id(auto_role) auto_role_from_db = self._auto_roles.find_auto_role_by_id(auto_role)
if auto_role_from_db is None: if auto_role_from_db is None:
@ -183,16 +166,10 @@ class AutoRoleGroup(DiscordCommandABC):
@rule.command(alias='rules') @rule.command(alias='rules')
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def list(self, ctx: Context, auto_role: int, wait: int = None): async def list(self, ctx: Context, auto_role: int, wait: int = None):
self._logger.debug(__name__, f'Received command auto-role rule list {ctx}') self._logger.debug(__name__, f'Received command auto-role rule list {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command auto-role rule list')
return
embed = discord.Embed( embed = discord.Embed(
title=self._t.transform('modules.auto_role.list.title'), title=self._t.transform('modules.auto_role.list.title'),
@ -227,16 +204,10 @@ class AutoRoleGroup(DiscordCommandABC):
@rule.command() @rule.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def add(self, ctx: Context, auto_role: int, emoji_name: str, role_id: str): async def add(self, ctx: Context, auto_role: int, emoji_name: str, role_id: str):
self._logger.debug(__name__, f'Received command auto-role add {ctx} {auto_role}') self._logger.debug(__name__, f'Received command auto-role add {ctx} {auto_role}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command auto-role rule add')
return
emoji = discord.utils.get(self._bot.emojis, name=emoji_name) emoji = discord.utils.get(self._bot.emojis, name=emoji_name)
if emoji is None: if emoji is None:
@ -300,16 +271,10 @@ class AutoRoleGroup(DiscordCommandABC):
@rule.command() @rule.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def remove(self, ctx: Context, auto_role_rule: int): async def remove(self, ctx: Context, auto_role_rule: int):
self._logger.debug(__name__, f'Received command auto-role remove {ctx} {auto_role_rule}') self._logger.debug(__name__, f'Received command auto-role remove {ctx} {auto_role_rule}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command auto-role remove')
return
auto_role_from_db = self._auto_roles.get_auto_role_rule_by_id(auto_role_rule) auto_role_from_db = self._auto_roles.get_auto_role_rule_by_id(auto_role_rule)
if auto_role_from_db is None: if auto_role_from_db is None:

View File

@ -3,6 +3,7 @@ from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from discord import RawReactionActionEvent 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.auto_role_repository_abc import AutoRoleRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from modules.auto_role.helper.reaction_handler import ReactionHandler from modules.auto_role.helper.reaction_handler import ReactionHandler
@ -26,6 +27,7 @@ class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC):
self._auto_roles = auto_roles self._auto_roles = auto_roles
self._reaction_handler = reaction_handler self._reaction_handler = reaction_handler
@EventChecks.check_is_ready()
async def on_raw_reaction_add(self, payload: RawReactionActionEvent): async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
self._logger.debug(__name__, f'Module {type(self)} started') self._logger.debug(__name__, f'Module {type(self)} started')

View File

@ -3,6 +3,7 @@ from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from discord import RawReactionActionEvent 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.auto_role_repository_abc import AutoRoleRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from modules.auto_role.helper.reaction_handler import ReactionHandler from modules.auto_role.helper.reaction_handler import ReactionHandler
@ -26,6 +27,7 @@ class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC):
self._auto_roles = auto_roles self._auto_roles = auto_roles
self._reaction_handler = reaction_handler self._reaction_handler = reaction_handler
@EventChecks.check_is_ready()
async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): async def on_raw_reaction_remove(self, payload: RawReactionActionEvent):
self._logger.debug(__name__, f'Module {type(self)} started') self._logger.debug(__name__, f'Module {type(self)} started')

View File

@ -8,6 +8,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from modules.base.configuration.base_server_settings import BaseServerSettings from modules.base.configuration.base_server_settings import BaseServerSettings
@ -36,11 +37,9 @@ class AFKCommand(DiscordCommandABC):
@commands.hybrid_command() @commands.hybrid_command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
async def afk(self, ctx: Context): async def afk(self, ctx: Context):
self._logger.debug(__name__, f'Received command afk {ctx}') self._logger.debug(__name__, f'Received command afk {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}') settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}')
if ctx.author.voice is None or ctx.author.voice.channel is None: if ctx.author.voice is None or ctx.author.voice.channel is None:

View File

@ -10,6 +10,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from modules.base.configuration.base_server_settings import BaseServerSettings from modules.base.configuration.base_server_settings import BaseServerSettings
@ -36,11 +37,9 @@ class HelpCommand(DiscordCommandABC):
@commands.hybrid_command() @commands.hybrid_command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
async def help(self, ctx: Context, persistent_flag: str = None): async def help(self, ctx: Context, persistent_flag: str = None):
self._logger.debug(__name__, f'Received command help {ctx}:{persistent_flag}') self._logger.debug(__name__, f'Received command help {ctx}:{persistent_flag}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}') settings: BaseServerSettings = self._config.get_configuration(f'BaseServerSettings_{ctx.guild.id}')
is_persistent = persistent_flag == '--stay' is_persistent = persistent_flag == '--stay'
await self._message_service.send_ctx_msg(ctx, settings.help_command_reference_url, is_persistent=is_persistent) await self._message_service.send_ctx_msg(ctx, settings.help_command_reference_url, is_persistent=is_persistent)

View File

@ -11,6 +11,7 @@ from discord.ext.commands import Context
import bot import bot
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
@ -38,11 +39,9 @@ class InfoCommand(DiscordCommandABC):
@commands.hybrid_command() @commands.hybrid_command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
async def info(self, ctx: Context, *, wait: int = None): async def info(self, ctx: Context, *, wait: int = None):
self._logger.debug(__name__, f'Received command info {ctx},{wait}') self._logger.debug(__name__, f'Received command info {ctx},{wait}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
client = self._client_utils.get_client(self._bot.user.id, ctx.guild.id) client = self._client_utils.get_client(self._bot.user.id, ctx.guild.id)
embed = discord.Embed( embed = discord.Embed(

View File

@ -6,6 +6,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
@ -31,10 +32,8 @@ class PingCommand(DiscordCommandABC):
@commands.hybrid_command() @commands.hybrid_command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
async def ping(self, ctx: Context): async def ping(self, ctx: Context):
self._logger.debug(__name__, f'Received command ping {ctx}') self._logger.debug(__name__, f'Received command ping {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.pong')) await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.base.pong'))
self._logger.trace(__name__, f'Finished ping command') self._logger.trace(__name__, f'Finished ping command')

View File

@ -9,6 +9,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.configuration.server_settings import ServerSettings from bot_core.configuration.server_settings import ServerSettings
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -37,18 +38,12 @@ class PurgeCommand(DiscordCommandABC):
@commands.hybrid_command() @commands.hybrid_command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def purge(self, ctx: Context): async def purge(self, ctx: Context):
self._logger.debug(__name__, f'Received command purge {ctx}') self._logger.debug(__name__, f'Received command purge {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
server_settings: ServerSettings = self._config.get_configuration(f'ServerSettings_{ctx.guild.id}') server_settings: ServerSettings = self._config.get_configuration(f'ServerSettings_{ctx.guild.id}')
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished purge command')
return
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.moderator.purge_message')) await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.moderator.purge_message'))
await asyncio.sleep(server_settings.message_delete_timer) await asyncio.sleep(server_settings.message_delete_timer)
try: try:

View File

@ -1,6 +1,5 @@
import asyncio import asyncio
import discord
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_discord.command import DiscordCommandABC from cpl_discord.command import DiscordCommandABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
@ -11,6 +10,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.configuration.bot_settings import BotSettings from bot_core.configuration.bot_settings import BotSettings
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -43,18 +43,10 @@ class RestartCommand(DiscordCommandABC):
@commands.hybrid_command() @commands.hybrid_command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def restart(self, ctx: Context): async def restart(self, ctx: Context):
self._logger.debug(__name__, f'Received command restart {ctx}') self._logger.debug(__name__, f'Received command restart {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished restart command')
return
self._config.add_configuration('IS_RESTART', 'true') self._config.add_configuration('IS_RESTART', 'true')
await self._client_utils.presence_game('common.presence.restart') await self._client_utils.presence_game('common.presence.restart')

View File

@ -11,6 +11,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.configuration.bot_settings import BotSettings from bot_core.configuration.bot_settings import BotSettings
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -43,18 +44,10 @@ class ShutdownCommand(DiscordCommandABC):
@commands.hybrid_command() @commands.hybrid_command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def shutdown(self, ctx: Context): async def shutdown(self, ctx: Context):
self._logger.debug(__name__, f'Received command shutdown {ctx}') self._logger.debug(__name__, f'Received command shutdown {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished shutdown command')
return
await self._client_utils.presence_game('common.presence.shutdown') await self._client_utils.presence_game('common.presence.shutdown')
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.shutdown_message')) await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.shutdown_message'))

View File

@ -10,6 +10,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
@ -60,16 +61,10 @@ class UserGroup(DiscordCommandABC):
@user.command() @user.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def info(self, ctx: Context, member: Optional[discord.Member] = None, *, wait: int = None): async def info(self, ctx: Context, member: Optional[discord.Member] = None, *, wait: int = None):
self._logger.debug(__name__, f'Received command user-info {ctx}:{member},{wait}') self._logger.debug(__name__, f'Received command user-info {ctx}:{member},{wait}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished purge command')
return
if member is None or not isinstance(member, discord.Member): if member is None or not isinstance(member, discord.Member):
member = ctx.author member = ctx.author

View File

@ -13,6 +13,7 @@ from cpl_discord.events.on_command_error_abc import OnCommandErrorABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.configuration.bot_settings import BotSettings from bot_core.configuration.bot_settings import BotSettings
from bot_core.exception.check_error import CheckError
class BaseOnCommandErrorEvent(OnCommandErrorABC): class BaseOnCommandErrorEvent(OnCommandErrorABC):
@ -35,6 +36,9 @@ class BaseOnCommandErrorEvent(OnCommandErrorABC):
self._t = translate self._t = translate
async def on_command_error(self, ctx: Context, error: CommandError): async def on_command_error(self, ctx: Context, error: CommandError):
if isinstance(error, CheckError):
return
error = getattr(error, 'original', error) error = getattr(error, 'original', error)
uid = uuid.uuid4() uid = uuid.uuid4()
self._logger.error(__name__, f'Got error: {type(error).__name__} UID: {uid}') self._logger.error(__name__, f'Got error: {type(error).__name__} UID: {uid}')

View File

@ -9,6 +9,7 @@ from cpl_discord.events import OnMemberJoinABC
from cpl_translation import TranslatePipe from cpl_translation import TranslatePipe
from bot_core.abc.message_service_abc import MessageServiceABC 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.known_user_repository_abc import KnownUserRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC 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_joined_server_repository_abc import UserJoinedServerRepositoryABC
@ -91,6 +92,7 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC):
except Exception as e: except Exception as e:
self._logger.error(__name__, f'Cannot get user {member.id}', 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): async def on_member_join(self, member: discord.Member):
self._logger.debug(__name__, f'Module {type(self)} started') self._logger.debug(__name__, f'Module {type(self)} started')
self._check_for_known_user(member) self._check_for_known_user(member)

View File

@ -8,6 +8,7 @@ from cpl_discord.events import OnMemberRemoveABC
from cpl_translation import TranslatePipe from cpl_translation import TranslatePipe
from bot_core.abc.message_service_abc import MessageServiceABC 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.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC
@ -59,6 +60,7 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC):
except Exception as e: except Exception as e:
self._logger.error(__name__, f'Cannot get user {member.id}', 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): async def on_member_remove(self, member: discord.Member):
self._logger.debug(__name__, f'Module {type(self)} started') self._logger.debug(__name__, f'Module {type(self)} started')
await self._remove_user(member) await self._remove_user(member)

View File

@ -5,6 +5,7 @@ from cpl_core.database.context import DatabaseContextABC
from cpl_discord.events import OnMessageABC from cpl_discord.events import OnMessageABC
from cpl_discord.service import DiscordBotServiceABC 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.helper.log_message_helper import LogMessageHelper
from bot_core.logging.message_logger import MessageLogger from bot_core.logging.message_logger import MessageLogger
from bot_data.abc.client_repository_abc import ClientRepositoryABC 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}') 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): async def on_message(self, message: discord.Message):
self._logger.debug(__name__, f'Module {type(self)} started') self._logger.debug(__name__, f'Module {type(self)} started')
self._logger.info(__name__, f'Received message: {LogMessageHelper.get_log_string(message)}') self._logger.info(__name__, f'Received message: {LogMessageHelper.get_log_string(message)}')

View File

@ -7,6 +7,7 @@ from cpl_core.database.context import DatabaseContextABC
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from cpl_discord.events import OnVoiceStateUpdateABC 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.known_user_repository_abc import KnownUserRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC 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_joined_server_repository_abc import UserJoinedServerRepositoryABC
@ -83,6 +84,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
except Exception as e: except Exception as e:
self._logger.error(__name__, f'Ontime validation failed', 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): 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.debug(__name__, f'Module {type(self)} started')
self._logger.trace(__name__, f'Detected on_voice_state_update {member.id} from {before} to {after}') self._logger.trace(__name__, f'Detected on_voice_state_update {member.id} from {before} to {after}')

View File

@ -12,6 +12,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from bot_data.abc.level_repository_abc import LevelRepositoryABC from bot_data.abc.level_repository_abc import LevelRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
@ -99,16 +100,10 @@ class LevelGroup(DiscordCommandABC):
@level.command(alias='levels') @level.command(alias='levels')
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def list(self, ctx: Context, wait: int = None): async def list(self, ctx: Context, wait: int = None):
self._logger.debug(__name__, f'Received command level list {ctx}') self._logger.debug(__name__, f'Received command level list {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command level list')
return
if ctx.guild is None: if ctx.guild is None:
return return
@ -141,16 +136,10 @@ class LevelGroup(DiscordCommandABC):
@level.command() @level.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_admin()
async def create(self, ctx: Context, name: str, color: str, min_xp: int, permissions: int): async def create(self, ctx: Context, name: str, color: str, min_xp: int, permissions: int):
self._logger.debug(__name__, f'Received command level create {ctx}') self._logger.debug(__name__, f'Received command level create {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_admin(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command level remove')
return
try: try:
color = hex(discord.Colour.from_str(color).value) color = hex(discord.Colour.from_str(color).value)
@ -199,19 +188,10 @@ class LevelGroup(DiscordCommandABC):
@level.command() @level.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_admin()
async def edit(self, ctx: Context, level: str, name: str = None, color: str = None, min_xp: int = None, permissions: int = None): async def edit(self, ctx: Context, level: str, name: str = None, color: str = None, min_xp: int = None, permissions: int = None):
self._logger.debug(__name__, f'Received command level edit {ctx}') self._logger.debug(__name__, f'Received command level edit {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_admin(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command level remove')
return
if ctx.guild is None:
return
server = self._servers.get_server_by_discord_id(ctx.guild.id) server = self._servers.get_server_by_discord_id(ctx.guild.id)
level_from_db = self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).single_or_default() level_from_db = self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).single_or_default()
@ -248,7 +228,8 @@ class LevelGroup(DiscordCommandABC):
self._levels.update_level(level_from_db) self._levels.update_level(level_from_db)
self._db.save_changes() self._db.save_changes()
await role.edit(name=level_from_db.name, permissions=discord.Permissions(level_from_db.permissions), colour=discord.Colour(int(level_from_db.color, 16))) await role.edit(name=level_from_db.name, permissions=discord.Permissions(level_from_db.permissions), colour=discord.Colour(int(level_from_db.color, 16)))
self._logger.info(__name__, f'Saved level {level_from_db.name} with color {level_from_db.color}, min_xp {level_from_db.min_xp} and permissions {level_from_db.permissions}') self._logger.info(__name__,
f'Saved level {level_from_db.name} with color {level_from_db.color}, min_xp {level_from_db.min_xp} and permissions {level_from_db.permissions}')
except Exception as e: except Exception as e:
self._logger.error(__name__, f'Could not save level {level} with color {color}, min_xp {min_xp} and permissions {permissions}', e) self._logger.error(__name__, f'Could not save level {level} with color {color}, min_xp {min_xp} and permissions {permissions}', e)
else: else:
@ -271,20 +252,10 @@ class LevelGroup(DiscordCommandABC):
@level.command() @level.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_admin()
async def remove(self, ctx: Context, level: str): async def remove(self, ctx: Context, level: str):
self._logger.debug(__name__, f'Received command level remove {ctx}') self._logger.debug(__name__, f'Received command level remove {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_admin(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command level remove')
return
if ctx.guild is None:
self._logger.trace(__name__, f'Finished command level remove')
return
server = self._servers.get_server_by_discord_id(ctx.guild.id) server = self._servers.get_server_by_discord_id(ctx.guild.id)
level_from_db = self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).first_or_default() level_from_db = self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).first_or_default()
@ -318,19 +289,10 @@ class LevelGroup(DiscordCommandABC):
@level.command() @level.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def down(self, ctx: Context, member: discord.Member): async def down(self, ctx: Context, member: discord.Member):
self._logger.debug(__name__, f'Received command level down {ctx} {member}') self._logger.debug(__name__, f'Received command level down {ctx} {member}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command level down')
return
if ctx.guild is None:
return
if member.bot: if member.bot:
return return
@ -360,19 +322,10 @@ class LevelGroup(DiscordCommandABC):
@level.command() @level.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def up(self, ctx: Context, member: discord.Member): async def up(self, ctx: Context, member: discord.Member):
self._logger.debug(__name__, f'Received command level up {ctx} {member}') self._logger.debug(__name__, f'Received command level up {ctx} {member}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command level up')
return
if ctx.guild is None:
return
if member.bot: if member.bot:
return return
@ -402,19 +355,10 @@ class LevelGroup(DiscordCommandABC):
@level.command() @level.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def set(self, ctx: Context, member: discord.Member, level: str): async def set(self, ctx: Context, member: discord.Member, level: str):
self._logger.debug(__name__, f'Received command level up {ctx} {member}') self._logger.debug(__name__, f'Received command level up {ctx} {member}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command level up')
return
if ctx.guild is None:
return
if member.bot: if member.bot:
return return

View File

@ -1,6 +1,7 @@
import discord import discord
from cpl_discord.events import OnMessageABC from cpl_discord.events import OnMessageABC
from bot_core.helper.event_checks import EventChecks
from bot_core.logging.message_logger import MessageLogger from bot_core.logging.message_logger import MessageLogger
from modules.level.service.level_service import LevelService from modules.level.service.level_service import LevelService
@ -16,6 +17,7 @@ class LevelOnMessageEvent(OnMessageABC):
self._logger = logger self._logger = logger
self._level = level self._level = level
@EventChecks.check_is_ready()
async def on_message(self, message: discord.Message): async def on_message(self, message: discord.Message):
self._logger.debug(__name__, f'Module {type(self)} started') self._logger.debug(__name__, f'Module {type(self)} started')
await self._level.check_level(message.author) await self._level.check_level(message.author)

View File

@ -2,6 +2,7 @@ import discord
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from cpl_discord.events import OnVoiceStateUpdateABC from cpl_discord.events import OnVoiceStateUpdateABC
from bot_core.helper.event_checks import EventChecks
from modules.level.service.level_service import LevelService from modules.level.service.level_service import LevelService
@ -18,6 +19,7 @@ class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
self._logger.info(__name__, f'Module {type(self)} loaded') 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): 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.debug(__name__, f'Module {type(self)} started')
await self._level.check_level(member) await self._level.check_level(member)

View File

@ -10,6 +10,7 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.helper.command_checks import CommandChecks
from bot_core.logging.command_logger import CommandLogger from bot_core.logging.command_logger import CommandLogger
from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
@ -51,16 +52,10 @@ class StatsGroup(DiscordCommandABC):
@stats.command() @stats.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def list(self, ctx: Context, wait: int = None): async def list(self, ctx: Context, wait: int = None):
self._logger.debug(__name__, f'Received command stats list {ctx}') self._logger.debug(__name__, f'Received command stats list {ctx}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command stats list')
return
if ctx.guild is None: if ctx.guild is None:
return return
@ -91,16 +86,10 @@ class StatsGroup(DiscordCommandABC):
@stats.command() @stats.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def view(self, ctx: Context, name: str, wait: int = None): async def view(self, ctx: Context, name: str, wait: int = None):
self._logger.debug(__name__, f'Received command stats view {ctx}:{name}') self._logger.debug(__name__, f'Received command stats view {ctx}:{name}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_moderator(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command stats view')
return
if ctx.guild is None: if ctx.guild is None:
return return
@ -139,16 +128,10 @@ class StatsGroup(DiscordCommandABC):
@stats.command() @stats.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_technician()
async def add(self, ctx: Context, name: str): async def add(self, ctx: Context, name: str):
self._logger.debug(__name__, f'Received command stats add {ctx}: {name}') self._logger.debug(__name__, f'Received command stats add {ctx}: {name}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_technician(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command stats add')
return
if ctx.guild is None: if ctx.guild is None:
return return
@ -161,16 +144,10 @@ class StatsGroup(DiscordCommandABC):
@stats.command() @stats.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_technician()
async def edit(self, ctx: Context, name: str): async def edit(self, ctx: Context, name: str):
self._logger.debug(__name__, f'Received command stats edit {ctx}: {name}') self._logger.debug(__name__, f'Received command stats edit {ctx}: {name}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_technician(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command stats edit')
return
try: try:
server = self._servers.get_server_by_discord_id(ctx.guild.id) server = self._servers.get_server_by_discord_id(ctx.guild.id)
@ -192,16 +169,10 @@ class StatsGroup(DiscordCommandABC):
@stats.command() @stats.command()
@commands.guild_only() @commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_technician()
async def remove(self, ctx: Context, name: str): async def remove(self, ctx: Context, name: str):
self._logger.debug(__name__, f'Received command stats remove {ctx}: {name}') self._logger.debug(__name__, f'Received command stats remove {ctx}: {name}')
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
return
self._client_utils.received_command(ctx.guild.id)
if not self._permissions.is_member_technician(ctx.author):
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
self._logger.trace(__name__, f'Finished command stats remove')
return
try: try:
server = self._servers.get_server_by_discord_id(ctx.guild.id) server = self._servers.get_server_by_discord_id(ctx.guild.id)