forked from sh-edraft.de/sh_discord_bot
Added shutdown command
This commit is contained in:
parent
90a517d2b1
commit
5c564d3a8b
@ -6,6 +6,7 @@ from cpl_discord import get_discord_collection
|
||||
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
||||
|
||||
from modules.admin.command.restart_command import RestartCommand
|
||||
from modules.admin.command.shutdown_command import ShutdownCommand
|
||||
from modules.base.command.afk_command import AFKCommand
|
||||
from modules.base.command.help_command import HelpCommand
|
||||
from modules.base.command.info_command import InfoCommand
|
||||
@ -36,6 +37,7 @@ class StartupDiscordExtension(StartupExtensionABC):
|
||||
""" commands """
|
||||
# admin
|
||||
dc.add_command(RestartCommand)
|
||||
dc.add_command(ShutdownCommand)
|
||||
# moderator
|
||||
dc.add_command(PurgeCommand)
|
||||
# simple
|
||||
|
@ -7,7 +7,8 @@
|
||||
},
|
||||
"modules": {
|
||||
"admin": {
|
||||
"restart_message": "Bin gleich wieder da :D"
|
||||
"restart_message": "Bin gleich wieder da :D",
|
||||
"shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, Euer Freund. Lebt lange und in Frieden :)"
|
||||
},
|
||||
"moderator": {},
|
||||
"base": {
|
||||
|
@ -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')
|
||||
|
51
src/modules/admin/command/shutdown_command.py
Normal file
51
src/modules/admin/command/shutdown_command.py
Normal 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')
|
Loading…
Reference in New Issue
Block a user