master #475
@ -43,6 +43,8 @@ class AuthUserTransformer(TransformerABC):
|
||||
def _is_admin(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
if member is None:
|
||||
return False
|
||||
return permissions.is_member_admin(member)
|
||||
|
||||
@staticmethod
|
||||
@ -50,6 +52,8 @@ class AuthUserTransformer(TransformerABC):
|
||||
def _is_moderator(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
if member is None:
|
||||
return False
|
||||
return permissions.is_member_moderator(member)
|
||||
|
||||
@classmethod
|
||||
|
@ -5,11 +5,11 @@ from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
from bot_core.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class PermissionService(PermissionServiceABC):
|
||||
@ -112,3 +112,18 @@ class PermissionService(PermissionServiceABC):
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "Permission check failed", e)
|
||||
return False
|
||||
|
||||
def is_member_technician_by_id(self, member_id: int):
|
||||
has_permission_cached = self.get_cached_permission(member_id, TeamMemberTypeEnum.technician)
|
||||
if has_permission_cached is not None:
|
||||
return has_permission_cached
|
||||
|
||||
self._logger.debug(__name__, f"Checking is member {member_id} technician")
|
||||
|
||||
try:
|
||||
has_permission = member_id in self._technician_configs.get_technician_config().technician_ids
|
||||
self.set_cached_permission(has_permission, member_id, TeamMemberTypeEnum.technician)
|
||||
return has_permission
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "Permission check failed", e)
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user