From 21c34436b9024f6aba2f6611da659102f8bd6021 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 3 Oct 2022 22:22:51 +0200 Subject: [PATCH] Improved auto-role-rule list #54 --- src/bot/translation/de.json | 17 ++++++++++++++++- .../autorole/command/auto_role_command.py | 14 +++++++++----- .../autorole/command/auto_role_rule_command.py | 18 +++++++++++++++++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/bot/translation/de.json b/src/bot/translation/de.json index d009e38e..db98a9a7 100644 --- a/src/bot/translation/de.json +++ b/src/bot/translation/de.json @@ -55,10 +55,25 @@ }, "auto_role": { "list": { - "title": "beobachtete Nachrichten:", + "title": "Beobachtete Nachrichten:", "description": "Von auto-role beobachtete Nachrichten:", "auto_role_id": "auto-role Id", "message_id": "Nachricht-Id" + }, + "rule": { + "list": { + "title": "auto-role Regeln:", + "description": "Von auto-role angewendete Regeln:", + "auto_role_id": "auto-role Id", + "emoji": "Emoji", + "role": "Rolle" + }, + "error": { + "id_not_found": "Kein auto-role Eintrag mit der Id gefunden!" + } + }, + "error": { + "nothing_found": "Keine auto-role Einträge gefunden." } }, "moderator": { diff --git a/src/modules/autorole/command/auto_role_command.py b/src/modules/autorole/command/auto_role_command.py index 0960c6eb..733d413f 100644 --- a/src/modules/autorole/command/auto_role_command.py +++ b/src/modules/autorole/command/auto_role_command.py @@ -54,14 +54,18 @@ class AutoRoleCommand(DiscordCommandABC): description=self._t.transform('modules.auto_role.list.description'), color=int('ef9d0d', 16) ) + auto_roles = self._auto_roles.get_auto_roles() + if auto_roles.count() < 1: + await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.error.nothing_found')) + self._logger.trace(__name__, f'Finished command auto-role list') + return 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}' + for auto_role in auto_roles: + auto_role_id += f'\n{auto_role.auto_role_id}' + message_id += f'\n{auto_role.discord_message_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) diff --git a/src/modules/autorole/command/auto_role_rule_command.py b/src/modules/autorole/command/auto_role_rule_command.py index 3e2ab240..3027acaf 100644 --- a/src/modules/autorole/command/auto_role_rule_command.py +++ b/src/modules/autorole/command/auto_role_rule_command.py @@ -57,9 +57,25 @@ class AutoRoleRuleCommand(DiscordCommandABC): description=self._t.transform('modules.auto_role.list.description'), color=int('ef9d0d', 16) ) + rules = self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role) + if rules.count() < 1: + await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.error.id_not_found')) + self._logger.trace(__name__, f'Finished command auto-role-rule list') + return + auto_role_rule_id = '' + emoji = '' + role = '' + for rule in rules: + auto_role_rule_id += f'\n{rule.role_id}' + emoji += f'\n{rule.emoji_name}' + role += f'\n{ctx.guild.get_role(rule.role_id)}' + + embed.add_field(name=self._t.transform('modules.auto_role.rule.list.auto_role_id'), value=auto_role_rule_id, inline=True) + embed.add_field(name=self._t.transform('modules.auto_role.rule.list.emoji'), value=emoji, inline=True) + embed.add_field(name=self._t.transform('modules.auto_role.rule.list.role'), value=role, 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') + self._logger.trace(__name__, f'Finished command auto-role-rule list') @list.autocomplete('auto_role') async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: