Added shutdown command

This commit is contained in:
2022-07-19 12:03:13 +02:00
parent 90a517d2b1
commit 5c564d3a8b
4 changed files with 56 additions and 2 deletions

View File

@@ -47,6 +47,6 @@ class RestartCommand(DiscordCommandABC):
self._config.add_configuration('IS_RESTART', 'true')
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.restart_message'))
await self._bot.logout()
await self._bot.stop_async()
self._logger.trace(__name__, f'Finished restart command')

View File

@@ -0,0 +1,51 @@
from cpl_core.configuration import ConfigurationABC
from cpl_core.logging import LoggerABC
from cpl_discord.command import DiscordCommandABC
from cpl_discord.service import DiscordBotServiceABC
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 modules.permission.abc.permission_service_abc import PermissionServiceABC
class ShutdownCommand(DiscordCommandABC):
def __init__(
self,
logger: LoggerABC,
config: ConfigurationABC,
message_service: MessageServiceABC,
bot: DiscordBotServiceABC,
client_utils: ClientUtilsServiceABC,
translate: TranslatePipe,
permissions: PermissionServiceABC,
):
DiscordCommandABC.__init__(self)
self._logger = logger
self._config = config
self._message_service = message_service
self._bot = bot
self._client_utils = client_utils
self._t = translate
self._permissions = permissions
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
@commands.command()
async def shutdown(self, ctx: Context):
self._logger.debug(__name__, f'Received command shutdown {ctx}')
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._message_service.send_ctx_msg(ctx, self._t.transform('modules.admin.shutdown_message'))
await self._bot.stop_async()
self._logger.trace(__name__, f'Finished shutdown command')