0.3 #146
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user