Compare commits
No commits in common. "7173dee28d9e778e08ea8f5ef14a355e6e77ff73" and "8fa6458d6ec1a5cc50e1c7d15c4f4d7450e0b512" have entirely different histories.
7173dee28d
...
8fa6458d6e
@ -12,7 +12,6 @@ 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
|
||||||
|
|
||||||
@ -32,7 +31,6 @@ 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()
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
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)
|
|
@ -1,7 +0,0 @@
|
|||||||
from discord.ext.commands import CommandError
|
|
||||||
|
|
||||||
|
|
||||||
class CheckError(CommandError):
|
|
||||||
|
|
||||||
def __init__(self, message, *args):
|
|
||||||
CommandError.__init__(self, message, *args)
|
|
@ -1,76 +0,0 @@
|
|||||||
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)
|
|
@ -1,31 +0,0 @@
|
|||||||
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)
|
|
@ -1,5 +1,6 @@
|
|||||||
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
|
||||||
@ -10,7 +11,6 @@ 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,10 +43,18 @@ 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')
|
||||||
|
@ -13,7 +13,6 @@ 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):
|
||||||
@ -36,9 +35,6 @@ 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}')
|
||||||
|
Loading…
Reference in New Issue
Block a user