From f2e6be530b69ee7b4a4078e9c447ad8fa4b69484 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 5 Oct 2022 19:04:58 +0200 Subject: [PATCH] Renamed some functions & fixed list return context #54 --- .../config/appsettings.edrafts-pc-ubuntu.json | 6 +-- src/bot_data/abc/auto_role_repository_abc.py | 7 +--- .../service/auto_role_repository_service.py | 40 +++++++------------ .../auto_role/command/auto_role_group.py | 2 +- .../auto_role_on_raw_reaction_remove.py | 1 - 5 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/bot/config/appsettings.edrafts-pc-ubuntu.json b/src/bot/config/appsettings.edrafts-pc-ubuntu.json index 6de95194..a05aac5f 100644 --- a/src/bot/config/appsettings.edrafts-pc-ubuntu.json +++ b/src/bot/config/appsettings.edrafts-pc-ubuntu.json @@ -9,19 +9,19 @@ "Command": { "Path": "logs/", "Filename": "commands.log", - "ConsoleLogLevel": "TRACE", + "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" }, "Database": { "Path": "logs/", "Filename": "database.log", - "ConsoleLogLevel": "TRACE", + "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" }, "Message": { "Path": "logs/", "Filename": "message.log", - "ConsoleLogLevel": "TRACE", + "ConsoleLogLevel": "DEBUG", "FileLogLevel": "TRACE" } }, diff --git a/src/bot_data/abc/auto_role_repository_abc.py b/src/bot_data/abc/auto_role_repository_abc.py index 14422fc5..899cd486 100644 --- a/src/bot_data/abc/auto_role_repository_abc.py +++ b/src/bot_data/abc/auto_role_repository_abc.py @@ -25,13 +25,10 @@ class AutoRoleRepositoryABC(ABC): def get_auto_roles_by_server_id(self, id: int) -> AutoRole: pass @abstractmethod - def find_auto_roles_by_server_id(self, id: int) -> Optional[AutoRole]: pass + def get_auto_role_by_message_id(self, id: int) -> AutoRole: pass @abstractmethod - def get_auto_roles_by_message_id(self, id: int) -> AutoRole: pass - - @abstractmethod - def find_auto_roles_by_message_id(self, id: int) -> Optional[AutoRole]: pass + def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]: pass @abstractmethod def add_auto_role(self, auto_role: AutoRole): pass diff --git a/src/bot_data/service/auto_role_repository_service.py b/src/bot_data/service/auto_role_repository_service.py index 9801a17d..291f0a3f 100644 --- a/src/bot_data/service/auto_role_repository_service.py +++ b/src/bot_data/service/auto_role_repository_service.py @@ -59,34 +59,22 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): id=result[0] ) - def get_auto_roles_by_server_id(self, id: int) -> AutoRole: + def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]: self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_server_id_string(id)}') - result = self._context.select(AutoRole.get_select_by_server_id_string(id))[0] - return AutoRole( - result[1], - result[2], - result[3], - result[4], - id=result[0] - ) + auto_roles = List(AutoRole) + results = self._context.select(AutoRole.get_select_by_server_id_string(id)) + for result in results: + auto_roles.append(AutoRole( + result[1], + result[2], + result[3], + result[4], + id=result[0] + )) - def find_auto_roles_by_server_id(self, id: int) -> Optional[AutoRole]: - self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_server_id_string(id)}') - result = self._context.select(AutoRole.get_select_by_server_id_string(id)) - if result is None or len(result) == 0: - return None + return auto_roles - result = result[0] - - return AutoRole( - result[1], - result[2], - result[3], - result[4], - id=result[0] - ) - - def get_auto_roles_by_message_id(self, id: int) -> AutoRole: + def get_auto_role_by_message_id(self, id: int) -> AutoRole: self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_message_id_string(id)}') result = self._context.select(AutoRole.get_select_by_message_id_string(id))[0] return AutoRole( @@ -97,7 +85,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): id=result[0] ) - def find_auto_roles_by_message_id(self, id: int) -> Optional[AutoRole]: + def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]: self._logger.trace(__name__, f'Send SQL command: {AutoRole.get_select_by_message_id_string(id)}') result = self._context.select(AutoRole.get_select_by_message_id_string(id)) if result is None or len(result) == 0: diff --git a/src/modules/auto_role/command/auto_role_group.py b/src/modules/auto_role/command/auto_role_group.py index 3ef985b0..515d2fe4 100644 --- a/src/modules/auto_role/command/auto_role_group.py +++ b/src/modules/auto_role/command/auto_role_group.py @@ -107,7 +107,7 @@ class AutoRoleGroup(DiscordCommandABC): self._logger.trace(__name__, f'Finished command auto-role add') return - if self._auto_roles.find_auto_roles_by_message_id(int(message_id)) is not None: + if self._auto_roles.find_auto_role_by_message_id(int(message_id)) is not None: self._logger.debug(__name__, f'auto-role for message {message_id} already exists') await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.already_exists').format(message_id)) self._logger.trace(__name__, f'Finished command auto-role add') diff --git a/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py b/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py index ca0ab888..30936676 100644 --- a/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py +++ b/src/modules/auto_role/events/auto_role_on_raw_reaction_remove.py @@ -1,5 +1,4 @@ from cpl_core.logging import LoggerABC -from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC from cpl_discord.service import DiscordBotServiceABC from discord import RawReactionActionEvent