dev #392

Merged
edraft merged 14 commits from dev into master 2023-10-02 09:22:17 +02:00
Showing only changes of commit a9c9880fd4 - Show all commits

View File

@ -1,3 +1,5 @@
from typing import Optional
import discord
from cpl_core.configuration import ConfigurationABC
from cpl_core.logging import LoggerABC
@ -41,7 +43,11 @@ class ShortRoleNameService:
before = ""
after = ""
new_nick = member.nick if member.nick is not None else member.name
role_ids = List(discord.Role, member.roles).select(lambda x: x.id)
member_roles = List(discord.Role, member.roles)
highest_role: Optional[discord.Role] = (
member_roles.last_or_default() if settings.short_role_name_only_set_highest_role else None
)
member_role_ids = member_roles.select(lambda x: x.id)
server = self._server.get_server_by_discord_id(member.guild.id)
for short_role_name in self._short_role_names.get_short_role_names_by_server_id(server.id):
@ -51,7 +57,11 @@ class ShortRoleNameService:
new_nick = new_nick.replace(f"[{short_role_name.short_name}] ", "")
new_nick = new_nick.replace(f"[{short_role_name.short_name}]", "")
if short_role_name.role_id not in role_ids:
if (
short_role_name.role_id not in member_role_ids
or highest_role
and highest_role.id != short_role_name.role_id
):
continue
if short_role_name.position == ShortRoleNamePositionEnum.before: