From 85f571762428420b6ef2161470df08ad89bf3bcb Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Wed, 12 Oct 2022 21:27:55 +0200 Subject: [PATCH] Addad technician to PermissionService #60 --- .../permission/abc/permission_service_abc.py | 6 +++++ .../permission/service/permission_service.py | 27 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/modules/permission/abc/permission_service_abc.py b/src/modules/permission/abc/permission_service_abc.py index 3fc54ff5..b2323742 100644 --- a/src/modules/permission/abc/permission_service_abc.py +++ b/src/modules/permission/abc/permission_service_abc.py @@ -32,8 +32,14 @@ class PermissionServiceABC(ABC): @abstractmethod def get_moderators(self, g_id: int) -> list[discord.Member]: pass + @abstractmethod + def get_technicians(self) -> list[discord.Member]: pass + @abstractmethod def is_member_admin(self, member: discord.Member) -> bool: pass @abstractmethod def is_member_moderator(self, member: discord.Member) -> bool: pass + + @abstractmethod + def is_member_technician(self, member: discord.Member) -> bool: pass diff --git a/src/modules/permission/service/permission_service.py b/src/modules/permission/service/permission_service.py index f6376ccc..f43f2f69 100644 --- a/src/modules/permission/service/permission_service.py +++ b/src/modules/permission/service/permission_service.py @@ -3,13 +3,20 @@ from cpl_core.logging import LoggerABC from cpl_core.configuration import ConfigurationABC from cpl_discord.service import DiscordBotServiceABC +from bot_core.configuration.bot_settings import BotSettings from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.configuration.permission_server_settings import PermissionServerSettings class PermissionService(PermissionServiceABC): - def __init__(self, logger: LoggerABC, bot: DiscordBotServiceABC, config: ConfigurationABC): + def __init__( + self, + logger: LoggerABC, + bot: DiscordBotServiceABC, + config: ConfigurationABC, + bot_settings: BotSettings + ): PermissionServiceABC.__init__(self) self._logger = logger self._bot = bot @@ -23,11 +30,20 @@ class PermissionService(PermissionServiceABC): self._moderator_roles: dict[int, list[discord.Role]] = {} self._moderators: dict[int, list[discord.Member]] = {} + self._technician_ids: list[int] = bot_settings.technicians + self._technicians: list[discord.Member] = [] + def on_ready(self): for guild in self._bot.guilds: guild: discord.Guild = guild self._logger.debug(__name__, f'Validate permission settings') + for technician_id in self._technician_ids: + technician = guild.get_member(technician_id) + if technician is None: + continue + self._technicians.append(technician) + settings: PermissionServerSettings = self._config.get_configuration(f'PermissionServerSettings_{guild.id}') if settings is None: self._logger.error(__name__, 'Permission settings not found') @@ -105,8 +121,15 @@ class PermissionService(PermissionServiceABC): def get_moderators(self, g_id: int) -> list[discord.Member]: return self._moderators[g_id] + def get_technicians(self) -> list[discord.Member]: + return self._technicians + def is_member_admin(self, member: discord.Member) -> bool: return member.guild.id in self._admins and member in self._admins[member.guild.id] def is_member_moderator(self, member: discord.Member) -> bool: - return member.guild.id in self._moderators and member in self._moderators[member.guild.id] or self.is_member_admin(member) + return member.guild.id in self._moderators \ + and member in self._moderators[member.guild.id] or self.is_member_admin(member) + + def is_member_technician(self, member: discord.Member) -> bool: + return member in self._technicians