From 4db97248ca9ab3c712073cb26fe71cbc6066be45 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 27 Dec 2021 19:32:12 +0100 Subject: [PATCH 01/10] Improved config loading --- src/gismo/appsettings.example.json | 36 ------------------- src/gismo/{ => config}/appsettings.json | 0 src/gismo/config/base.json | 2 ++ src/gismo/config/boot_log.json | 10 ++++++ src/gismo/config/database.json | 2 ++ src/gismo/startup.py | 6 ++-- .../configuration/discord_settings.py | 2 +- src/modules/boot_log/boot_log.py | 16 ++++++--- src/modules/boot_log/boot_log_settings.py | 29 +++++++++++++++ src/modules_core/abc/module_abc.py | 19 ++++++---- src/modules_core/service/module_service.py | 19 ++++++++-- 11 files changed, 87 insertions(+), 54 deletions(-) delete mode 100644 src/gismo/appsettings.example.json rename src/gismo/{ => config}/appsettings.json (100%) create mode 100644 src/gismo/config/base.json create mode 100644 src/gismo/config/boot_log.json create mode 100644 src/gismo/config/database.json create mode 100644 src/modules/boot_log/boot_log_settings.py diff --git a/src/gismo/appsettings.example.json b/src/gismo/appsettings.example.json deleted file mode 100644 index 7bd96f0..0000000 --- a/src/gismo/appsettings.example.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "TimeFormatSettings": { - "DateFormat": "%Y-%m-%d", - "TimeFormat": "%H:%M:%S", - "DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f", - "DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S" - }, - "LoggingSettings": { - "Path": "logs/", - "Filename": "log_$start_time.log", - "ConsoleLogLevel": "ERROR", - "FileLogLevel": "WARN" - }, - "Discord": { - "Token": "" - }, - "Bot": { - "Prefix": "!g", - "Servers": [ - { - "Id": "", - "LoginMessageChannelId": "", - "LoginMessage": "", - "MessageDeleteTimer": 0, - "WelcomeMessage": "", - "GoodbyeMessage": "", - "MaxVoiceStateHours": 0, - "XpPerMessage": 0, - "XpPerOntimeHour": 0, - "AFKChannelIds": [], - "AdminRoleIds": [], - "ModeratorRoleIds": [] - } - ] - } -} \ No newline at end of file diff --git a/src/gismo/appsettings.json b/src/gismo/config/appsettings.json similarity index 100% rename from src/gismo/appsettings.json rename to src/gismo/config/appsettings.json diff --git a/src/gismo/config/base.json b/src/gismo/config/base.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/src/gismo/config/base.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/gismo/config/boot_log.json b/src/gismo/config/boot_log.json new file mode 100644 index 0000000..f54b141 --- /dev/null +++ b/src/gismo/config/boot_log.json @@ -0,0 +1,10 @@ +{ + "910199451145076828": { + "LoginMessageChannelId": "910199452915093588", + "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert" + }, + "511824600884051979": { + "LoginMessageChannelId": "521260270757347328", + "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert" + } +} \ No newline at end of file diff --git a/src/gismo/config/database.json b/src/gismo/config/database.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/src/gismo/config/database.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/gismo/startup.py b/src/gismo/startup.py index 1d38c1d..fbdd7cf 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -54,9 +54,9 @@ class Startup(StartupABC): environment.set_working_directory(os.path.dirname(os.path.realpath(__file__))) configuration.add_environment_variables('GISMO_') - configuration.add_json_file(f'appsettings.json', optional=False) - configuration.add_json_file(f'appsettings.{environment.environment_name}.json', optional=True) - configuration.add_json_file(f'appsettings.{environment.host_name}.json', optional=True) + configuration.add_json_file(f'config/appsettings.json', optional=False) + configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True) + configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True) configuration.add_configuration('Startup_StartTime', self._start_time) diff --git a/src/gismo_core/configuration/discord_settings.py b/src/gismo_core/configuration/discord_settings.py index efec204..84d323b 100644 --- a/src/gismo_core/configuration/discord_settings.py +++ b/src/gismo_core/configuration/discord_settings.py @@ -19,5 +19,5 @@ class DiscordSettings(ConfigurationModelABC): try: self._token = settings['Token'] except Exception as e: - Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings') + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {__name__} settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/src/modules/boot_log/boot_log.py b/src/modules/boot_log/boot_log.py index 4ee4834..cd07e80 100644 --- a/src/modules/boot_log/boot_log.py +++ b/src/modules/boot_log/boot_log.py @@ -8,6 +8,7 @@ from discord import guild from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.configuration.server_settings import ServerSettings +from modules.boot_log.boot_log_settings import BootLogSettings from modules_core.abc.events.on_ready_abc import OnReadyABC from modules_core.abc.module_abc import ModuleABC @@ -26,11 +27,16 @@ class BootLog(ModuleABC, OnReadyABC): self._logger = logger self._bot = bot self._message_service = message_service - - ModuleABC.__init__(self) - self._priorities[OnReadyABC] = 10 + + ModuleABC.__init__( + self, + { + OnReadyABC: 10 + }, + BootLogSettings + ) self._logger.trace(__name__, f'Module {type(self)} loaded') - + async def on_ready(self): self._logger.debug(__name__, f'Module {type(self)} started') try: @@ -69,4 +75,4 @@ class BootLog(ModuleABC, OnReadyABC): server_settings.login_message.format(init_time) ) - self._logger.trace(__name__, f'Module {type(self)} stopped') \ No newline at end of file + self._logger.trace(__name__, f'Module {type(self)} stopped') diff --git a/src/modules/boot_log/boot_log_settings.py b/src/modules/boot_log/boot_log_settings.py new file mode 100644 index 0000000..ea8611e --- /dev/null +++ b/src/modules/boot_log/boot_log_settings.py @@ -0,0 +1,29 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class BootLogSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._login_message_channel_id: int = 0 + self._login_message: str = '' + + @property + def login_message_channel_id(self) -> int: + return self._login_message_channel_id + + @property + def login_message(self) -> str: + return self._login_message + + def from_dict(self, settings: dict): + try: + self._login_message_channel_id = int(settings['LoginMessageChannelId']) + self._login_message = settings['LoginMessage'] + except Exception as e: + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {__name__} settings') + Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/src/modules_core/abc/module_abc.py b/src/modules_core/abc/module_abc.py index d860319..7829e32 100644 --- a/src/modules_core/abc/module_abc.py +++ b/src/modules_core/abc/module_abc.py @@ -1,12 +1,23 @@ from abc import ABC, abstractmethod +from typing import Optional +from cpl_core.configuration import ConfigurationModelABC class ModuleABC(ABC): @abstractmethod - def __init__(self): - self._priorities = {} + def __init__(self, priorities: dict[type, int], settings_type: type): + self._priorities = priorities self._success = True + self._settings_type = settings_type + + @property + def success(self) -> bool: + return self._success + + @property + def settings_type(self) -> type: + return self._settings_type def get_priority(self, t: type) -> int: if t not in self._priorities: @@ -15,7 +26,3 @@ class ModuleABC(ABC): def stop_propagation(self): self._success = False - - @property - def success(self) -> bool: - return self._success diff --git a/src/modules_core/service/module_service.py b/src/modules_core/service/module_service.py index 2d16bf6..965e0f6 100644 --- a/src/modules_core/service/module_service.py +++ b/src/modules_core/service/module_service.py @@ -1,8 +1,10 @@ from abc import ABC, ABCMeta from datetime import datetime +import json from typing import Optional, Sequence, Union import discord +from cpl_core.configuration import ConfigurationModelABC, ConfigurationABC from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.logging import LoggerABC @@ -64,8 +66,9 @@ class _MetaCogABC(ABCMeta, commands.CogMeta): pass class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): - def __init__(self, logger: LoggerABC, services: ServiceProviderABC, env: ApplicationEnvironmentABC): + def __init__(self, logger: LoggerABC, config: ConfigurationABC, services: ServiceProviderABC, env: ApplicationEnvironmentABC): self._logger = logger + self._config = config self._services = services self._env = env self._modules: List[ModuleABC] = List() @@ -75,12 +78,21 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): module_types = self._modules.where(lambda m: issubclass(m, t)) modules = List(t) for module_type in module_types: - module = self._services.get_service(module_type) + module: ModuleABC = self._services.get_service(module_type) if module is None: self._logger.warn(__name__, f'Module {module_type} not found in services!') break + + with open(f'config/{String.convert_to_snake_case(type(module).__name__).lower()}.json', encoding='utf-8') as cfg: + json_cfg = json.load(cfg) + for id in json_cfg: + settings: ConfigurationModelABC = module.settings_type() + settings.from_dict(json_cfg[id]) + self._config.add_configuration(f'{type(module).__name__}_{id}', settings) + self._logger.debug(__name__, f'Added config: {type(module).__name__}_{id}') + modules.append(module) - + return modules.order_by(lambda m: m.get_priority(t)) async def _handle_event(self, event: type, *args): @@ -94,6 +106,7 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0]) for module in modules: func = getattr(module, func_name) + exit() await func(*args) if not module.success: self._logger.debug(__name__, f'Stopped propagation for {event} from {type(module)}') -- 2.45.2 From 2f657a7ce785ae5dbf11980bc9f95397ef3e386f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 27 Dec 2021 19:41:16 +0100 Subject: [PATCH 02/10] [WIP] Improved configuration handling --- src/gismo/config/base.json | 18 +++++ src/gismo/config/boot_log.json | 4 - .../configuration/server_settings.py | 73 +----------------- src/modules/base/base.py | 16 ++-- src/modules/base/base_settings.py | 76 +++++++++++++++++++ src/modules/database/database.py | 7 +- src/modules_core/service/module_service.py | 18 ++--- 7 files changed, 120 insertions(+), 92 deletions(-) create mode 100644 src/modules/base/base_settings.py diff --git a/src/gismo/config/base.json b/src/gismo/config/base.json index 7a73a41..41b1cd3 100644 --- a/src/gismo/config/base.json +++ b/src/gismo/config/base.json @@ -1,2 +1,20 @@ { + "910199451145076828": { + "WelcomeMessage": "Hello There!\nIch bin Gismo und heiße dich bei {} herzlichst willkommen!", + "WelcomeMessageForTeam": "{} hat gerade das Irrenhaus betreten.", + "GoodbyeMessage": "Schade das du uns so schnell verlässt :(", + "MaxVoiceStateHours": 24, + "XpPerMessage": 2, + "XpPerOntimeHour": 4, + "AFKChannelIds": [ + 910199452915093593, + 910199452915093594 + ], + "AdminRoleIds": [ + 925072155203477584 + ], + "ModeratorRoleIds": [ + 925072209884635167 + ] + } } \ No newline at end of file diff --git a/src/gismo/config/boot_log.json b/src/gismo/config/boot_log.json index f54b141..155cf7c 100644 --- a/src/gismo/config/boot_log.json +++ b/src/gismo/config/boot_log.json @@ -2,9 +2,5 @@ "910199451145076828": { "LoginMessageChannelId": "910199452915093588", "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert" - }, - "511824600884051979": { - "LoginMessageChannelId": "521260270757347328", - "LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert" } } \ No newline at end of file diff --git a/src/gismo_core/configuration/server_settings.py b/src/gismo_core/configuration/server_settings.py index d9e3402..f4dffc4 100644 --- a/src/gismo_core/configuration/server_settings.py +++ b/src/gismo_core/configuration/server_settings.py @@ -11,17 +11,6 @@ class ServerSettings(ConfigurationModelABC): self._id: int = 0 self._message_delete_timer: int = 0 - self._login_message_channel_id: int = 0 - self._login_message: str = '' - self._welcome_message: str = '' - self._welcome_message_for_team: str = '' - self._goodbye_message: str = '' - self._max_voice_state_hours: int = 0 - self._xp_per_message: int = 0 - self._xp_per_ontime_hour: int = 0 - self._afk_channel_ids: list[int] = [] - self._admin_roles: list[int] = [] - self._moderator_roles: list[int] = [] @property def id(self) -> str: @@ -30,71 +19,11 @@ class ServerSettings(ConfigurationModelABC): @property def message_delete_timer(self) -> int: return self._message_delete_timer - - @property - def login_message_channel_id(self) -> int: - return self._login_message_channel_id - - @property - def login_message(self) -> str: - return self._login_message - - @property - def welcome_message(self) -> str: - return self._welcome_message - - @property - def welcome_message_for_team(self) -> str: - return self._welcome_message_for_team - - @property - def goodbye_message(self) -> str: - return self._goodbye_message - - @property - def max_voice_state_hours(self) -> int: - return self._max_voice_state_hours - - @property - def xp_per_message(self) -> int: - return self._xp_per_message - - @property - def xp_per_ontime_hour(self) -> int: - return self._xp_per_ontime_hour - - @property - def afk_channel_ids(self) -> list[int]: - return self._afk_channel_ids - - @property - def admin_roles(self) -> list[int]: - return self._admin_roles - - @property - def moderator_roles(self) -> list[int]: - return self._moderator_roles def from_dict(self, settings: dict): try: self._id = int(settings['Id']) - self._message_delete_timer = int(settings['MessageDeleteTimer']) - self._login_message_channel_id = int(settings['LoginMessageChannelId']) - self._login_message = settings['LoginMessage'] - self._welcome_message = settings['WelcomeMessage'] - self._welcome_message_for_team = settings['WelcomeMessageForTeam'] - self._goodbye_message = settings['GoodbyeMessage'] - self._max_voice_state_hours = int(settings['MaxVoiceStateHours']) - self._xp_per_message = int(settings['XpPerMessage']) - self._xp_per_ontime_hour = int(settings['XpPerOntimeHour']) - for id in settings['AFKChannelIds']: - self._afk_channel_ids.append(int(id)) - - for id in settings['AdminRoleIds']: - self._admin_roles.append(int(id)) - - for id in settings['ModeratorRoleIds']: - self._moderator_roles.append(int(id)) + self._message_delete_timer = int(settings['MessageDeleteTimer']) except Exception as e: Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/src/modules/base/base.py b/src/modules/base/base.py index 5fd7892..ff3e3f9 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -20,6 +20,7 @@ from gismo_data.model.known_user import KnownUser from gismo_data.model.user import User from gismo_data.model.user_joined_server import UserJoinedServer from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel +from modules.base.base_settings import BaseSettings from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC from modules_core.abc.events.on_member_remove_abc import OnMemberRemoveABC from modules_core.abc.events.on_message_abc import OnMessageABC @@ -56,11 +57,16 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._db = db self._messenger = messenger - ModuleABC.__init__(self) - self._priorities[OnMemberJoinABC] = 1 - self._priorities[OnMemberRemoveABC] = 1 - self._priorities[OnMessageABC] = 30 - self._priorities[OnVoiceStateUpdateABC] = 10 + ModuleABC.__init__( + self, + { + OnMemberJoinABC: 1, + OnMemberRemoveABC: 1, + OnMessageABC: 30, + OnVoiceStateUpdateABC: 10 + }, + BaseSettings + ) self._logger.trace(__name__, f'Module {type(self)} loaded') def _apppend_received_message_count(self, g_id: int): diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py new file mode 100644 index 0000000..112e4e8 --- /dev/null +++ b/src/modules/base/base_settings.py @@ -0,0 +1,76 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class BaseSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._welcome_message: str = '' + self._welcome_message_for_team: str = '' + self._goodbye_message: str = '' + self._max_voice_state_hours: int = 0 + self._xp_per_message: int = 0 + self._xp_per_ontime_hour: int = 0 + self._afk_channel_ids: list[int] = [] + self._admin_roles: list[int] = [] + self._moderator_roles: list[int] = [] + + @property + def welcome_message(self) -> str: + return self._welcome_message + + @property + def welcome_message_for_team(self) -> str: + return self._welcome_message_for_team + + @property + def goodbye_message(self) -> str: + return self._goodbye_message + + @property + def max_voice_state_hours(self) -> int: + return self._max_voice_state_hours + + @property + def xp_per_message(self) -> int: + return self._xp_per_message + + @property + def xp_per_ontime_hour(self) -> int: + return self._xp_per_ontime_hour + + @property + def afk_channel_ids(self) -> list[int]: + return self._afk_channel_ids + + @property + def admin_roles(self) -> list[int]: + return self._admin_roles + + @property + def moderator_roles(self) -> list[int]: + return self._moderator_roles + + def from_dict(self, settings: dict): + try: + self._welcome_message = settings['WelcomeMessage'] + self._welcome_message_for_team = settings['WelcomeMessageForTeam'] + self._goodbye_message = settings['GoodbyeMessage'] + self._max_voice_state_hours = int(settings['MaxVoiceStateHours']) + self._xp_per_message = int(settings['XpPerMessage']) + self._xp_per_ontime_hour = int(settings['XpPerOntimeHour']) + for id in settings['AFKChannelIds']: + self._afk_channel_ids.append(int(id)) + + for id in settings['AdminRoleIds']: + self._admin_roles.append(int(id)) + + for id in settings['ModeratorRoleIds']: + self._moderator_roles.append(int(id)) + 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/database/database.py b/src/modules/database/database.py index 65730df..eb19850 100644 --- a/src/modules/database/database.py +++ b/src/modules/database/database.py @@ -52,8 +52,11 @@ class Database(ModuleABC, OnReadyABC): self._user_joins = user_joins self._user_joins_vc = user_joins_vc - ModuleABC.__init__(self) - self._priorities[OnReadyABC] = 0 + ModuleABC.__init__( + self, + { OnReadyABC: 0 }, + None + ) self._logger.trace(__name__, f'Module {type(self)} loaded') def _validate_init_time(self): diff --git a/src/modules_core/service/module_service.py b/src/modules_core/service/module_service.py index 965e0f6..d029056 100644 --- a/src/modules_core/service/module_service.py +++ b/src/modules_core/service/module_service.py @@ -82,14 +82,15 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): if module is None: self._logger.warn(__name__, f'Module {module_type} not found in services!') break - - with open(f'config/{String.convert_to_snake_case(type(module).__name__).lower()}.json', encoding='utf-8') as cfg: - json_cfg = json.load(cfg) - for id in json_cfg: - settings: ConfigurationModelABC = module.settings_type() - settings.from_dict(json_cfg[id]) - self._config.add_configuration(f'{type(module).__name__}_{id}', settings) - self._logger.debug(__name__, f'Added config: {type(module).__name__}_{id}') + + if (module.settings_type is not None): + with open(f'config/{String.convert_to_snake_case(type(module).__name__).lower()}.json', encoding='utf-8') as cfg: + json_cfg = json.load(cfg) + for id in json_cfg: + settings: ConfigurationModelABC = module.settings_type() + settings.from_dict(json_cfg[id]) + self._config.add_configuration(f'{type(module).__name__}_{id}', settings) + self._logger.debug(__name__, f'Added config: {type(module).__name__}_{id}') modules.append(module) @@ -106,7 +107,6 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0]) for module in modules: func = getattr(module, func_name) - exit() await func(*args) if not module.success: self._logger.debug(__name__, f'Stopped propagation for {event} from {type(module)}') -- 2.45.2 From 500d884ea1b1d9bcf33a58092df5860f2ea0c709 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 27 Dec 2021 19:54:10 +0100 Subject: [PATCH 03/10] Added better config handling to modules --- src/modules/base/base.py | 26 ++++++++++++++------------ src/modules/boot_log/boot_log.py | 17 +++++++++++------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/modules/base/base.py b/src/modules/base/base.py index ff3e3f9..d08363c 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -8,7 +8,6 @@ from cpl_core.logging.logger_abc import LoggerABC from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.abc.message_service_abc import MessageServiceABC -from gismo_core.configuration.server_settings import ServerSettings from gismo_data.abc.client_repository_abc import ClientRepositoryABC from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC from gismo_data.abc.server_repository_abc import ServerRepositoryABC @@ -69,6 +68,9 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS ) self._logger.trace(__name__, f'Module {type(self)} loaded') + def _get_config(self, g_id: int) -> BaseSettings: + return self._config.get_configuration(f'{type(self).__name__}_{g_id}') + def _apppend_received_message_count(self, g_id: int): try: self._clients.apppend_received_message_count(self._bot.user.id, g_id, 1) @@ -98,7 +100,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS async def _add_if_not_exists_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Check if user exists {member}') - settings: ServerSettings = self._config.get_configuration(f'DSERVER_{member.guild.id}') + settings: BaseSettings = self._get_config() await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member) for roleId in settings.admin_roles: @@ -132,7 +134,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS async def _remove_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Remove user {member}') - settings: ServerSettings = self._config.get_configuration(f'DSERVER_{member.guild.id}') + settings: BaseSettings = self._get_config() await self._messenger.send_dm_message(settings.goodbye_message, member) try: @@ -169,7 +171,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._db.save_changes() return - server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{user.server.discord_server_id}') + settings: BaseSettings = self._get_config() join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.user_id) join.leaved_on = datetime.now() @@ -177,7 +179,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS # ontime as hours ontime = round((join.leaved_on - join.joined_on).total_seconds()/3600, 2) old_xp = user.xp - user.xp += round(ontime * server_st.xp_per_ontime_hour) + user.xp += round(ontime * settings.xp_per_ontime_hour) self._user_joins_vc.update_user_joined_voice_channel(join) self._users.update_user(user) @@ -206,9 +208,9 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._logger.error(__name__, f'User not found {dc_user_id}') return - server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{user.server.discord_server_id}') + settings: BaseSettings = self._get_config() old_xp = user.xp - user.xp += server_st._xp_per_message + user.xp += settings._xp_per_message self._users.update_user(user) self._db.save_changes() @@ -236,29 +238,29 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._logger.debug(__name__, f'Module {type(self)} started') self._logger.trace(__name__, f'Detected on_voice_state_update {member.id} from {before} to {after}') u: discord.User = member - server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{member.guild.id}') + settings: BaseSettings = self._get_config() server = self._servers.get_server_by_discord_id(member.guild.id) try: # join - if before.channel is None and after.channel is not None and after.channel.id not in server_st.afk_channel_ids: + if before.channel is None and after.channel is not None and after.channel.id not in settings.afk_channel_ids: self._logger.trace(__name__, f'User {u.id} joined {after.channel}') self._update_voice_state(True, member.id, after.channel.id, server.server_id) # leave - elif before.channel is not None and after.channel is None and before.channel.id not in server_st.afk_channel_ids: + elif before.channel is not None and after.channel is None and before.channel.id not in settings.afk_channel_ids: self._logger.trace(__name__, f'User {u.id} left {before.channel}') self._update_voice_state(False, member.id, before.channel.id, server.server_id) # channel to channel elif before.channel is not None and after.channel is not None: # joined - if before.channel.id in server_st.afk_channel_ids and after.channel.id not in server_st.afk_channel_ids: + if before.channel.id in settings.afk_channel_ids and after.channel.id not in settings.afk_channel_ids: self._logger.trace(__name__, f'User {u.id} joined {after.channel}') self._update_voice_state(True, member.id, after.channel.id, server.server_id) # left - elif after.channel.id in server_st.afk_channel_ids and before.channel.id not in server_st.afk_channel_ids: + elif after.channel.id in settings.afk_channel_ids and before.channel.id not in settings.afk_channel_ids: self._logger.trace(__name__, f'User {u.id} left {before.channel}') self._update_voice_state(False, member.id, before.channel.id, server.server_id) diff --git a/src/modules/boot_log/boot_log.py b/src/modules/boot_log/boot_log.py index cd07e80..b784bcb 100644 --- a/src/modules/boot_log/boot_log.py +++ b/src/modules/boot_log/boot_log.py @@ -61,18 +61,23 @@ class BootLog(ModuleABC, OnReadyABC): g: guild = g self._logger.debug(__name__, f'Server detected: {g.id}') - server_settings: ServerSettings = self._config.get_configuration( - f'DSERVER_{g.id}') + server_settings: ServerSettings = self._config.get_configuration(f'DSERVER_{g.id}') if server_settings is None: - self._logger.error( - __name__, f'Config for server {g.id} not found!') + self._logger.error(__name__, f'Config for server {g.id} not found!') + await self._bot.close() + return + + module_settings: BootLogSettings = self._config.get_configuration(f'{type(self).__name__}_{g.id}') + if module_settings is None: + self._logger.error(__name__, f'Config {type(self).__name__}_{g.id} not found!') await self._bot.close() return await self._message_service.send_channel_message( self._bot.get_channel( - server_settings.login_message_channel_id), - server_settings.login_message.format(init_time) + module_settings.login_message_channel_id + ), + module_settings.login_message.format(init_time) ) self._logger.trace(__name__, f'Module {type(self)} stopped') -- 2.45.2 From ff247bcec336245f4f3ce7ca2934c76b432d5e4a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 29 Dec 2021 19:29:35 +0100 Subject: [PATCH 04/10] [WIP] Added permission module --- cpl-workspace.json | 3 +- src/gismo/config/base.json | 6 --- src/gismo/config/permission.json | 10 +++++ src/gismo/startup.py | 9 +++- src/modules/__init__.py | 1 + src/modules/base/base.py | 1 + src/modules/base/base_settings.py | 16 ------- src/modules/permission/__init__.py | 1 + src/modules/permission/abc/__init__.py | 1 + .../permission/abc/permission_service_abc.py | 7 +++ .../configuration/permission_settings.py | 33 ++++++++++++++ src/modules/permission/permission.json | 43 +++++++++++++++++++ src/modules/permission/permission.py | 41 ++++++++++++++++++ src/modules/permission/service/__init__.py | 1 + .../permission/service/permission_service.py | 4 ++ 15 files changed, 153 insertions(+), 24 deletions(-) create mode 100644 src/gismo/config/permission.json create mode 100644 src/modules/permission/__init__.py create mode 100644 src/modules/permission/abc/__init__.py create mode 100644 src/modules/permission/abc/permission_service_abc.py create mode 100644 src/modules/permission/configuration/permission_settings.py create mode 100644 src/modules/permission/permission.json create mode 100644 src/modules/permission/permission.py create mode 100644 src/modules/permission/service/__init__.py create mode 100644 src/modules/permission/service/permission_service.py diff --git a/cpl-workspace.json b/cpl-workspace.json index 891044f..61764bb 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -11,7 +11,8 @@ "level-generator": "tools/level_generator/level-generator.json", "ontime-calculator": "tools/ontime_calculator/ontime-calculator.json", "database": "src/modules/database/database.json", - "base": "src/modules/base/base.json" + "base": "src/modules/base/base.json", + "permission": "src/modules/permission/permission.json" }, "Scripts": { "build-start": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../gismo; echo 'gismo:'; cpl build; cd ../../dist/gismo/build/gismo; bash gismo", diff --git a/src/gismo/config/base.json b/src/gismo/config/base.json index 41b1cd3..dbf85b8 100644 --- a/src/gismo/config/base.json +++ b/src/gismo/config/base.json @@ -9,12 +9,6 @@ "AFKChannelIds": [ 910199452915093593, 910199452915093594 - ], - "AdminRoleIds": [ - 925072155203477584 - ], - "ModeratorRoleIds": [ - 925072209884635167 ] } } \ No newline at end of file diff --git a/src/gismo/config/permission.json b/src/gismo/config/permission.json new file mode 100644 index 0000000..dac1484 --- /dev/null +++ b/src/gismo/config/permission.json @@ -0,0 +1,10 @@ +{ + "910199451145076828": { + "AdminRoleIds": [ + 925072155203477584 + ], + "ModeratorRoleIds": [ + 925072209884635167 + ] + } +} \ No newline at end of file diff --git a/src/gismo/startup.py b/src/gismo/startup.py index fbdd7cf..1a1f79e 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -37,6 +37,9 @@ from gismo_data.service.user_repository_service import UserRepositoryService from modules.base.base import Base from modules.boot_log.boot_log import BootLog from modules.database.database import Database +from modules.permission.abc.permission_service_abc import PermissionServiceABC +from modules.permission.permission import Permission +from modules.permission.service.permission_service import PermissionService from modules_core.abc.module_abc import ModuleABC from modules_core.abc.module_service_abc import ModuleServiceABC from modules_core.service.module_service import ModuleService @@ -73,7 +76,7 @@ class Startup(StartupABC): services.add_singleton(BotServiceABC, BotService) services.add_transient(MessageServiceABC, MessageService) - # services + # general services services.add_transient(MigrationService) # data services @@ -85,10 +88,14 @@ class Startup(StartupABC): services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService) # modules + services.add_transient(ModuleABC, Permission) services.add_transient(ModuleABC, Database) services.add_transient(ModuleABC, Base) services.add_transient(ModuleABC, BootLog) + # permission module services + services.add_transient(PermissionServiceABC, PermissionService) + # migrations services.add_transient(MigrationABC, InitialMigration) services.add_transient(MigrationABC, Migration_0_3) diff --git a/src/modules/__init__.py b/src/modules/__init__.py index e69de29..425ab6c 100644 --- a/src/modules/__init__.py +++ b/src/modules/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/modules/base/base.py b/src/modules/base/base.py index d08363c..ca41fb6 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -100,6 +100,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS async def _add_if_not_exists_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Check if user exists {member}') + # todo: user permission service settings: BaseSettings = self._get_config() await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member) diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py index 112e4e8..7afd1c0 100644 --- a/src/modules/base/base_settings.py +++ b/src/modules/base/base_settings.py @@ -16,8 +16,6 @@ class BaseSettings(ConfigurationModelABC): self._xp_per_message: int = 0 self._xp_per_ontime_hour: int = 0 self._afk_channel_ids: list[int] = [] - self._admin_roles: list[int] = [] - self._moderator_roles: list[int] = [] @property def welcome_message(self) -> str: @@ -47,14 +45,6 @@ class BaseSettings(ConfigurationModelABC): def afk_channel_ids(self) -> list[int]: return self._afk_channel_ids - @property - def admin_roles(self) -> list[int]: - return self._admin_roles - - @property - def moderator_roles(self) -> list[int]: - return self._moderator_roles - def from_dict(self, settings: dict): try: self._welcome_message = settings['WelcomeMessage'] @@ -65,12 +55,6 @@ class BaseSettings(ConfigurationModelABC): self._xp_per_ontime_hour = int(settings['XpPerOntimeHour']) for id in settings['AFKChannelIds']: self._afk_channel_ids.append(int(id)) - - for id in settings['AdminRoleIds']: - self._admin_roles.append(int(id)) - - for id in settings['ModeratorRoleIds']: - self._moderator_roles.append(int(id)) 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/__init__.py b/src/modules/permission/__init__.py new file mode 100644 index 0000000..425ab6c --- /dev/null +++ b/src/modules/permission/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/modules/permission/abc/__init__.py b/src/modules/permission/abc/__init__.py new file mode 100644 index 0000000..425ab6c --- /dev/null +++ b/src/modules/permission/abc/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/modules/permission/abc/permission_service_abc.py b/src/modules/permission/abc/permission_service_abc.py new file mode 100644 index 0000000..d74070b --- /dev/null +++ b/src/modules/permission/abc/permission_service_abc.py @@ -0,0 +1,7 @@ +from abc import ABC, abstractmethod + + +class PermissionServiceABC(ABC): + + @abstractmethod + def __init__(self): pass diff --git a/src/modules/permission/configuration/permission_settings.py b/src/modules/permission/configuration/permission_settings.py new file mode 100644 index 0000000..95cf5ef --- /dev/null +++ b/src/modules/permission/configuration/permission_settings.py @@ -0,0 +1,33 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class PermissionSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._admin_roles: list[int] = [] + self._moderator_roles: list[int] = [] + + + @property + def admin_roles(self) -> list[int]: + return self._admin_roles + + @property + def moderator_roles(self) -> list[int]: + return self._moderator_roles + + def from_dict(self, settings: dict): + try: + for id in settings['AdminRoleIds']: + self._admin_roles.append(int(id)) + + for id in settings['ModeratorRoleIds']: + self._moderator_roles.append(int(id)) + 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.json b/src/modules/permission/permission.json new file mode 100644 index 0000000..be0f7a5 --- /dev/null +++ b/src/modules/permission/permission.json @@ -0,0 +1,43 @@ +{ + "ProjectSettings": { + "Name": "modules/permission", + "Version": { + "Major": "0", + "Minor": "0", + "Micro": "0" + }, + "Author": "", + "AuthorEmail": "", + "Description": "", + "LongDescription": "", + "URL": "", + "CopyrightDate": "", + "CopyrightName": "", + "LicenseName": "", + "LicenseDescription": "", + "Dependencies": [ + "sh_cpl-core>=2021.11.0.post1" + ], + "PythonVersion": ">=3.9.2", + "PythonPath": { + "linux": "" + }, + "Classifiers": [] + }, + "BuildSettings": { + "ProjectType": "library", + "SourcePath": "", + "OutputPath": "../../dist", + "Main": "modules/permission.main", + "EntryPoint": "modules/permission", + "IncludePackageData": false, + "Included": [], + "Excluded": [ + "*/__pycache__", + "*/logs", + "*/tests" + ], + "PackageData": {}, + "ProjectReferences": [] + } +} \ No newline at end of file diff --git a/src/modules/permission/permission.py b/src/modules/permission/permission.py new file mode 100644 index 0000000..2b71dc8 --- /dev/null +++ b/src/modules/permission/permission.py @@ -0,0 +1,41 @@ +from ctypes import Union +from datetime import datetime + +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.database.context import DatabaseContextABC +from cpl_core.logging import LoggerABC + +from gismo_core.abc.bot_service_abc import BotServiceABC +from gismo_core.configuration.server_settings import ServerSettings +from gismo_data.abc.client_repository_abc import ClientRepositoryABC +from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC +from gismo_data.abc.user_joined_server_repository_abc import \ + UserJoinedServerRepositoryABC +from gismo_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC +from gismo_data.abc.user_repository_abc import UserRepositoryABC +from gismo_data.model.client import Client +from gismo_data.model.known_user import KnownUser +from gismo_data.model.server import Server +from gismo_data.model.user import User +from gismo_data.model.user_joined_server import UserJoinedServer +from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel +from gismo_data.service.user_repository_service import ServerRepositoryABC +from modules.permission.configuration.permission_settings import PermissionSettings +from modules_core.abc.events.on_ready_abc import OnReadyABC +from modules_core.abc.module_abc import ModuleABC + + +class Permission(ModuleABC): + + def __init__( + self, + logger: LoggerABC, + ): + self._logger = logger + ModuleABC.__init__( + self, + { OnReadyABC: 0 }, + PermissionSettings + ) + self._logger.trace(__name__, f'Module {type(self)} loaded') \ No newline at end of file diff --git a/src/modules/permission/service/__init__.py b/src/modules/permission/service/__init__.py new file mode 100644 index 0000000..425ab6c --- /dev/null +++ b/src/modules/permission/service/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/modules/permission/service/permission_service.py b/src/modules/permission/service/permission_service.py new file mode 100644 index 0000000..461fe98 --- /dev/null +++ b/src/modules/permission/service/permission_service.py @@ -0,0 +1,4 @@ +class PermissionService: + + def __init__(self): + pass -- 2.45.2 From a8663b8d54f72321abeb8505cc2ac1a9209cdd89 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 29 Dec 2021 20:41:15 +0100 Subject: [PATCH 05/10] Improved permission handling --- src/gismo/startup.py | 15 ++-- src/modules/base/base.py | 22 ++--- src/modules/boot_log/boot_log.py | 2 +- src/modules/database/database.py | 2 +- .../permission/abc/permission_service_abc.py | 25 ++++++ .../configuration/permission_settings.py | 1 - src/modules/permission/permission.py | 46 +++++----- .../permission/service/permission_service.py | 90 ++++++++++++++++++- src/modules_core/service/module_service.py | 22 +++-- 9 files changed, 164 insertions(+), 61 deletions(-) diff --git a/src/gismo/startup.py b/src/gismo/startup.py index 1a1f79e..df453cb 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -71,12 +71,10 @@ class Startup(StartupABC): services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) - # modules + # general services services.add_singleton(ModuleServiceABC, ModuleService) services.add_singleton(BotServiceABC, BotService) services.add_transient(MessageServiceABC, MessageService) - - # general services services.add_transient(MigrationService) # data services @@ -87,14 +85,15 @@ class Startup(StartupABC): services.add_transient(UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService) services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService) + # module services + services.add_singleton(PermissionServiceABC, PermissionService) + # modules - services.add_transient(ModuleABC, Permission) services.add_transient(ModuleABC, Database) - services.add_transient(ModuleABC, Base) services.add_transient(ModuleABC, BootLog) - - # permission module services - services.add_transient(PermissionServiceABC, PermissionService) + services.add_singleton(ModuleABC, Permission) + services.add_singleton(ModuleABC, Base) + # migrations services.add_transient(MigrationABC, InitialMigration) diff --git a/src/modules/base/base.py b/src/modules/base/base.py index ca41fb6..a10e745 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -20,6 +20,7 @@ from gismo_data.model.user import User from gismo_data.model.user_joined_server import UserJoinedServer from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel from modules.base.base_settings import BaseSettings +from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC from modules_core.abc.events.on_member_remove_abc import OnMemberRemoveABC from modules_core.abc.events.on_message_abc import OnMessageABC @@ -42,7 +43,8 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS user_joins_vc: UserJoinedVoiceChannelRepositoryABC, bot: BotServiceABC, db: DatabaseContextABC, - messenger: MessageServiceABC + messenger: MessageServiceABC, + permission_service: PermissionServiceABC ): self._config = config self._logger = logger @@ -55,6 +57,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._bot = bot self._db = db self._messenger = messenger + self._permission_service = permission_service ModuleABC.__init__( self, @@ -66,7 +69,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS }, BaseSettings ) - self._logger.trace(__name__, f'Module {type(self)} loaded') + self._logger.info(__name__, f'Module {type(self)} loaded') def _get_config(self, g_id: int) -> BaseSettings: return self._config.get_configuration(f'{type(self).__name__}_{g_id}') @@ -100,21 +103,14 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS async def _add_if_not_exists_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Check if user exists {member}') - # todo: user permission service settings: BaseSettings = self._get_config() await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member) - for roleId in settings.admin_roles: - g: discord.Guild = member.guild - role: discord.Role = g.get_role(roleId) - for admin in role.members: - await self._messenger.send_dm_message(settings.welcome_message_for_team.format(member.name), admin) + for admin in self._permission_service.get_admins(): + await self._messenger.send_dm_message(settings.welcome_message_for_team.format(member.name), admin) - for roleId in settings.moderator_roles: - g: discord.Guild = member.guild - role: discord.Role = g.get_role(roleId) - for mod in role.members: - await self._messenger.send_dm_message(settings.welcome_message_for_team.format(member.name), mod) + for moderator in self._permission_service.get_moderators(): + await self._messenger.send_dm_message(settings.welcome_message_for_team.format(member.name), moderator) try: server = self._servers.get_server_by_discord_id(member.guild.id) diff --git a/src/modules/boot_log/boot_log.py b/src/modules/boot_log/boot_log.py index b784bcb..d6e0928 100644 --- a/src/modules/boot_log/boot_log.py +++ b/src/modules/boot_log/boot_log.py @@ -35,7 +35,7 @@ class BootLog(ModuleABC, OnReadyABC): }, BootLogSettings ) - self._logger.trace(__name__, f'Module {type(self)} loaded') + self._logger.info(__name__, f'Module {type(self)} loaded') async def on_ready(self): self._logger.debug(__name__, f'Module {type(self)} started') diff --git a/src/modules/database/database.py b/src/modules/database/database.py index eb19850..2c6e226 100644 --- a/src/modules/database/database.py +++ b/src/modules/database/database.py @@ -57,7 +57,7 @@ class Database(ModuleABC, OnReadyABC): { OnReadyABC: 0 }, None ) - self._logger.trace(__name__, f'Module {type(self)} loaded') + self._logger.info(__name__, f'Module {type(self)} loaded') def _validate_init_time(self): try: diff --git a/src/modules/permission/abc/permission_service_abc.py b/src/modules/permission/abc/permission_service_abc.py index d74070b..c47ece7 100644 --- a/src/modules/permission/abc/permission_service_abc.py +++ b/src/modules/permission/abc/permission_service_abc.py @@ -1,7 +1,32 @@ from abc import ABC, abstractmethod +import discord class PermissionServiceABC(ABC): @abstractmethod def __init__(self): pass + + @abstractmethod + def on_ready(self): pass + + @abstractmethod + def on_member_update(self, before: discord.Member, after: discord.Member): pass + + @abstractmethod + def get_admin_role_ids(self, g_id: int) -> list[int]: pass + + @abstractmethod + def get_admin_roles(self, g_id: int) -> list[discord.Role]: pass + + @abstractmethod + def get_admins(self, g_id: int) -> list[discord.Member]: pass + + @abstractmethod + def get_moderator_role_ids(self, g_id: int) -> list[int]: pass + + @abstractmethod + def get_moderator_roles(self, g_id: int) -> list[discord.Role]: pass + + @abstractmethod + def get_moderators(self, g_id: int) -> list[discord.Member]: pass diff --git a/src/modules/permission/configuration/permission_settings.py b/src/modules/permission/configuration/permission_settings.py index 95cf5ef..dceabe8 100644 --- a/src/modules/permission/configuration/permission_settings.py +++ b/src/modules/permission/configuration/permission_settings.py @@ -12,7 +12,6 @@ class PermissionSettings(ConfigurationModelABC): self._admin_roles: list[int] = [] self._moderator_roles: list[int] = [] - @property def admin_roles(self) -> list[int]: return self._admin_roles diff --git a/src/modules/permission/permission.py b/src/modules/permission/permission.py index 2b71dc8..1f799d0 100644 --- a/src/modules/permission/permission.py +++ b/src/modules/permission/permission.py @@ -1,41 +1,37 @@ -from ctypes import Union -from datetime import datetime - import discord -from cpl_core.configuration import ConfigurationABC -from cpl_core.database.context import DatabaseContextABC -from cpl_core.logging import LoggerABC -from gismo_core.abc.bot_service_abc import BotServiceABC -from gismo_core.configuration.server_settings import ServerSettings -from gismo_data.abc.client_repository_abc import ClientRepositoryABC -from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC -from gismo_data.abc.user_joined_server_repository_abc import \ - UserJoinedServerRepositoryABC -from gismo_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC -from gismo_data.abc.user_repository_abc import UserRepositoryABC -from gismo_data.model.client import Client -from gismo_data.model.known_user import KnownUser -from gismo_data.model.server import Server -from gismo_data.model.user import User -from gismo_data.model.user_joined_server import UserJoinedServer -from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel -from gismo_data.service.user_repository_service import ServerRepositoryABC -from modules.permission.configuration.permission_settings import PermissionSettings +from cpl_core.logging import LoggerABC +from modules.permission.abc.permission_service_abc import PermissionServiceABC +from modules.permission.configuration.permission_settings import \ + PermissionSettings +from modules_core.abc.events.on_member_update_abc import OnMemberUpdateABC from modules_core.abc.events.on_ready_abc import OnReadyABC from modules_core.abc.module_abc import ModuleABC -class Permission(ModuleABC): +class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC): def __init__( self, logger: LoggerABC, + permission_service: PermissionServiceABC ): self._logger = logger + self._permission_service = permission_service + ModuleABC.__init__( self, - { OnReadyABC: 0 }, + { OnReadyABC: 1, OnMemberUpdateABC: 0 }, PermissionSettings ) - self._logger.trace(__name__, f'Module {type(self)} loaded') \ No newline at end of file + self._logger.info(__name__, f'Module {type(self)} loaded') + + async def on_ready(self): + self._logger.debug(__name__, f'Module {type(self)} started') + self._permission_service.on_ready() + + async def on_member_update(self, before: discord.Member, after: discord.Member): + self._logger.debug(__name__, f'Module {type(self)} started') + + if before.roles != after.roles: + self._permission_service.on_member_update(before, after) \ No newline at end of file diff --git a/src/modules/permission/service/permission_service.py b/src/modules/permission/service/permission_service.py index 461fe98..c0b9158 100644 --- a/src/modules/permission/service/permission_service.py +++ b/src/modules/permission/service/permission_service.py @@ -1,4 +1,88 @@ -class PermissionService: +import discord +from cpl_core.logging import LoggerABC +from cpl_core.configuration import ConfigurationABC +from gismo_core.abc.bot_service_abc import BotServiceABC +from modules.permission.abc.permission_service_abc import PermissionServiceABC +from modules.permission.configuration.permission_settings import PermissionSettings - def __init__(self): - pass + +class PermissionService(PermissionServiceABC): + + def __init__(self, logger: LoggerABC, bot: BotServiceABC, config: ConfigurationABC): + PermissionServiceABC.__init__(self) + self._logger = logger + 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._moderator_role_ids: dict[list[int]] = {} + self._moderator_roles: dict[list[discord.Role]] = {} + self._moderators: dict[list[discord.Member]] = {} + + def on_ready(self): + for guild in self._bot.guilds: + guild: discord.Guild = guild + + settings: PermissionSettings = self._config.get_configuration(f'Permission_{guild.id}') + if settings is None: + self._logger.error(__name__, 'Permission settings not found') + return + + self._admin_role_ids[guild.id] = settings.admin_roles + self._admin_roles[guild.id] = [] + self._admins[guild.id] = [] + + self._moderator_role_ids[guild.id] = settings.moderator_roles + self._moderator_roles[guild.id] = [] + self._moderators[guild.id] = [] + + for role in guild.roles: + role: discord.Role = role + + if role.id in self._admin_role_ids: + self._admin_roles[guild.id].append(role) + + for member in role.members: + self._admins[guild.id].append(member) + + if role.id in self._moderator_role_ids: + self._moderator_roles[guild.id].append(role) + + for member in role.members: + self._moderators[guild.id].append(member) + + def on_member_update(self, before: discord.Member, after: discord.Member): + g_id = after.guild.id + + if before in self._admin_roles[g_id] and after not in self._admin_roles[g_id]: + self._admins[g_id].remove(after) + + elif before not in self._admin_roles[g_id] and after in self._admin_roles[g_id]: + self._admins[g_id].append(after) + + if before in self._moderator_roles[g_id] and after not in self._moderator_roles[g_id]: + self._moderators[g_id].remove(after) + + elif before not in self._moderator_roles[g_id] and after in self._moderator_roles[g_id]: + self._moderators[g_id].append(after) + + def get_admin_role_ids(self, g_id: int) -> list[int]: + return self._admin_role_ids[g_id] + + def get_admin_roles(self, g_id: int) -> list[discord.Role]: + return self._admin_roles[g_id] + + def get_admins(self, g_id: int) -> list[discord.Member]: + return self._admins[g_id] + + def get_moderator_role_ids(self, g_id: int) -> list[int]: + return self._moderator_role_ids[g_id] + + def get_moderator_roles(self, g_id: int) -> list[discord.Role]: + return self._moderator_roles[g_id] + + def get_moderators(self, g_id: int) -> list[discord.Member]: + return self._moderators[g_id] diff --git a/src/modules_core/service/module_service.py b/src/modules_core/service/module_service.py index d029056..ead37c5 100644 --- a/src/modules_core/service/module_service.py +++ b/src/modules_core/service/module_service.py @@ -90,7 +90,7 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): settings: ConfigurationModelABC = module.settings_type() settings.from_dict(json_cfg[id]) self._config.add_configuration(f'{type(module).__name__}_{id}', settings) - self._logger.debug(__name__, f'Added config: {type(module).__name__}_{id}') + self._logger.info(__name__, f'Added config: {type(module).__name__}_{id}') modules.append(module) @@ -103,14 +103,18 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): if modules.count() < 1: self._logger.debug(__name__, f'Stopped {event} modules') return - - func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0]) - for module in modules: - func = getattr(module, func_name) - await func(*args) - if not module.success: - self._logger.debug(__name__, f'Stopped propagation for {event} from {type(module)}') - break + + try: + func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0]) + for module in modules: + self._logger.trace(__name__, f'Start {type(module)} module') + func = getattr(module, func_name) + await func(*args) + if not module.success: + self._logger.debug(__name__, f'Stopped propagation for {event} from {type(module)}') + break + except Exception as e: + self._logger.error(__name__, f'Start {event} modules failed', e) self._logger.debug(__name__, f'Stopped {event} modules') -- 2.45.2 From b352987dccf3ec10219fdb261b259e40e7449f53 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 29 Dec 2021 21:01:58 +0100 Subject: [PATCH 06/10] Improved permission role handling --- src/modules/permission/permission.py | 2 +- .../permission/service/permission_service.py | 61 ++++++++++++------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/modules/permission/permission.py b/src/modules/permission/permission.py index 1f799d0..9a4dcee 100644 --- a/src/modules/permission/permission.py +++ b/src/modules/permission/permission.py @@ -34,4 +34,4 @@ class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC): self._logger.debug(__name__, f'Module {type(self)} started') if before.roles != after.roles: - self._permission_service.on_member_update(before, after) \ No newline at end of file + self._permission_service.on_member_update(before, after) diff --git a/src/modules/permission/service/permission_service.py b/src/modules/permission/service/permission_service.py index c0b9158..6172625 100644 --- a/src/modules/permission/service/permission_service.py +++ b/src/modules/permission/service/permission_service.py @@ -25,6 +25,7 @@ class PermissionService(PermissionServiceABC): def on_ready(self): for guild in self._bot.guilds: guild: discord.Guild = guild + self._logger.debug(__name__, f'Validate permission settings') settings: PermissionSettings = self._config.get_configuration(f'Permission_{guild.id}') if settings is None: @@ -32,42 +33,60 @@ class PermissionService(PermissionServiceABC): return self._admin_role_ids[guild.id] = settings.admin_roles - self._admin_roles[guild.id] = [] - self._admins[guild.id] = [] - self._moderator_role_ids[guild.id] = settings.moderator_roles - self._moderator_roles[guild.id] = [] - self._moderators[guild.id] = [] + + admin_roles = [] + admins = [] + + mod_roles = [] + mods = [] for role in guild.roles: role: discord.Role = role - if role.id in self._admin_role_ids: - self._admin_roles[guild.id].append(role) + if role.id in self._admin_role_ids[guild.id]: + admin_roles.append(role) + self._logger.trace(__name__, f'Added admin role {role}') for member in role.members: - self._admins[guild.id].append(member) + admins.append(member) + self._logger.trace(__name__, f'Added admin {member}') - if role.id in self._moderator_role_ids: - self._moderator_roles[guild.id].append(role) + if role.id in self._moderator_role_ids[guild.id]: + mod_roles.append(role) + self._logger.trace(__name__, f'Added moderator role {role}') for member in role.members: - self._moderators[guild.id].append(member) + mods.append(member) + self._logger.trace(__name__, f'Added moderator {member}') + + + self._admin_roles[guild.id] = admin_roles + self._admins[guild.id] = admins + self._moderator_roles[guild.id] = mod_roles + self._moderators[guild.id] = mods def on_member_update(self, before: discord.Member, after: discord.Member): g_id = after.guild.id - - if before in self._admin_roles[g_id] and after not in self._admin_roles[g_id]: - self._admins[g_id].remove(after) - - elif before not in self._admin_roles[g_id] and after in self._admin_roles[g_id]: - self._admins[g_id].append(after) - if before in self._moderator_roles[g_id] and after not in self._moderator_roles[g_id]: - self._moderators[g_id].remove(after) + for admin_role in self._admin_roles[g_id]: + 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') + + elif admin_role in after.roles and admin_role not in before.roles: + self._admins[g_id].append(after) + self._logger.trace(__name__, f'Added {after.id} to admins') - elif before not in self._moderator_roles[g_id] and after in self._moderator_roles[g_id]: - self._moderators[g_id].append(after) + for moderator_role in self._moderator_roles[g_id]: + if moderator_role in before.roles and moderator_role not in after.roles: + self._moderators[g_id].remove(after) + self._logger.trace(__name__, f'Removed {after.id} from moderators') + + elif moderator_role in after.roles and moderator_role not in before.roles: + 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] -- 2.45.2 From 7dd2d13b58a9f1bc6d9f783332ccfe1f6326c561 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 31 Dec 2021 10:18:24 +0100 Subject: [PATCH 07/10] Moved modules_core -> gismo_core --- cpl-workspace.json | 1 - src/gismo/gismo.json | 1 - src/gismo/main.py | 2 + src/gismo/startup.py | 6 +- .../abc/events/on_bulk_message_delete_abc.py | 0 .../abc/events/on_connect_abc.py | 0 .../abc/events/on_disconnect_abc.py | 0 .../abc/events/on_error_abc.py | 0 .../abc/events/on_group_join_abc.py | 0 .../abc/events/on_group_remove_abc.py | 0 .../abc/events/on_guild_available_abc.py | 0 .../abc/events/on_guild_channel_create_abc.py | 0 .../abc/events/on_guild_channel_delete_abc.py | 0 .../on_guild_channel_pins_update_abc.py | 0 .../abc/events/on_guild_channel_update_abc.py | 0 .../abc/events/on_guild_emojis_update_abc.py | 0 .../on_guild_integrations_update_abc.py | 0 .../abc/events/on_guild_join_abc.py | 0 .../abc/events/on_guild_remove_abc.py | 0 .../abc/events/on_guild_role_create_abc.py | 0 .../abc/events/on_guild_role_delete_abc.py | 0 .../abc/events/on_guild_role_update_abc.py | 0 .../abc/events/on_guild_unavailable_abc.py | 0 .../abc/events/on_guild_update_abc.py | 0 .../abc/events/on_invite_create_abc.py | 0 .../abc/events/on_invite_delete_abc.py | 0 .../abc/events/on_member_ban_abc.py | 0 .../abc/events/on_member_join_abc.py | 0 .../abc/events/on_member_remove_abc.py | 0 .../abc/events/on_member_unban_abc.py | 0 .../abc/events/on_member_update_abc.py | 0 .../abc/events/on_message_abc.py | 0 .../abc/events/on_message_delete_abc.py | 0 .../abc/events/on_message_edit_abc.py | 0 .../events/on_private_channel_create_abc.py | 0 .../events/on_private_channel_delete_abc.py | 0 .../on_private_channel_pins_update_abc.py | 0 .../events/on_private_channel_update_abc.py | 0 .../abc/events/on_reaction_add_abc.py | 0 .../abc/events/on_reaction_clear_abc.py | 0 .../abc/events/on_reaction_clear_emoji_abc.py | 0 .../abc/events/on_reaction_remove_abc.py | 0 .../abc/events/on_ready_abc.py | 0 .../abc/events/on_relationship_add_abc.py | 0 .../abc/events/on_relationship_remove_abc.py | 0 .../abc/events/on_relationship_update_abc.py | 0 .../abc/events/on_resume_abc.py | 0 .../abc/events/on_typing_abc.py | 0 .../abc/events/on_user_update_abc.py | 0 .../abc/events/on_voice_state_update_abc.py | 0 .../abc/events/on_webhooks_update_abc.py | 0 .../abc/module_abc.py | 0 .../abc/module_service_abc.py | 0 src/gismo_core/service/bot_service.py | 4 +- .../service/module_service.py | 96 +++++++++---------- src/modules/base/base.py | 10 +- src/modules/boot_log/boot_log.py | 4 +- src/modules/database/database.py | 4 +- src/modules/permission/permission.py | 6 +- src/modules_core/__init__.py | 25 ----- src/modules_core/abc/__init__.py | 25 ----- src/modules_core/events_enum.py | 6 -- src/modules_core/modules-core.json | 44 --------- src/modules_core/service/__init__.py | 25 ----- 64 files changed, 67 insertions(+), 192 deletions(-) rename src/{modules_core => gismo_core}/abc/events/on_bulk_message_delete_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_connect_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_disconnect_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_error_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_group_join_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_group_remove_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_available_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_channel_create_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_channel_delete_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_channel_pins_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_channel_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_emojis_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_integrations_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_join_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_remove_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_role_create_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_role_delete_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_role_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_unavailable_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_guild_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_invite_create_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_invite_delete_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_member_ban_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_member_join_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_member_remove_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_member_unban_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_member_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_message_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_message_delete_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_message_edit_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_private_channel_create_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_private_channel_delete_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_private_channel_pins_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_private_channel_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_reaction_add_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_reaction_clear_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_reaction_clear_emoji_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_reaction_remove_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_ready_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_relationship_add_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_relationship_remove_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_relationship_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_resume_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_typing_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_user_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_voice_state_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/events/on_webhooks_update_abc.py (100%) rename src/{modules_core => gismo_core}/abc/module_abc.py (100%) rename src/{modules_core => gismo_core}/abc/module_service_abc.py (100%) rename src/{modules_core => gismo_core}/service/module_service.py (80%) delete mode 100644 src/modules_core/__init__.py delete mode 100644 src/modules_core/abc/__init__.py delete mode 100644 src/modules_core/events_enum.py delete mode 100644 src/modules_core/modules-core.json delete mode 100644 src/modules_core/service/__init__.py diff --git a/cpl-workspace.json b/cpl-workspace.json index 61764bb..2684182 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -6,7 +6,6 @@ "gismo-cli": "src/gismo_cli/gismo-cli.json", "gismo-core": "src/gismo_core/gismo-core.json", "gismo-data": "src/gismo_data/gismo-data.json", - "modules-core": "src/modules_core/modules-core.json", "boot-log": "src/modules/boot_log/boot-log.json", "level-generator": "tools/level_generator/level-generator.json", "ontime-calculator": "tools/ontime_calculator/ontime-calculator.json", diff --git a/src/gismo/gismo.json b/src/gismo/gismo.json index 81c9765..37f5aaa 100644 --- a/src/gismo/gismo.json +++ b/src/gismo/gismo.json @@ -47,7 +47,6 @@ "ProjectReferences": [ "../gismo_core/gismo-core.json", "../gismo_data/gismo-data.json", - "../modules_core/modules-core.json", "../modules/boot_log/boot-log.json", "../modules/base/base.json", "../modules/database/database.json" diff --git a/src/gismo/main.py b/src/gismo/main.py index 87df32e..af10e51 100644 --- a/src/gismo/main.py +++ b/src/gismo/main.py @@ -43,3 +43,5 @@ if __name__ == '__main__': # / ) ) ~ edraft # ___// | / # `--' \_~-, + +# happy new year :) diff --git a/src/gismo/startup.py b/src/gismo/startup.py index df453cb..aaf9ba3 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -40,9 +40,9 @@ from modules.database.database import Database from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.permission import Permission from modules.permission.service.permission_service import PermissionService -from modules_core.abc.module_abc import ModuleABC -from modules_core.abc.module_service_abc import ModuleServiceABC -from modules_core.service.module_service import ModuleService +from gismo_core.abc.module_abc import ModuleABC +from gismo_core.abc.module_service_abc import ModuleServiceABC +from gismo_core.service.module_service import ModuleService class Startup(StartupABC): diff --git a/src/modules_core/abc/events/on_bulk_message_delete_abc.py b/src/gismo_core/abc/events/on_bulk_message_delete_abc.py similarity index 100% rename from src/modules_core/abc/events/on_bulk_message_delete_abc.py rename to src/gismo_core/abc/events/on_bulk_message_delete_abc.py diff --git a/src/modules_core/abc/events/on_connect_abc.py b/src/gismo_core/abc/events/on_connect_abc.py similarity index 100% rename from src/modules_core/abc/events/on_connect_abc.py rename to src/gismo_core/abc/events/on_connect_abc.py diff --git a/src/modules_core/abc/events/on_disconnect_abc.py b/src/gismo_core/abc/events/on_disconnect_abc.py similarity index 100% rename from src/modules_core/abc/events/on_disconnect_abc.py rename to src/gismo_core/abc/events/on_disconnect_abc.py diff --git a/src/modules_core/abc/events/on_error_abc.py b/src/gismo_core/abc/events/on_error_abc.py similarity index 100% rename from src/modules_core/abc/events/on_error_abc.py rename to src/gismo_core/abc/events/on_error_abc.py diff --git a/src/modules_core/abc/events/on_group_join_abc.py b/src/gismo_core/abc/events/on_group_join_abc.py similarity index 100% rename from src/modules_core/abc/events/on_group_join_abc.py rename to src/gismo_core/abc/events/on_group_join_abc.py diff --git a/src/modules_core/abc/events/on_group_remove_abc.py b/src/gismo_core/abc/events/on_group_remove_abc.py similarity index 100% rename from src/modules_core/abc/events/on_group_remove_abc.py rename to src/gismo_core/abc/events/on_group_remove_abc.py diff --git a/src/modules_core/abc/events/on_guild_available_abc.py b/src/gismo_core/abc/events/on_guild_available_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_available_abc.py rename to src/gismo_core/abc/events/on_guild_available_abc.py diff --git a/src/modules_core/abc/events/on_guild_channel_create_abc.py b/src/gismo_core/abc/events/on_guild_channel_create_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_channel_create_abc.py rename to src/gismo_core/abc/events/on_guild_channel_create_abc.py diff --git a/src/modules_core/abc/events/on_guild_channel_delete_abc.py b/src/gismo_core/abc/events/on_guild_channel_delete_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_channel_delete_abc.py rename to src/gismo_core/abc/events/on_guild_channel_delete_abc.py diff --git a/src/modules_core/abc/events/on_guild_channel_pins_update_abc.py b/src/gismo_core/abc/events/on_guild_channel_pins_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_channel_pins_update_abc.py rename to src/gismo_core/abc/events/on_guild_channel_pins_update_abc.py diff --git a/src/modules_core/abc/events/on_guild_channel_update_abc.py b/src/gismo_core/abc/events/on_guild_channel_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_channel_update_abc.py rename to src/gismo_core/abc/events/on_guild_channel_update_abc.py diff --git a/src/modules_core/abc/events/on_guild_emojis_update_abc.py b/src/gismo_core/abc/events/on_guild_emojis_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_emojis_update_abc.py rename to src/gismo_core/abc/events/on_guild_emojis_update_abc.py diff --git a/src/modules_core/abc/events/on_guild_integrations_update_abc.py b/src/gismo_core/abc/events/on_guild_integrations_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_integrations_update_abc.py rename to src/gismo_core/abc/events/on_guild_integrations_update_abc.py diff --git a/src/modules_core/abc/events/on_guild_join_abc.py b/src/gismo_core/abc/events/on_guild_join_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_join_abc.py rename to src/gismo_core/abc/events/on_guild_join_abc.py diff --git a/src/modules_core/abc/events/on_guild_remove_abc.py b/src/gismo_core/abc/events/on_guild_remove_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_remove_abc.py rename to src/gismo_core/abc/events/on_guild_remove_abc.py diff --git a/src/modules_core/abc/events/on_guild_role_create_abc.py b/src/gismo_core/abc/events/on_guild_role_create_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_role_create_abc.py rename to src/gismo_core/abc/events/on_guild_role_create_abc.py diff --git a/src/modules_core/abc/events/on_guild_role_delete_abc.py b/src/gismo_core/abc/events/on_guild_role_delete_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_role_delete_abc.py rename to src/gismo_core/abc/events/on_guild_role_delete_abc.py diff --git a/src/modules_core/abc/events/on_guild_role_update_abc.py b/src/gismo_core/abc/events/on_guild_role_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_role_update_abc.py rename to src/gismo_core/abc/events/on_guild_role_update_abc.py diff --git a/src/modules_core/abc/events/on_guild_unavailable_abc.py b/src/gismo_core/abc/events/on_guild_unavailable_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_unavailable_abc.py rename to src/gismo_core/abc/events/on_guild_unavailable_abc.py diff --git a/src/modules_core/abc/events/on_guild_update_abc.py b/src/gismo_core/abc/events/on_guild_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_guild_update_abc.py rename to src/gismo_core/abc/events/on_guild_update_abc.py diff --git a/src/modules_core/abc/events/on_invite_create_abc.py b/src/gismo_core/abc/events/on_invite_create_abc.py similarity index 100% rename from src/modules_core/abc/events/on_invite_create_abc.py rename to src/gismo_core/abc/events/on_invite_create_abc.py diff --git a/src/modules_core/abc/events/on_invite_delete_abc.py b/src/gismo_core/abc/events/on_invite_delete_abc.py similarity index 100% rename from src/modules_core/abc/events/on_invite_delete_abc.py rename to src/gismo_core/abc/events/on_invite_delete_abc.py diff --git a/src/modules_core/abc/events/on_member_ban_abc.py b/src/gismo_core/abc/events/on_member_ban_abc.py similarity index 100% rename from src/modules_core/abc/events/on_member_ban_abc.py rename to src/gismo_core/abc/events/on_member_ban_abc.py diff --git a/src/modules_core/abc/events/on_member_join_abc.py b/src/gismo_core/abc/events/on_member_join_abc.py similarity index 100% rename from src/modules_core/abc/events/on_member_join_abc.py rename to src/gismo_core/abc/events/on_member_join_abc.py diff --git a/src/modules_core/abc/events/on_member_remove_abc.py b/src/gismo_core/abc/events/on_member_remove_abc.py similarity index 100% rename from src/modules_core/abc/events/on_member_remove_abc.py rename to src/gismo_core/abc/events/on_member_remove_abc.py diff --git a/src/modules_core/abc/events/on_member_unban_abc.py b/src/gismo_core/abc/events/on_member_unban_abc.py similarity index 100% rename from src/modules_core/abc/events/on_member_unban_abc.py rename to src/gismo_core/abc/events/on_member_unban_abc.py diff --git a/src/modules_core/abc/events/on_member_update_abc.py b/src/gismo_core/abc/events/on_member_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_member_update_abc.py rename to src/gismo_core/abc/events/on_member_update_abc.py diff --git a/src/modules_core/abc/events/on_message_abc.py b/src/gismo_core/abc/events/on_message_abc.py similarity index 100% rename from src/modules_core/abc/events/on_message_abc.py rename to src/gismo_core/abc/events/on_message_abc.py diff --git a/src/modules_core/abc/events/on_message_delete_abc.py b/src/gismo_core/abc/events/on_message_delete_abc.py similarity index 100% rename from src/modules_core/abc/events/on_message_delete_abc.py rename to src/gismo_core/abc/events/on_message_delete_abc.py diff --git a/src/modules_core/abc/events/on_message_edit_abc.py b/src/gismo_core/abc/events/on_message_edit_abc.py similarity index 100% rename from src/modules_core/abc/events/on_message_edit_abc.py rename to src/gismo_core/abc/events/on_message_edit_abc.py diff --git a/src/modules_core/abc/events/on_private_channel_create_abc.py b/src/gismo_core/abc/events/on_private_channel_create_abc.py similarity index 100% rename from src/modules_core/abc/events/on_private_channel_create_abc.py rename to src/gismo_core/abc/events/on_private_channel_create_abc.py diff --git a/src/modules_core/abc/events/on_private_channel_delete_abc.py b/src/gismo_core/abc/events/on_private_channel_delete_abc.py similarity index 100% rename from src/modules_core/abc/events/on_private_channel_delete_abc.py rename to src/gismo_core/abc/events/on_private_channel_delete_abc.py diff --git a/src/modules_core/abc/events/on_private_channel_pins_update_abc.py b/src/gismo_core/abc/events/on_private_channel_pins_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_private_channel_pins_update_abc.py rename to src/gismo_core/abc/events/on_private_channel_pins_update_abc.py diff --git a/src/modules_core/abc/events/on_private_channel_update_abc.py b/src/gismo_core/abc/events/on_private_channel_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_private_channel_update_abc.py rename to src/gismo_core/abc/events/on_private_channel_update_abc.py diff --git a/src/modules_core/abc/events/on_reaction_add_abc.py b/src/gismo_core/abc/events/on_reaction_add_abc.py similarity index 100% rename from src/modules_core/abc/events/on_reaction_add_abc.py rename to src/gismo_core/abc/events/on_reaction_add_abc.py diff --git a/src/modules_core/abc/events/on_reaction_clear_abc.py b/src/gismo_core/abc/events/on_reaction_clear_abc.py similarity index 100% rename from src/modules_core/abc/events/on_reaction_clear_abc.py rename to src/gismo_core/abc/events/on_reaction_clear_abc.py diff --git a/src/modules_core/abc/events/on_reaction_clear_emoji_abc.py b/src/gismo_core/abc/events/on_reaction_clear_emoji_abc.py similarity index 100% rename from src/modules_core/abc/events/on_reaction_clear_emoji_abc.py rename to src/gismo_core/abc/events/on_reaction_clear_emoji_abc.py diff --git a/src/modules_core/abc/events/on_reaction_remove_abc.py b/src/gismo_core/abc/events/on_reaction_remove_abc.py similarity index 100% rename from src/modules_core/abc/events/on_reaction_remove_abc.py rename to src/gismo_core/abc/events/on_reaction_remove_abc.py diff --git a/src/modules_core/abc/events/on_ready_abc.py b/src/gismo_core/abc/events/on_ready_abc.py similarity index 100% rename from src/modules_core/abc/events/on_ready_abc.py rename to src/gismo_core/abc/events/on_ready_abc.py diff --git a/src/modules_core/abc/events/on_relationship_add_abc.py b/src/gismo_core/abc/events/on_relationship_add_abc.py similarity index 100% rename from src/modules_core/abc/events/on_relationship_add_abc.py rename to src/gismo_core/abc/events/on_relationship_add_abc.py diff --git a/src/modules_core/abc/events/on_relationship_remove_abc.py b/src/gismo_core/abc/events/on_relationship_remove_abc.py similarity index 100% rename from src/modules_core/abc/events/on_relationship_remove_abc.py rename to src/gismo_core/abc/events/on_relationship_remove_abc.py diff --git a/src/modules_core/abc/events/on_relationship_update_abc.py b/src/gismo_core/abc/events/on_relationship_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_relationship_update_abc.py rename to src/gismo_core/abc/events/on_relationship_update_abc.py diff --git a/src/modules_core/abc/events/on_resume_abc.py b/src/gismo_core/abc/events/on_resume_abc.py similarity index 100% rename from src/modules_core/abc/events/on_resume_abc.py rename to src/gismo_core/abc/events/on_resume_abc.py diff --git a/src/modules_core/abc/events/on_typing_abc.py b/src/gismo_core/abc/events/on_typing_abc.py similarity index 100% rename from src/modules_core/abc/events/on_typing_abc.py rename to src/gismo_core/abc/events/on_typing_abc.py diff --git a/src/modules_core/abc/events/on_user_update_abc.py b/src/gismo_core/abc/events/on_user_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_user_update_abc.py rename to src/gismo_core/abc/events/on_user_update_abc.py diff --git a/src/modules_core/abc/events/on_voice_state_update_abc.py b/src/gismo_core/abc/events/on_voice_state_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_voice_state_update_abc.py rename to src/gismo_core/abc/events/on_voice_state_update_abc.py diff --git a/src/modules_core/abc/events/on_webhooks_update_abc.py b/src/gismo_core/abc/events/on_webhooks_update_abc.py similarity index 100% rename from src/modules_core/abc/events/on_webhooks_update_abc.py rename to src/gismo_core/abc/events/on_webhooks_update_abc.py diff --git a/src/modules_core/abc/module_abc.py b/src/gismo_core/abc/module_abc.py similarity index 100% rename from src/modules_core/abc/module_abc.py rename to src/gismo_core/abc/module_abc.py diff --git a/src/modules_core/abc/module_service_abc.py b/src/gismo_core/abc/module_service_abc.py similarity index 100% rename from src/modules_core/abc/module_service_abc.py rename to src/gismo_core/abc/module_service_abc.py diff --git a/src/gismo_core/service/bot_service.py b/src/gismo_core/service/bot_service.py index 2e8fa95..b7c124a 100644 --- a/src/gismo_core/service/bot_service.py +++ b/src/gismo_core/service/bot_service.py @@ -8,8 +8,8 @@ from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.configuration.bot_settings import BotSettings from gismo_core.configuration.discord_settings import DiscordSettings from gismo_core.configuration.server_settings import ServerSettings -from modules_core.abc.module_service_abc import ModuleServiceABC -from modules_core.service.module_service import ModuleService +from gismo_core.abc.module_service_abc import ModuleServiceABC +from gismo_core.service.module_service import ModuleService class BotService(BotServiceABC, commands.Bot): diff --git a/src/modules_core/service/module_service.py b/src/gismo_core/service/module_service.py similarity index 80% rename from src/modules_core/service/module_service.py rename to src/gismo_core/service/module_service.py index ead37c5..4934932 100644 --- a/src/modules_core/service/module_service.py +++ b/src/gismo_core/service/module_service.py @@ -11,54 +11,54 @@ from cpl_core.logging import LoggerABC from cpl_core.utils import String from cpl_query.extension import List from discord.ext import commands -from modules_core.abc.events.on_bulk_message_delete_abc import OnBulkMessageDeleteABC -from modules_core.abc.events.on_connect_abc import OnConnectABC -from modules_core.abc.events.on_disconnect_abc import OnDisconnectABC -from modules_core.abc.events.on_group_join_abc import OnGroupJoinABC -from modules_core.abc.events.on_group_remove_abc import OnGroupRemoveABC -from modules_core.abc.events.on_guild_available_abc import OnGuildAvailableABC -from modules_core.abc.events.on_guild_channel_create_abc import OnGuildChannelCreateABC -from modules_core.abc.events.on_guild_channel_delete_abc import OnGuildChannelDeleteABC -from modules_core.abc.events.on_guild_channel_pins_update_abc import OnGuildChannelPinsUpdateABC -from modules_core.abc.events.on_guild_channel_update_abc import OnGuildChannelUpdateABC -from modules_core.abc.events.on_guild_emojis_update_abc import OnGuildEmojisUpdateABC -from modules_core.abc.events.on_guild_integrations_update_abc import OnGuildIntegrationsUpdateABC -from modules_core.abc.events.on_guild_join_abc import OnGuildJoinABC -from modules_core.abc.events.on_guild_remove_abc import OnGuildRemoveABC -from modules_core.abc.events.on_guild_role_create_abc import OnGuildRoleCreateABC -from modules_core.abc.events.on_guild_role_delete_abc import OnGuildRoleDeleteABC -from modules_core.abc.events.on_guild_role_update_abc import OnGuildRoleUpdateABC -from modules_core.abc.events.on_guild_unavailable_abc import OnGuildUnavailableABC -from modules_core.abc.events.on_guild_update_abc import OnGuildUpdateABC -from modules_core.abc.events.on_invite_create_abc import OnInviteCreateABC -from modules_core.abc.events.on_invite_delete_abc import OnInviteDeleteABC -from modules_core.abc.events.on_member_ban_abc import OnMemberBanABC -from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC -from modules_core.abc.events.on_member_remove_abc import OnMemberRemoveABC -from modules_core.abc.events.on_member_unban_abc import OnMemberUnbanABC -from modules_core.abc.events.on_member_update_abc import OnMemberUpdateABC -from modules_core.abc.events.on_message_abc import OnMessageABC -from modules_core.abc.events.on_message_delete_abc import OnMessageDeleteABC -from modules_core.abc.events.on_message_edit_abc import OnMessageEditABC -from modules_core.abc.events.on_private_channel_create_abc import OnPrivateChannelCreateABC -from modules_core.abc.events.on_private_channel_delete_abc import OnPrivateChannelDeleteABC -from modules_core.abc.events.on_private_channel_pins_update_abc import OnPrivateChannelPinsUpdateABC -from modules_core.abc.events.on_private_channel_update_abc import OnPrivateChannelUpdateABC -from modules_core.abc.events.on_reaction_add_abc import OnReactionAddABC -from modules_core.abc.events.on_reaction_clear_abc import OnReactionClearABC -from modules_core.abc.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC -from modules_core.abc.events.on_reaction_remove_abc import OnReactionRemoveABC -from modules_core.abc.events.on_ready_abc import OnReadyABC -from modules_core.abc.events.on_relationship_add_abc import OnRelationshipAddABC -from modules_core.abc.events.on_relationship_remove_abc import OnRelationshipRemoveABC -from modules_core.abc.events.on_relationship_update_abc import OnRelationshipUpdateABC -from modules_core.abc.events.on_resume_abc import OnResumeABC -from modules_core.abc.events.on_typing_abc import OnTypingABC -from modules_core.abc.events.on_user_update_abc import OnUserUpdateABC -from modules_core.abc.events.on_voice_state_update_abc import OnVoiceStateUpdateABC -from modules_core.abc.events.on_webhooks_update_abc import OnWebhooksUpdateABC -from modules_core.abc.module_abc import ModuleABC -from modules_core.abc.module_service_abc import ModuleServiceABC +from gismo_core.abc.events.on_bulk_message_delete_abc import OnBulkMessageDeleteABC +from gismo_core.abc.events.on_connect_abc import OnConnectABC +from gismo_core.abc.events.on_disconnect_abc import OnDisconnectABC +from gismo_core.abc.events.on_group_join_abc import OnGroupJoinABC +from gismo_core.abc.events.on_group_remove_abc import OnGroupRemoveABC +from gismo_core.abc.events.on_guild_available_abc import OnGuildAvailableABC +from gismo_core.abc.events.on_guild_channel_create_abc import OnGuildChannelCreateABC +from gismo_core.abc.events.on_guild_channel_delete_abc import OnGuildChannelDeleteABC +from gismo_core.abc.events.on_guild_channel_pins_update_abc import OnGuildChannelPinsUpdateABC +from gismo_core.abc.events.on_guild_channel_update_abc import OnGuildChannelUpdateABC +from gismo_core.abc.events.on_guild_emojis_update_abc import OnGuildEmojisUpdateABC +from gismo_core.abc.events.on_guild_integrations_update_abc import OnGuildIntegrationsUpdateABC +from gismo_core.abc.events.on_guild_join_abc import OnGuildJoinABC +from gismo_core.abc.events.on_guild_remove_abc import OnGuildRemoveABC +from gismo_core.abc.events.on_guild_role_create_abc import OnGuildRoleCreateABC +from gismo_core.abc.events.on_guild_role_delete_abc import OnGuildRoleDeleteABC +from gismo_core.abc.events.on_guild_role_update_abc import OnGuildRoleUpdateABC +from gismo_core.abc.events.on_guild_unavailable_abc import OnGuildUnavailableABC +from gismo_core.abc.events.on_guild_update_abc import OnGuildUpdateABC +from gismo_core.abc.events.on_invite_create_abc import OnInviteCreateABC +from gismo_core.abc.events.on_invite_delete_abc import OnInviteDeleteABC +from gismo_core.abc.events.on_member_ban_abc import OnMemberBanABC +from gismo_core.abc.events.on_member_join_abc import OnMemberJoinABC +from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC +from gismo_core.abc.events.on_member_unban_abc import OnMemberUnbanABC +from gismo_core.abc.events.on_member_update_abc import OnMemberUpdateABC +from gismo_core.abc.events.on_message_abc import OnMessageABC +from gismo_core.abc.events.on_message_delete_abc import OnMessageDeleteABC +from gismo_core.abc.events.on_message_edit_abc import OnMessageEditABC +from gismo_core.abc.events.on_private_channel_create_abc import OnPrivateChannelCreateABC +from gismo_core.abc.events.on_private_channel_delete_abc import OnPrivateChannelDeleteABC +from gismo_core.abc.events.on_private_channel_pins_update_abc import OnPrivateChannelPinsUpdateABC +from gismo_core.abc.events.on_private_channel_update_abc import OnPrivateChannelUpdateABC +from gismo_core.abc.events.on_reaction_add_abc import OnReactionAddABC +from gismo_core.abc.events.on_reaction_clear_abc import OnReactionClearABC +from gismo_core.abc.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC +from gismo_core.abc.events.on_reaction_remove_abc import OnReactionRemoveABC +from gismo_core.abc.events.on_ready_abc import OnReadyABC +from gismo_core.abc.events.on_relationship_add_abc import OnRelationshipAddABC +from gismo_core.abc.events.on_relationship_remove_abc import OnRelationshipRemoveABC +from gismo_core.abc.events.on_relationship_update_abc import OnRelationshipUpdateABC +from gismo_core.abc.events.on_resume_abc import OnResumeABC +from gismo_core.abc.events.on_typing_abc import OnTypingABC +from gismo_core.abc.events.on_user_update_abc import OnUserUpdateABC +from gismo_core.abc.events.on_voice_state_update_abc import OnVoiceStateUpdateABC +from gismo_core.abc.events.on_webhooks_update_abc import OnWebhooksUpdateABC +from gismo_core.abc.module_abc import ModuleABC +from gismo_core.abc.module_service_abc import ModuleServiceABC class _MetaCogABC(ABCMeta, commands.CogMeta): pass diff --git a/src/modules/base/base.py b/src/modules/base/base.py index a10e745..0f4a1fc 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -21,12 +21,12 @@ from gismo_data.model.user_joined_server import UserJoinedServer from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel from modules.base.base_settings import BaseSettings from modules.permission.abc.permission_service_abc import PermissionServiceABC -from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC -from modules_core.abc.events.on_member_remove_abc import OnMemberRemoveABC -from modules_core.abc.events.on_message_abc import OnMessageABC -from modules_core.abc.events.on_voice_state_update_abc import \ +from gismo_core.abc.events.on_member_join_abc import OnMemberJoinABC +from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC +from gismo_core.abc.events.on_message_abc import OnMessageABC +from gismo_core.abc.events.on_voice_state_update_abc import \ OnVoiceStateUpdateABC -from modules_core.abc.module_abc import ModuleABC +from gismo_core.abc.module_abc import ModuleABC class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceStateUpdateABC): diff --git a/src/modules/boot_log/boot_log.py b/src/modules/boot_log/boot_log.py index d6e0928..90cb559 100644 --- a/src/modules/boot_log/boot_log.py +++ b/src/modules/boot_log/boot_log.py @@ -9,8 +9,8 @@ from gismo_core.abc.bot_service_abc import BotServiceABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.configuration.server_settings import ServerSettings from modules.boot_log.boot_log_settings import BootLogSettings -from modules_core.abc.events.on_ready_abc import OnReadyABC -from modules_core.abc.module_abc import ModuleABC +from gismo_core.abc.events.on_ready_abc import OnReadyABC +from gismo_core.abc.module_abc import ModuleABC class BootLog(ModuleABC, OnReadyABC): diff --git a/src/modules/database/database.py b/src/modules/database/database.py index 2c6e226..ad40452 100644 --- a/src/modules/database/database.py +++ b/src/modules/database/database.py @@ -21,8 +21,8 @@ from gismo_data.model.user import User from gismo_data.model.user_joined_server import UserJoinedServer from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel from gismo_data.service.user_repository_service import ServerRepositoryABC -from modules_core.abc.events.on_ready_abc import OnReadyABC -from modules_core.abc.module_abc import ModuleABC +from gismo_core.abc.events.on_ready_abc import OnReadyABC +from gismo_core.abc.module_abc import ModuleABC class Database(ModuleABC, OnReadyABC): diff --git a/src/modules/permission/permission.py b/src/modules/permission/permission.py index 9a4dcee..d606bc4 100644 --- a/src/modules/permission/permission.py +++ b/src/modules/permission/permission.py @@ -4,9 +4,9 @@ from cpl_core.logging import LoggerABC from modules.permission.abc.permission_service_abc import PermissionServiceABC from modules.permission.configuration.permission_settings import \ PermissionSettings -from modules_core.abc.events.on_member_update_abc import OnMemberUpdateABC -from modules_core.abc.events.on_ready_abc import OnReadyABC -from modules_core.abc.module_abc import ModuleABC +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 class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC): diff --git a/src/modules_core/__init__.py b/src/modules_core/__init__.py deleted file mode 100644 index 88a2e59..0000000 --- a/src/modules_core/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -gismo sh-edraft Gismo -~~~~~~~~~~~~~~~~~~~ - -sh-edraft Dicord bot Gismo - -:copyright: (c) 2021 - 2022 sh-edraft.de -:license: MIT, see LICENSE for more details. - -""" - -__title__ = 'modules_core' -__author__ = 'Sven Heidemann' -__license__ = 'MIT' -__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' - -from collections import namedtuple - -# imports - -VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') diff --git a/src/modules_core/abc/__init__.py b/src/modules_core/abc/__init__.py deleted file mode 100644 index 4e57337..0000000 --- a/src/modules_core/abc/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -gismo sh-edraft Gismo -~~~~~~~~~~~~~~~~~~~ - -sh-edraft Dicord bot Gismo - -:copyright: (c) 2021 - 2022 sh-edraft.de -:license: MIT, see LICENSE for more details. - -""" - -__title__ = 'modules_core.abc' -__author__ = 'Sven Heidemann' -__license__ = 'MIT' -__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' - -from collections import namedtuple - -# imports - -VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') diff --git a/src/modules_core/events_enum.py b/src/modules_core/events_enum.py deleted file mode 100644 index fafe57e..0000000 --- a/src/modules_core/events_enum.py +++ /dev/null @@ -1,6 +0,0 @@ -from enum import Enum - - -class EventsEnum(Enum): - - on_ready = 'on_ready' diff --git a/src/modules_core/modules-core.json b/src/modules_core/modules-core.json deleted file mode 100644 index 9324f5f..0000000 --- a/src/modules_core/modules-core.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "ProjectSettings": { - "Name": "modules-core", - "Version": { - "Major": "0", - "Minor": "1", - "Micro": "0" - }, - "Author": "Sven Heidemann", - "AuthorEmail": "sven.heidemann@sh-edraft.de", - "Description": "sh-edraft Gismo - Modules core", - "LongDescription": "sh-edraft Dicord bot Gismo - Modules core", - "URL": "https://www.sh-edraft.de", - "CopyrightDate": "2021 - 2022", - "CopyrightName": "sh-edraft.de", - "LicenseName": "MIT", - "LicenseDescription": "MIT, see LICENSE for more details.", - "Dependencies": [ - "sh_cpl-core>=2021.11.0", - "sh_cpl-query>=2021.11.0" - ], - "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "../../venv/bin/python" - }, - "Classifiers": [] - }, - "BuildSettings": { - "ProjectType": "library", - "SourcePath": "", - "OutputPath": "../../dist", - "Main": "", - "EntryPoint": "", - "IncludePackageData": false, - "Included": [], - "Excluded": [ - "*/__pycache__", - "*/logs", - "*/tests" - ], - "PackageData": {}, - "ProjectReferences": [] - } -} \ No newline at end of file diff --git a/src/modules_core/service/__init__.py b/src/modules_core/service/__init__.py deleted file mode 100644 index bf3e373..0000000 --- a/src/modules_core/service/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -gismo sh-edraft Gismo -~~~~~~~~~~~~~~~~~~~ - -sh-edraft Dicord bot Gismo - -:copyright: (c) 2021 - 2022 sh-edraft.de -:license: MIT, see LICENSE for more details. - -""" - -__title__ = 'modules_core.service' -__author__ = 'Sven Heidemann' -__license__ = 'MIT' -__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de' -__version__ = '0.3.0' - -from collections import namedtuple - -# imports - -VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='0', minor='3', micro='0') -- 2.45.2 From ed2dab6ff8af66f620dc2798911ea98d88941d75 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 31 Dec 2021 11:42:09 +0100 Subject: [PATCH 08/10] Added logic to add commands --- src/gismo/startup.py | 6 ++++- src/gismo_core/abc/command_abc.py | 11 ++++++++ src/gismo_core/commands_meta.py | 5 ++++ src/gismo_core/service/message_service.py | 11 +++++--- src/gismo_core/service/module_service.py | 8 +++--- src/modules/base/base.py | 20 ++++++++------ src/modules/base/service/__init__.py | 1 + .../base/service/base_command_service.py | 27 +++++++++++++++++++ src/modules/boot_log/boot_log.py | 1 + 9 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 src/gismo_core/abc/command_abc.py create mode 100644 src/gismo_core/commands_meta.py create mode 100644 src/modules/base/service/__init__.py create mode 100644 src/modules/base/service/base_command_service.py diff --git a/src/gismo/startup.py b/src/gismo/startup.py index aaf9ba3..491dfae 100644 --- a/src/gismo/startup.py +++ b/src/gismo/startup.py @@ -11,6 +11,7 @@ from cpl_core.environment import ApplicationEnvironment from cpl_core.logging import LoggerABC from gismo_core.abc.bot_service_abc import BotServiceABC +from gismo_core.abc.command_abc import CommandABC from gismo_core.abc.message_service_abc import MessageServiceABC from gismo_core.service.bot_service import BotService from gismo_core.service.message_service import MessageService @@ -35,6 +36,7 @@ from gismo_data.service.user_joined_server_repository_service import UserJoinedS from gismo_data.service.user_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService from gismo_data.service.user_repository_service import UserRepositoryService from modules.base.base import Base +from modules.base.service.base_command_service import BaseCommandService from modules.boot_log.boot_log import BootLog from modules.database.database import Database from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -88,12 +90,14 @@ class Startup(StartupABC): # module services services.add_singleton(PermissionServiceABC, PermissionService) + # commands + services.add_singleton(CommandABC, BaseCommandService) + # modules services.add_transient(ModuleABC, Database) services.add_transient(ModuleABC, BootLog) services.add_singleton(ModuleABC, Permission) services.add_singleton(ModuleABC, Base) - # migrations services.add_transient(MigrationABC, InitialMigration) diff --git a/src/gismo_core/abc/command_abc.py b/src/gismo_core/abc/command_abc.py new file mode 100644 index 0000000..350f501 --- /dev/null +++ b/src/gismo_core/abc/command_abc.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod + +from discord.ext import commands + +from gismo_core.commands_meta import CommandsMeta + + +class CommandABC(ABC, commands.Cog, metaclass=CommandsMeta): + + @abstractmethod + def __init__(self): pass diff --git a/src/gismo_core/commands_meta.py b/src/gismo_core/commands_meta.py new file mode 100644 index 0000000..8b66f16 --- /dev/null +++ b/src/gismo_core/commands_meta.py @@ -0,0 +1,5 @@ +from abc import ABCMeta +from discord.ext import commands + + +class CommandsMeta(ABCMeta, commands.CogMeta): pass diff --git a/src/gismo_core/service/message_service.py b/src/gismo_core/service/message_service.py index b86a712..d31a733 100644 --- a/src/gismo_core/service/message_service.py +++ b/src/gismo_core/service/message_service.py @@ -26,12 +26,15 @@ class MessageService(MessageServiceABC): async def delete_messages(self, messages: List[discord.Message]): self._logger.debug(__name__, f'Try to delete {messages.count()} messages') for message in messages: - await self.delete_message(message) + server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{message.guild.id}') + await asyncio.sleep(server_st.message_delete_timer) + await self.delete_message(message, mass_delete=True) self._logger.debug(__name__, 'Deleting messages finished') - async def delete_message(self, message: discord.Message): + async def delete_message(self, message: discord.Message, mass_delete=False): server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{message.guild.id}') - await asyncio.sleep(server_st.message_delete_timer) + if not mass_delete: + await asyncio.sleep(server_st.message_delete_timer) self._logger.debug(__name__, f'Try to delete message:\n\t{message}\n\t{message.content}') guild_id = message.guild.id try: @@ -86,4 +89,4 @@ class MessageService(MessageServiceABC): self._logger.info(__name__, f'Sent message to channel {ctx.channel.id}') self._clients.apppend_sent_message_count(self._bot.user.id, ctx.guild.id, 1) self._db.save_changes() - await self.delete_message(msg) + await self.delete_messages(List(discord.Message, [msg, ctx.message])) diff --git a/src/gismo_core/service/module_service.py b/src/gismo_core/service/module_service.py index 4934932..cb870df 100644 --- a/src/gismo_core/service/module_service.py +++ b/src/gismo_core/service/module_service.py @@ -59,12 +59,10 @@ from gismo_core.abc.events.on_voice_state_update_abc import OnVoiceStateUpdateAB from gismo_core.abc.events.on_webhooks_update_abc import OnWebhooksUpdateABC from gismo_core.abc.module_abc import ModuleABC from gismo_core.abc.module_service_abc import ModuleServiceABC +from gismo_core.commands_meta import CommandsMeta -class _MetaCogABC(ABCMeta, commands.CogMeta): pass - - -class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): +class ModuleService(ModuleServiceABC, commands.Cog, metaclass=CommandsMeta): def __init__(self, logger: LoggerABC, config: ConfigurationABC, services: ServiceProviderABC, env: ApplicationEnvironmentABC): self._logger = logger @@ -90,7 +88,7 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC): settings: ConfigurationModelABC = module.settings_type() settings.from_dict(json_cfg[id]) self._config.add_configuration(f'{type(module).__name__}_{id}', settings) - self._logger.info(__name__, f'Added config: {type(module).__name__}_{id}') + self._logger.debug(__name__, f'Added config: {type(module).__name__}_{id}') modules.append(module) diff --git a/src/modules/base/base.py b/src/modules/base/base.py index 0f4a1fc..9666eb9 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -16,10 +16,12 @@ from gismo_data.abc.user_joined_server_repository_abc import \ from gismo_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC from gismo_data.abc.user_repository_abc import UserRepositoryABC from gismo_data.model.known_user import KnownUser +from gismo_data.model.server import Server from gismo_data.model.user import User from gismo_data.model.user_joined_server import UserJoinedServer from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel from modules.base.base_settings import BaseSettings +from modules.base.service.base_command_service import BaseCommandService from modules.permission.abc.permission_service_abc import PermissionServiceABC from gismo_core.abc.events.on_member_join_abc import OnMemberJoinABC from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC @@ -44,7 +46,8 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS bot: BotServiceABC, db: DatabaseContextABC, messenger: MessageServiceABC, - permission_service: PermissionServiceABC + permission_service: PermissionServiceABC, + base_command_service: BaseCommandService ): self._config = config self._logger = logger @@ -69,6 +72,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS }, BaseSettings ) + self._bot.add_cog(base_command_service) self._logger.info(__name__, f'Module {type(self)} loaded') def _get_config(self, g_id: int) -> BaseSettings: @@ -103,7 +107,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS async def _add_if_not_exists_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Check if user exists {member}') - settings: BaseSettings = self._get_config() + settings: BaseSettings = self._get_config(member.guild.id) await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member) for admin in self._permission_service.get_admins(): @@ -131,7 +135,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS async def _remove_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Remove user {member}') - settings: BaseSettings = self._get_config() + settings: BaseSettings = self._get_config(member.guild.id) await self._messenger.send_dm_message(settings.goodbye_message, member) try: @@ -149,10 +153,10 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS except Exception as e: self._logger.error(__name__, f'Cannot get user {member.id}', e) - def _update_voice_state(self, joined: bool, dc_user_id: int, dc_channel_id: int, srv_id: int): + def _update_voice_state(self, joined: bool, dc_user_id: int, dc_channel_id: int, server: Server): user: User = None try: - user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, srv_id) + user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id) except Exception as e: self._logger.error(__name__, f'Cannot get user {dc_user_id}', e) return @@ -168,7 +172,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._db.save_changes() return - settings: BaseSettings = self._get_config() + settings: BaseSettings = self._get_config(server.discord_server_id) join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.user_id) join.leaved_on = datetime.now() @@ -205,7 +209,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._logger.error(__name__, f'User not found {dc_user_id}') return - settings: BaseSettings = self._get_config() + settings: BaseSettings = self._get_config(message.guild.id) old_xp = user.xp user.xp += settings._xp_per_message self._users.update_user(user) @@ -235,7 +239,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS self._logger.debug(__name__, f'Module {type(self)} started') self._logger.trace(__name__, f'Detected on_voice_state_update {member.id} from {before} to {after}') u: discord.User = member - settings: BaseSettings = self._get_config() + settings: BaseSettings = self._get_config(member.guild.id) server = self._servers.get_server_by_discord_id(member.guild.id) try: diff --git a/src/modules/base/service/__init__.py b/src/modules/base/service/__init__.py new file mode 100644 index 0000000..425ab6c --- /dev/null +++ b/src/modules/base/service/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/modules/base/service/base_command_service.py b/src/modules/base/service/base_command_service.py new file mode 100644 index 0000000..9ea4ee4 --- /dev/null +++ b/src/modules/base/service/base_command_service.py @@ -0,0 +1,27 @@ +import discord +from discord.ext import commands +from discord.ext.commands import Context + +from cpl_core.logging import LoggerABC +from gismo_core.abc.command_abc import CommandABC +from gismo_core.abc.message_service_abc import MessageServiceABC + + +class BaseCommandService(CommandABC): + + def __init__( + self, + logger: LoggerABC, + message_service: MessageServiceABC + ): + CommandABC.__init__(self) + + self._logger = logger + self._message_service = message_service + + self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') + + @commands.command() + async def ping(self, ctx: Context): + self._logger.debug(__name__, f'Received command ping {ctx}') + await self._message_service.send_ctx_msg(ctx, 'Pong') diff --git a/src/modules/boot_log/boot_log.py b/src/modules/boot_log/boot_log.py index 90cb559..3d0044c 100644 --- a/src/modules/boot_log/boot_log.py +++ b/src/modules/boot_log/boot_log.py @@ -79,5 +79,6 @@ class BootLog(ModuleABC, OnReadyABC): ), module_settings.login_message.format(init_time) ) + self._logger.info(__name__, 'Bot is ready') self._logger.trace(__name__, f'Module {type(self)} stopped') -- 2.45.2 From ab44aa55bcc17cc86ebc2c721a5adb635119e1c1 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 31 Dec 2021 11:52:37 +0100 Subject: [PATCH 09/10] Added purge command --- src/gismo/config/base.json | 3 ++- src/modules/base/base_settings.py | 6 ++++++ .../base/service/base_command_service.py | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/gismo/config/base.json b/src/gismo/config/base.json index dbf85b8..99a41c8 100644 --- a/src/gismo/config/base.json +++ b/src/gismo/config/base.json @@ -9,6 +9,7 @@ "AFKChannelIds": [ 910199452915093593, 910199452915093594 - ] + ], + "PurgeMessage": "Ja mein Herr, ich lösche alle Nachrichten!" } } \ No newline at end of file diff --git a/src/modules/base/base_settings.py b/src/modules/base/base_settings.py index 7afd1c0..4598b3b 100644 --- a/src/modules/base/base_settings.py +++ b/src/modules/base/base_settings.py @@ -16,6 +16,7 @@ class BaseSettings(ConfigurationModelABC): self._xp_per_message: int = 0 self._xp_per_ontime_hour: int = 0 self._afk_channel_ids: list[int] = [] + self._purge_message: str = '' @property def welcome_message(self) -> str: @@ -45,6 +46,10 @@ class BaseSettings(ConfigurationModelABC): def afk_channel_ids(self) -> list[int]: return self._afk_channel_ids + @property + def purge_message(self) -> str: + return self._purge_message + def from_dict(self, settings: dict): try: self._welcome_message = settings['WelcomeMessage'] @@ -55,6 +60,7 @@ class BaseSettings(ConfigurationModelABC): self._xp_per_ontime_hour = int(settings['XpPerOntimeHour']) for id in settings['AFKChannelIds']: self._afk_channel_ids.append(int(id)) + self._purge_message = settings['PurgeMessage'] 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 9ea4ee4..b20dbf7 100644 --- a/src/modules/base/service/base_command_service.py +++ b/src/modules/base/service/base_command_service.py @@ -1,10 +1,15 @@ +import asyncio import discord from discord.ext import commands from discord.ext.commands import Context from cpl_core.logging import LoggerABC +from cpl_core.configuration import ConfigurationABC + 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 class BaseCommandService(CommandABC): @@ -12,11 +17,13 @@ class BaseCommandService(CommandABC): def __init__( self, logger: LoggerABC, + config: ConfigurationABC, message_service: MessageServiceABC ): CommandABC.__init__(self) self._logger = logger + self._config = config self._message_service = message_service self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') @@ -25,3 +32,15 @@ class BaseCommandService(CommandABC): async def ping(self, ctx: Context): self._logger.debug(__name__, f'Received command ping {ctx}') await self._message_service.send_ctx_msg(ctx, 'Pong') + self._logger.trace(__name__, f'Finished ping command') + + @commands.command() + async def purge(self, ctx: Context): + self._logger.debug(__name__, f'Received command purge {ctx}') + settings: BaseSettings = self._config.get_configuration(f'Base_{ctx.guild.id}') + server_settings: ServerSettings = self._config.get_configuration(f'DSERVER_{ctx.guild.id}') + + await self._message_service.send_ctx_msg(ctx, settings.purge_message) + await asyncio.sleep(server_settings.message_delete_timer) + await ctx.channel.purge() + self._logger.trace(__name__, f'Finished purge command') -- 2.45.2 From bed3f07347be093e01712084bc7f6350e10b4ed3 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 31 Dec 2021 12:05:10 +0100 Subject: [PATCH 10/10] Added permission check to command --- src/gismo/config/base.json | 3 ++- src/modules/base/base_settings.py | 6 ++++++ src/modules/base/service/base_command_service.py | 10 +++++++++- src/modules/permission/abc/permission_service_abc.py | 6 ++++++ src/modules/permission/service/permission_service.py | 7 +++++++ 5 files changed, 30 insertions(+), 2 deletions(-) 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) + -- 2.45.2