From bc8ff7dc0ff4099022defebba15723f29b39d6ce Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 8 Jan 2022 19:18:06 +0100 Subject: [PATCH] Added PyCharm support to permission module --- src/modules/permission/configuration/__init__.py | 0 .../configuration/permission_settings.py | 8 ++++---- src/modules/permission/permission.py | 5 ++--- .../permission/service/permission_service.py | 16 +++++++--------- 4 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 src/modules/permission/configuration/__init__.py diff --git a/src/modules/permission/configuration/__init__.py b/src/modules/permission/configuration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/modules/permission/configuration/permission_settings.py b/src/modules/permission/configuration/permission_settings.py index dceabe8..05512d1 100644 --- a/src/modules/permission/configuration/permission_settings.py +++ b/src/modules/permission/configuration/permission_settings.py @@ -22,11 +22,11 @@ class PermissionSettings(ConfigurationModelABC): def from_dict(self, settings: dict): try: - for id in settings['AdminRoleIds']: - self._admin_roles.append(int(id)) + for index in settings['AdminRoleIds']: + self._admin_roles.append(int(index)) - for id in settings['ModeratorRoleIds']: - self._moderator_roles.append(int(id)) + for index in settings['ModeratorRoleIds']: + self._moderator_roles.append(int(index)) except Exception as e: Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/src/modules/permission/permission.py b/src/modules/permission/permission.py index d606bc4..dcd3ab7 100644 --- a/src/modules/permission/permission.py +++ b/src/modules/permission/permission.py @@ -2,11 +2,10 @@ import discord from cpl_core.logging import LoggerABC 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_ready_abc import OnReadyABC from gismo_core.abc.module_abc import ModuleABC +from modules.permission.configuration.permission_settings import PermissionSettings class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC): @@ -21,7 +20,7 @@ class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC): ModuleABC.__init__( self, - { OnReadyABC: 1, OnMemberUpdateABC: 0 }, + {OnReadyABC: 1, OnMemberUpdateABC: 0}, PermissionSettings ) self._logger.info(__name__, f'Module {type(self)} loaded') diff --git a/src/modules/permission/service/permission_service.py b/src/modules/permission/service/permission_service.py index 86c91cb..d4290a4 100644 --- a/src/modules/permission/service/permission_service.py +++ b/src/modules/permission/service/permission_service.py @@ -14,13 +14,13 @@ class PermissionService(PermissionServiceABC): self._bot = bot self._config = config - self._admin_role_ids: dict[str, list[int]] = {} - self._admin_roles: dict[list[discord.Role]] = {} - self._admins: dict[list[discord.Member]] = {} + self._admin_role_ids: dict[int, list[int]] = {} + self._admin_roles: dict[int, list[discord.Role]] = {} + self._admins: dict[int, list[discord.Member]] = {} - self._moderator_role_ids: dict[list[int]] = {} - self._moderator_roles: dict[list[discord.Role]] = {} - self._moderators: dict[list[discord.Member]] = {} + self._moderator_role_ids: dict[int, list[int]] = {} + self._moderator_roles: dict[int, list[discord.Role]] = {} + self._moderators: dict[int, list[discord.Member]] = {} def on_ready(self): for guild in self._bot.guilds: @@ -59,7 +59,6 @@ class PermissionService(PermissionServiceABC): for member in role.members: mods.append(member) self._logger.trace(__name__, f'Added moderator {member}') - self._admin_roles[guild.id] = admin_roles self._admins[guild.id] = admins @@ -70,7 +69,7 @@ class PermissionService(PermissionServiceABC): g_id = after.guild.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._logger.trace(__name__, f'Removed {after.id} from admins') @@ -87,7 +86,6 @@ class PermissionService(PermissionServiceABC): self._moderators[g_id].append(after) self._logger.trace(__name__, f'Added {after.id} to moderators') - def get_admin_role_ids(self, g_id: int) -> list[int]: return self._admin_role_ids[g_id]