diff --git a/src/gismo/config/base.json b/src/gismo/config/base.json index 99a41c8..631149a 100644 --- a/src/gismo/config/base.json +++ b/src/gismo/config/base.json @@ -10,6 +10,7 @@ 910199452915093593, 910199452915093594 ], - "PurgeMessage": "Ja mein Herr, ich lösche alle Nachrichten!" + "PurgeMessage": "Ja mein Herr, ich lösche alle Nachrichten!", + "NoPermissionsMessage": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯" } } \ No newline at end of file diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py index 4598b3b..fbd7eaf 100644 --- a/src/modules/base/base_settings.py +++ b/src/modules/base/base_settings.py @@ -17,6 +17,7 @@ class BaseSettings(ConfigurationModelABC): self._xp_per_ontime_hour: int = 0 self._afk_channel_ids: list[int] = [] self._purge_message: str = '' + self._no_permissions_message: str = '' @property def welcome_message(self) -> str: @@ -50,6 +51,10 @@ class BaseSettings(ConfigurationModelABC): def purge_message(self) -> str: return self._purge_message + @property + def no_permissions_message(self) -> str: + return self._no_permissions_message + def from_dict(self, settings: dict): try: self._welcome_message = settings['WelcomeMessage'] @@ -61,6 +66,7 @@ class BaseSettings(ConfigurationModelABC): for id in settings['AFKChannelIds']: self._afk_channel_ids.append(int(id)) self._purge_message = settings['PurgeMessage'] + self._no_permissions_message = settings['NoPermissionsMessage'] 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/base/service/base_command_service.py b/src/modules/base/service/base_command_service.py index b20dbf7..4f41507 100644 --- a/src/modules/base/service/base_command_service.py +++ b/src/modules/base/service/base_command_service.py @@ -10,6 +10,7 @@ from gismo_core.abc.command_abc import CommandABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.configuration.server_settings import ServerSettings from modules.base.base_settings import BaseSettings +from modules.permission.abc.permission_service_abc import PermissionServiceABC class BaseCommandService(CommandABC): @@ -18,13 +19,15 @@ class BaseCommandService(CommandABC): self, logger: LoggerABC, config: ConfigurationABC, - message_service: MessageServiceABC + message_service: MessageServiceABC, + permissions: PermissionServiceABC ): CommandABC.__init__(self) self._logger = logger self._config = config self._message_service = message_service + self._permissions = permissions self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') @@ -40,6 +43,11 @@ class BaseCommandService(CommandABC): settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') server_settings: ServerSettings = self._config.get_configuration(f'DSERVER_{ctx.guild.id}') + if (not self._permissions.is_member_moderator(ctx.author)): + await self._message_service.send_ctx_msg(ctx, settings.no_permissions_message) + self._logger.trace(__name__, f'Finished purge command') + return + await self._message_service.send_ctx_msg(ctx, settings.purge_message) await asyncio.sleep(server_settings.message_delete_timer) await ctx.channel.purge() diff --git a/src/modules/permission/abc/permission_service_abc.py b/src/modules/permission/abc/permission_service_abc.py index c47ece7..cbfde25 100644 --- a/src/modules/permission/abc/permission_service_abc.py +++ b/src/modules/permission/abc/permission_service_abc.py @@ -30,3 +30,9 @@ class PermissionServiceABC(ABC): @abstractmethod def get_moderators(self, g_id: int) -> list[discord.Member]: pass + + @abstractmethod + def is_member_admin(member: discord.Member) -> bool: pass + + @abstractmethod + def is_member_moderator(member: discord.Member) -> bool: pass diff --git a/src/modules/permission/service/permission_service.py b/src/modules/permission/service/permission_service.py index 6172625..86c91cb 100644 --- a/src/modules/permission/service/permission_service.py +++ b/src/modules/permission/service/permission_service.py @@ -105,3 +105,10 @@ class PermissionService(PermissionServiceABC): def get_moderators(self, g_id: int) -> list[discord.Member]: return self._moderators[g_id] + + def is_member_admin(self, member: discord.Member) -> bool: + return member in self._admins[member.guild.id] + + def is_member_moderator(self, member: discord.Member) -> bool: + return member in self._moderators[member.guild.id] or self.is_member_admin(member) +