From 97e4f8ec292dc8e402910de06c78d0f997246b3b Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 4 Oct 2022 13:18:55 +0200 Subject: [PATCH] Added auto-role rule list #54 --- cpl-workspace.json | 2 +- .../config/appsettings.edrafts-pc-ubuntu.json | 2 +- src/bot/module_list.py | 5 +- .../{autorole => auto_role}/__init__.py | 0 .../{autorole => auto_role}/auto-role.json | 0 .../auto_role_module.py | 12 ++- .../command/__init__.py | 0 .../command/auto_role_group.py} | 57 ++++++++---- .../events/__init__.py | 0 .../events/auto_role_on_raw_reaction_add.py | 2 +- .../auto_role_on_raw_reaction_remove.py | 2 +- .../helper/__init__.py | 0 .../helper/reaction_handler.py | 0 .../autorole/command/auto_role_command.py | 86 ------------------- 14 files changed, 51 insertions(+), 117 deletions(-) rename src/modules/{autorole => auto_role}/__init__.py (100%) rename src/modules/{autorole => auto_role}/auto-role.json (100%) rename src/modules/{autorole => auto_role}/auto_role_module.py (68%) rename src/modules/{autorole => auto_role}/command/__init__.py (100%) rename src/modules/{autorole/command/auto_role_rule_command.py => auto_role/command/auto_role_group.py} (70%) rename src/modules/{autorole => auto_role}/events/__init__.py (100%) rename src/modules/{autorole => auto_role}/events/auto_role_on_raw_reaction_add.py (94%) rename src/modules/{autorole => auto_role}/events/auto_role_on_raw_reaction_remove.py (94%) rename src/modules/{autorole => auto_role}/helper/__init__.py (100%) rename src/modules/{autorole => auto_role}/helper/reaction_handler.py (100%) delete mode 100644 src/modules/autorole/command/auto_role_command.py diff --git a/cpl-workspace.json b/cpl-workspace.json index 663b790a..9841dd57 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -6,7 +6,7 @@ "bot-core": "src/bot_core/bot-core.json", "bot-data": "src/bot_data/bot-data.json", "admin": "src/modules/admin/admin.json", - "auto-role": "src/modules/admin/auto-role.json", + "auto-role": "src/modules/auto_role/auto-role.json", "base": "src/modules/base/base.json", "boot-log": "src/modules/boot_log/boot-log.json", "database": "src/modules/database/database.json", diff --git a/src/bot/config/appsettings.edrafts-pc-ubuntu.json b/src/bot/config/appsettings.edrafts-pc-ubuntu.json index 076ae8d8..a05aac5f 100644 --- a/src/bot/config/appsettings.edrafts-pc-ubuntu.json +++ b/src/bot/config/appsettings.edrafts-pc-ubuntu.json @@ -2,7 +2,7 @@ "LoggingSettings": { "Path": "logs/", "Filename": "bot.log", - "ConsoleLogLevel": "DEBUG", + "ConsoleLogLevel": "TRACE", "FileLogLevel": "TRACE" }, "BotLoggingSettings": { diff --git a/src/bot/module_list.py b/src/bot/module_list.py index 6e9670ff..5b8f4e5b 100644 --- a/src/bot/module_list.py +++ b/src/bot/module_list.py @@ -4,7 +4,7 @@ from bot_core.core_extension.core_extension_module import CoreExtensionModule from bot_core.core_module import CoreModule from bot_data.data_module import DataModule from modules.admin.admin_module import AdminModule -from modules.autorole.auto_role_module import AutoRoleModule +from modules.auto_role.auto_role_module import AutoRoleModule from modules.base.base_module import BaseModule from modules.boot_log.boot_log_module import BootLogModule from modules.database.database_module import DatabaseModule @@ -26,6 +26,7 @@ class ModuleList: DatabaseModule, ModeratorModule, PermissionModule, + # has to be last! + BootLogModule, CoreExtensionModule, - BootLogModule # has to be last! ]) diff --git a/src/modules/autorole/__init__.py b/src/modules/auto_role/__init__.py similarity index 100% rename from src/modules/autorole/__init__.py rename to src/modules/auto_role/__init__.py diff --git a/src/modules/autorole/auto-role.json b/src/modules/auto_role/auto-role.json similarity index 100% rename from src/modules/autorole/auto-role.json rename to src/modules/auto_role/auto-role.json diff --git a/src/modules/autorole/auto_role_module.py b/src/modules/auto_role/auto_role_module.py similarity index 68% rename from src/modules/autorole/auto_role_module.py rename to src/modules/auto_role/auto_role_module.py index 61f51b8e..cf53c6c4 100644 --- a/src/modules/autorole/auto_role_module.py +++ b/src/modules/auto_role/auto_role_module.py @@ -6,11 +6,10 @@ 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.command.auto_role_rule_command import AutoRoleRuleCommand -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 +from modules.auto_role.command.auto_role_group import AutoRoleGroup +from modules.auto_role.events.auto_role_on_raw_reaction_add import AutoRoleOnRawReactionAddEvent +from modules.auto_role.events.auto_role_on_raw_reaction_remove import AutoRoleOnRawReactionRemoveEvent +from modules.auto_role.helper.reaction_handler import ReactionHandler class AutoRoleModule(ModuleABC): @@ -24,8 +23,7 @@ class AutoRoleModule(ModuleABC): def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC): services.add_transient(ReactionHandler) # commands - self._dc.add_command(AutoRoleCommand) - self._dc.add_command(AutoRoleRuleCommand) + self._dc.add_command(AutoRoleGroup) # 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/auto_role/command/__init__.py similarity index 100% rename from src/modules/autorole/command/__init__.py rename to src/modules/auto_role/command/__init__.py diff --git a/src/modules/autorole/command/auto_role_rule_command.py b/src/modules/auto_role/command/auto_role_group.py similarity index 70% rename from src/modules/autorole/command/auto_role_rule_command.py rename to src/modules/auto_role/command/auto_role_group.py index 3027acaf..29072ae9 100644 --- a/src/modules/autorole/command/auto_role_rule_command.py +++ b/src/modules/auto_role/command/auto_role_group.py @@ -15,7 +15,7 @@ from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC -class AutoRoleRuleCommand(DiscordCommandABC): +class AutoRoleGroup(DiscordCommandABC): def __init__( self, @@ -39,12 +39,47 @@ class AutoRoleRuleCommand(DiscordCommandABC): self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') - @commands.hybrid_group(name="auto-role-rule") + @commands.hybrid_group(name="auto-role") @commands.guild_only() - async def auto_role(self, ctx: Context): + async def auto_role(self, ctx: Context): pass + + @auto_role.command(alias='auto-roles') + @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_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 = '' + message_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) + self._logger.trace(__name__, f'Finished command auto-role list') pass - @auto_role.command(alias='auto-role-rules') + @auto_role.group() + @commands.guild_only() + async def rule(self, ctx: Context): + pass + + @rule.command(alias='rules') @commands.guild_only() async def list(self, ctx: Context, auto_role: int, wait: int = None): self._logger.debug(__name__, f'Received command auto-role-rule list {ctx}') @@ -81,17 +116,3 @@ class AutoRoleRuleCommand(DiscordCommandABC): async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: auto_roles = self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id) return [app_commands.Choice(name=key, value=key) for key in auto_roles] - - @auto_role.command() - @commands.guild_only() - async def add(self, ctx: Context): - self._logger.debug(__name__, f'Received command auto-role-rule 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-rule remove {ctx}') - if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx): - return diff --git a/src/modules/autorole/events/__init__.py b/src/modules/auto_role/events/__init__.py similarity index 100% rename from src/modules/autorole/events/__init__.py rename to src/modules/auto_role/events/__init__.py diff --git a/src/modules/autorole/events/auto_role_on_raw_reaction_add.py b/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py similarity index 94% rename from src/modules/autorole/events/auto_role_on_raw_reaction_add.py rename to src/modules/auto_role/events/auto_role_on_raw_reaction_add.py index 586f87fd..f86de1f0 100644 --- a/src/modules/autorole/events/auto_role_on_raw_reaction_add.py +++ b/src/modules/auto_role/events/auto_role_on_raw_reaction_add.py @@ -5,7 +5,7 @@ from discord import RawReactionActionEvent from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC -from modules.autorole.helper.reaction_handler import ReactionHandler +from modules.auto_role.helper.reaction_handler import ReactionHandler class AutoRoleOnRawReactionAddEvent(OnRawReactionAddABC): diff --git a/src/modules/autorole/events/auto_role_on_raw_reaction_remove.py b/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py similarity index 94% rename from src/modules/autorole/events/auto_role_on_raw_reaction_remove.py rename to src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py index fbd86822..ca0ab888 100644 --- a/src/modules/autorole/events/auto_role_on_raw_reaction_remove.py +++ b/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py @@ -6,7 +6,7 @@ from discord import RawReactionActionEvent from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.server_repository_abc import ServerRepositoryABC -from modules.autorole.helper.reaction_handler import ReactionHandler +from modules.auto_role.helper.reaction_handler import ReactionHandler class AutoRoleOnRawReactionRemoveEvent(OnRawReactionRemoveABC): diff --git a/src/modules/autorole/helper/__init__.py b/src/modules/auto_role/helper/__init__.py similarity index 100% rename from src/modules/autorole/helper/__init__.py rename to src/modules/auto_role/helper/__init__.py diff --git a/src/modules/autorole/helper/reaction_handler.py b/src/modules/auto_role/helper/reaction_handler.py similarity index 100% rename from src/modules/autorole/helper/reaction_handler.py rename to src/modules/auto_role/helper/reaction_handler.py diff --git a/src/modules/autorole/command/auto_role_command.py b/src/modules/autorole/command/auto_role_command.py deleted file mode 100644 index 733d413f..00000000 --- a/src/modules/autorole/command/auto_role_command.py +++ /dev/null @@ -1,86 +0,0 @@ -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(alias='auto-roles') - @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_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 = '' - message_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) - 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