diff --git a/kdb-bot/src/bot_data/abc/auto_role_repository_abc.py b/kdb-bot/src/bot_data/abc/auto_role_repository_abc.py index 899cd486..4283824f 100644 --- a/kdb-bot/src/bot_data/abc/auto_role_repository_abc.py +++ b/kdb-bot/src/bot_data/abc/auto_role_repository_abc.py @@ -22,7 +22,7 @@ class AutoRoleRepositoryABC(ABC): def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]: pass @abstractmethod - def get_auto_roles_by_server_id(self, id: int) -> AutoRole: pass + def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]: pass @abstractmethod def get_auto_role_by_message_id(self, id: int) -> AutoRole: pass diff --git a/kdb-bot/src/modules/auto_role/command/auto_role_group.py b/kdb-bot/src/modules/auto_role/command/auto_role_group.py index 62667069..072a3bf5 100644 --- a/kdb-bot/src/modules/auto_role/command/auto_role_group.py +++ b/kdb-bot/src/modules/auto_role/command/auto_role_group.py @@ -67,12 +67,16 @@ class AutoRoleGroup(DiscordCommandABC): self._logger.trace(__name__, f'Finished command auto-role list') return + if ctx.guild is None: + return + 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() + server = self._servers.get_server_by_discord_id(ctx.guild.id) + auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id) 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') @@ -168,7 +172,8 @@ class AutoRoleGroup(DiscordCommandABC): @remove.autocomplete('auto_role') async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: - auto_roles = self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id) + server = self._servers.get_server_by_discord_id(interaction.guild.id) + auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id) return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles] @auto_role.group() @@ -216,7 +221,8 @@ class AutoRoleGroup(DiscordCommandABC): @list.autocomplete('auto_role') async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: - auto_roles = self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id) + server = self._servers.get_server_by_discord_id(interaction.guild.id) + auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id) return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles] @rule.command() @@ -264,7 +270,8 @@ class AutoRoleGroup(DiscordCommandABC): @add.autocomplete('auto_role') async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: - auto_roles = self._auto_roles.get_auto_roles().select(lambda x: x.auto_role_id) + server = self._servers.get_server_by_discord_id(interaction.guild.id) + auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id) return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles] @add.autocomplete('emoji_name') @@ -305,6 +312,7 @@ class AutoRoleGroup(DiscordCommandABC): @remove.autocomplete('auto_role_rule') async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: - rules = self._auto_roles.get_auto_role_rules() - return [app_commands.Choice(name=f'{rule.auto_role_rule_id} {rule.emoji_name} {interaction.guild.get_role(int(rule.role_id))}', value=rule.auto_role_rule_id) for rule in - rules] + server = self._servers.get_server_by_discord_id(interaction.guild.id) + auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id) + rules = auto_roles.select_many(lambda ar: self._auto_roles.get_auto_role_rules_by_auto_role_id(ar)) + return [app_commands.Choice(name=f'{rule.auto_role_rule_id} {rule.emoji_name} {interaction.guild.get_role(int(rule.role_id))}', value=rule.auto_role_rule_id) for rule in rules]