From 9daa0b1c54b2e634e43f55c9f602fe73510406ad Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 3 Oct 2022 19:26:48 +0200 Subject: [PATCH] Added auto-role list #54 --- src/bot/translation/de.json | 8 ++ src/modules/autorole/auto_role_module.py | 2 + src/modules/autorole/command/__init__.py | 0 .../autorole/command/auto_role_command.py | 82 +++++++++++++++++++ src/modules/base/command/info_command.py | 2 +- 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/modules/autorole/command/__init__.py create mode 100644 src/modules/autorole/command/auto_role_command.py diff --git a/src/bot/translation/de.json b/src/bot/translation/de.json index 02da2823..d009e38e 100644 --- a/src/bot/translation/de.json +++ b/src/bot/translation/de.json @@ -53,6 +53,14 @@ "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 :)", "deploy_message": "Der neue Stand wurde hochgeladen." }, + "auto_role": { + "list": { + "title": "beobachtete Nachrichten:", + "description": "Von auto-role beobachtete Nachrichten:", + "auto_role_id": "auto-role Id", + "message_id": "Nachricht-Id" + } + }, "moderator": { "purge_message": "Na gut..., ich lösche alle Nachrichten wenns sein muss." }, diff --git a/src/modules/autorole/auto_role_module.py b/src/modules/autorole/auto_role_module.py index 3206b7e8..2d6c5377 100644 --- a/src/modules/autorole/auto_role_module.py +++ b/src/modules/autorole/auto_role_module.py @@ -6,6 +6,7 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC from bot_core.abc.module_abc import ModuleABC from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from modules.autorole.command.auto_role_command import AutoRoleCommand from modules.autorole.events.auto_role_on_raw_reaction_add import AutoRoleOnRawReactionAddEvent from modules.autorole.events.auto_role_on_raw_reaction_remove import AutoRoleOnRawReactionRemoveEvent from modules.autorole.helper.reaction_handler import ReactionHandler @@ -22,6 +23,7 @@ class AutoRoleModule(ModuleABC): def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services.add_transient(ReactionHandler) # commands + self._dc.add_command(AutoRoleCommand) # events self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_add.value, AutoRoleOnRawReactionAddEvent) self._dc.add_event(DiscordEventTypesEnum.on_raw_reaction_remove.value, AutoRoleOnRawReactionRemoveEvent) diff --git a/src/modules/autorole/command/__init__.py b/src/modules/autorole/command/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/modules/autorole/command/auto_role_command.py b/src/modules/autorole/command/auto_role_command.py new file mode 100644 index 00000000..75af4a1b --- /dev/null +++ b/src/modules/autorole/command/auto_role_command.py @@ -0,0 +1,82 @@ +import discord +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 bot_core.logging.command_logger import CommandLogger +from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC +from bot_data.abc.server_repository_abc import ServerRepositoryABC + + +class AutoRoleCommand(DiscordCommandABC): + + def __init__( + self, + logger: CommandLogger, + message_service: MessageServiceABC, + bot: DiscordBotServiceABC, + client_utils: ClientUtilsServiceABC, + translate: TranslatePipe, + servers: ServerRepositoryABC, + auto_roles: AutoRoleRepositoryABC + ): + DiscordCommandABC.__init__(self) + + self._logger = logger + self._message_service = message_service + self._bot = bot + self._client_utils = client_utils + self._t = translate + self._servers = servers + self._auto_roles = auto_roles + + self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') + + @commands.hybrid_group(name="auto-role") + @commands.guild_only() + async def auto_role(self, ctx: Context): + pass + + @auto_role.command() + @commands.guild_only() + async def list(self, ctx: Context, wait: int = None): + 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) + + embed = discord.Embed( + title=self._t.transform('modules.auto_role.list.title'), + description=self._t.transform('modules.auto_role.list.description'), + color=int('ef9d0d', 16) + ) + + auto_role_id = '' + for id in self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id): + auto_role_id += f'\n{id}' + + message_id = '' + for id in self._auto_roles.get_auto_roles().select(lambda x: x.discord_message_id): + message_id += f'\n{id}' + embed.add_field(name=self._t.transform('modules.auto_role.list.auto_role_id'), value=auto_role_id, inline=True) + embed.add_field(name=self._t.transform('modules.auto_role.list.message_id'), value=message_id, inline=True) + await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait) + self._logger.trace(__name__, f'Finished command auto-role list') + + @auto_role.command() + @commands.guild_only() + async def add(self, ctx: Context): + self._logger.debug(__name__, f'Received command auto-role add {ctx}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return + + @auto_role.command() + @commands.guild_only() + async def remove(self, ctx: Context): + self._logger.debug(__name__, f'Received command auto-role remove {ctx}') + if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): + return diff --git a/src/modules/base/command/info_command.py b/src/modules/base/command/info_command.py index f7183cde..23587778 100644 --- a/src/modules/base/command/info_command.py +++ b/src/modules/base/command/info_command.py @@ -62,7 +62,7 @@ class InfoCommand(DiscordCommandABC): embed.add_field(name=self._t.transform('modules.base.info.fields.moved_users_count'), value=client.moved_users_count) from bot.module_list import ModuleList modules = ModuleList.get_modules() - modules = modules.select(lambda x: x.replace('Module', '')) + modules = modules.select(lambda x: x.__name__.replace('Module', '')) embed.add_field(name=self._t.transform('modules.base.info.fields.modules'), value='\n'.join(modules), inline=False) await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)