Merge branch '0.3' into #105

This commit is contained in:
Sven Heidemann 2022-11-09 22:23:08 +01:00
commit 55c43efbdc
2 changed files with 16 additions and 8 deletions

View File

@ -22,7 +22,7 @@ class AutoRoleRepositoryABC(ABC):
def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]: pass def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]: pass
@abstractmethod @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 @abstractmethod
def get_auto_role_by_message_id(self, id: int) -> AutoRole: pass def get_auto_role_by_message_id(self, id: int) -> AutoRole: pass

View File

@ -67,12 +67,16 @@ class AutoRoleGroup(DiscordCommandABC):
self._logger.trace(__name__, f'Finished command auto-role list') self._logger.trace(__name__, f'Finished command auto-role list')
return return
if ctx.guild is None:
return
embed = discord.Embed( embed = discord.Embed(
title=self._t.transform('modules.auto_role.list.title'), title=self._t.transform('modules.auto_role.list.title'),
description=self._t.transform('modules.auto_role.list.description'), description=self._t.transform('modules.auto_role.list.description'),
color=int('ef9d0d', 16) 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: if auto_roles.count() < 1:
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.error.nothing_found')) 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') self._logger.trace(__name__, f'Finished command auto-role list')
@ -168,7 +172,8 @@ class AutoRoleGroup(DiscordCommandABC):
@remove.autocomplete('auto_role') @remove.autocomplete('auto_role')
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: 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] return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
@auto_role.group() @auto_role.group()
@ -216,7 +221,8 @@ class AutoRoleGroup(DiscordCommandABC):
@list.autocomplete('auto_role') @list.autocomplete('auto_role')
async def list_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: 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] return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
@rule.command() @rule.command()
@ -264,7 +270,8 @@ class AutoRoleGroup(DiscordCommandABC):
@add.autocomplete('auto_role') @add.autocomplete('auto_role')
async def add_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: 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] return [app_commands.Choice(name=auto_role, value=auto_role) for auto_role in auto_roles]
@add.autocomplete('emoji_name') @add.autocomplete('emoji_name')
@ -305,6 +312,7 @@ class AutoRoleGroup(DiscordCommandABC):
@remove.autocomplete('auto_role_rule') @remove.autocomplete('auto_role_rule')
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]: async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
rules = self._auto_roles.get_auto_role_rules() server = self._servers.get_server_by_discord_id(interaction.guild.id)
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 auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
rules] 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]