Added PyCharm support to permission module

This commit is contained in:
Sven Heidemann 2022-01-08 19:18:06 +01:00
parent 7d4a28d524
commit bc8ff7dc0f
4 changed files with 13 additions and 16 deletions

View File

@ -22,11 +22,11 @@ class PermissionSettings(ConfigurationModelABC):
def from_dict(self, settings: dict): def from_dict(self, settings: dict):
try: try:
for id in settings['AdminRoleIds']: for index in settings['AdminRoleIds']:
self._admin_roles.append(int(id)) self._admin_roles.append(int(index))
for id in settings['ModeratorRoleIds']: for index in settings['ModeratorRoleIds']:
self._moderator_roles.append(int(id)) self._moderator_roles.append(int(index))
except Exception as e: except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings') Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')

View File

@ -2,11 +2,10 @@ import discord
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.abc.permission_service_abc import PermissionServiceABC
from modules.permission.configuration.permission_settings import \
PermissionSettings
from gismo_core.abc.events.on_member_update_abc import OnMemberUpdateABC from gismo_core.abc.events.on_member_update_abc import OnMemberUpdateABC
from gismo_core.abc.events.on_ready_abc import OnReadyABC from gismo_core.abc.events.on_ready_abc import OnReadyABC
from gismo_core.abc.module_abc import ModuleABC from gismo_core.abc.module_abc import ModuleABC
from modules.permission.configuration.permission_settings import PermissionSettings
class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC): class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC):
@ -21,7 +20,7 @@ class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC):
ModuleABC.__init__( ModuleABC.__init__(
self, self,
{ OnReadyABC: 1, OnMemberUpdateABC: 0 }, {OnReadyABC: 1, OnMemberUpdateABC: 0},
PermissionSettings PermissionSettings
) )
self._logger.info(__name__, f'Module {type(self)} loaded') self._logger.info(__name__, f'Module {type(self)} loaded')

View File

@ -14,13 +14,13 @@ class PermissionService(PermissionServiceABC):
self._bot = bot self._bot = bot
self._config = config self._config = config
self._admin_role_ids: dict[str, list[int]] = {} self._admin_role_ids: dict[int, list[int]] = {}
self._admin_roles: dict[list[discord.Role]] = {} self._admin_roles: dict[int, list[discord.Role]] = {}
self._admins: dict[list[discord.Member]] = {} self._admins: dict[int, list[discord.Member]] = {}
self._moderator_role_ids: dict[list[int]] = {} self._moderator_role_ids: dict[int, list[int]] = {}
self._moderator_roles: dict[list[discord.Role]] = {} self._moderator_roles: dict[int, list[discord.Role]] = {}
self._moderators: dict[list[discord.Member]] = {} self._moderators: dict[int, list[discord.Member]] = {}
def on_ready(self): def on_ready(self):
for guild in self._bot.guilds: for guild in self._bot.guilds:
@ -59,7 +59,6 @@ class PermissionService(PermissionServiceABC):
for member in role.members: for member in role.members:
mods.append(member) mods.append(member)
self._logger.trace(__name__, f'Added moderator {member}') self._logger.trace(__name__, f'Added moderator {member}')
self._admin_roles[guild.id] = admin_roles self._admin_roles[guild.id] = admin_roles
self._admins[guild.id] = admins self._admins[guild.id] = admins
@ -70,7 +69,7 @@ class PermissionService(PermissionServiceABC):
g_id = after.guild.id g_id = after.guild.id
for admin_role in self._admin_roles[g_id]: for admin_role in self._admin_roles[g_id]:
if admin_role in before.roles and admin_role not in after.roles: if admin_role in before.roles and admin_role not in after.roles:
self._admins[g_id].remove(after) self._admins[g_id].remove(after)
self._logger.trace(__name__, f'Removed {after.id} from admins') self._logger.trace(__name__, f'Removed {after.id} from admins')
@ -87,7 +86,6 @@ class PermissionService(PermissionServiceABC):
self._moderators[g_id].append(after) self._moderators[g_id].append(after)
self._logger.trace(__name__, f'Added {after.id} to moderators') self._logger.trace(__name__, f'Added {after.id} to moderators')
def get_admin_role_ids(self, g_id: int) -> list[int]: def get_admin_role_ids(self, g_id: int) -> list[int]:
return self._admin_role_ids[g_id] return self._admin_role_ids[g_id]