Merge pull request '0.3 - Techniker in PermissionService aufnehmen #60' (#69) from Ebola-Chan/kd_discord_bot:#60 into 0.3
Reviewed-on: sh-edraft.de/kd_discord_bot#69 Reviewed-by: Sven Heidemann <sven.heidemann@sh-edraft.de> Closes #60
This commit is contained in:
commit
56db9f42ad
@ -32,8 +32,14 @@ class PermissionServiceABC(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_moderators(self, g_id: int) -> list[discord.Member]: pass
|
def get_moderators(self, g_id: int) -> list[discord.Member]: pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_technicians(self) -> list[discord.Member]: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_member_admin(self, member: discord.Member) -> bool: pass
|
def is_member_admin(self, member: discord.Member) -> bool: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def is_member_moderator(self, member: discord.Member) -> bool: pass
|
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_core.configuration import ConfigurationABC
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
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.abc.permission_service_abc import PermissionServiceABC
|
||||||
from modules.permission.configuration.permission_server_settings import PermissionServerSettings
|
from modules.permission.configuration.permission_server_settings import PermissionServerSettings
|
||||||
|
|
||||||
|
|
||||||
class PermissionService(PermissionServiceABC):
|
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)
|
PermissionServiceABC.__init__(self)
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
self._bot = bot
|
self._bot = bot
|
||||||
@ -23,11 +30,20 @@ class PermissionService(PermissionServiceABC):
|
|||||||
self._moderator_roles: dict[int, list[discord.Role]] = {}
|
self._moderator_roles: dict[int, list[discord.Role]] = {}
|
||||||
self._moderators: dict[int, list[discord.Member]] = {}
|
self._moderators: dict[int, list[discord.Member]] = {}
|
||||||
|
|
||||||
|
self._technician_ids: list[int] = bot_settings.technicians
|
||||||
|
self._technicians: list[discord.Member] = []
|
||||||
|
|
||||||
def on_ready(self):
|
def on_ready(self):
|
||||||
for guild in self._bot.guilds:
|
for guild in self._bot.guilds:
|
||||||
guild: discord.Guild = guild
|
guild: discord.Guild = guild
|
||||||
self._logger.debug(__name__, f'Validate permission settings')
|
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}')
|
settings: PermissionServerSettings = self._config.get_configuration(f'PermissionServerSettings_{guild.id}')
|
||||||
if settings is None:
|
if settings is None:
|
||||||
self._logger.error(__name__, 'Permission settings not found')
|
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]:
|
def get_moderators(self, g_id: int) -> list[discord.Member]:
|
||||||
return self._moderators[g_id]
|
return self._moderators[g_id]
|
||||||
|
|
||||||
|
def get_technicians(self) -> list[discord.Member]:
|
||||||
|
return self._technicians
|
||||||
|
|
||||||
def is_member_admin(self, member: discord.Member) -> bool:
|
def is_member_admin(self, member: discord.Member) -> bool:
|
||||||
return member.guild.id in self._admins and member in self._admins[member.guild.id]
|
return member.guild.id in self._admins and member in self._admins[member.guild.id]
|
||||||
|
|
||||||
def is_member_moderator(self, member: discord.Member) -> bool:
|
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