diff --git a/src/gismo/config b/src/gismo/config index 370e96c..3d4e93d 160000 --- a/src/gismo/config +++ b/src/gismo/config @@ -1 +1 @@ -Subproject commit 370e96c5b19290d8d229fd71febbaf5ca51544ae +Subproject commit 3d4e93d4d658e1c6c571756f99a3297efb8a7d64 diff --git a/src/gismo_core/abc/module_abc.py b/src/gismo_core/abc/module_abc.py index 49d7af0..8f7589f 100644 --- a/src/gismo_core/abc/module_abc.py +++ b/src/gismo_core/abc/module_abc.py @@ -1,23 +1,22 @@ from abc import ABC, abstractmethod from typing import Optional -from cpl_core.configuration import ConfigurationModelABC class ModuleABC(ABC): @abstractmethod - def __init__(self, priorities: dict[type, int], settings_type: Optional[type]): + def __init__(self, priorities: dict[type, int], settings_types: list[Optional[type]]): self._priorities = priorities self._success = True - self._settings_type = settings_type + self._settings_types = settings_types @property def success(self) -> bool: return self._success @property - def settings_type(self) -> type: - return self._settings_type + def settings_types(self) -> list[type]: + return self._settings_types def get_priority(self, t: type) -> int: if t not in self._priorities: diff --git a/src/gismo_core/service/module_service.py b/src/gismo_core/service/module_service.py index aef87ee..20049ba 100644 --- a/src/gismo_core/service/module_service.py +++ b/src/gismo_core/service/module_service.py @@ -80,15 +80,18 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=CommandsMeta): if module is None: self._logger.warn(__name__, f'Module {module_type} not found in services!') break - - 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 index in json_cfg: - settings: ConfigurationModelABC = module.settings_type() - settings.from_dict(json_cfg[index]) - self._config.add_configuration(f'{type(module).__name__}_{index}', settings) - self._logger.debug(__name__, f'Added config: {type(module).__name__}_{index}') + + if len(module.settings_types) > 0: + for settings_type in module.settings_types: + settings_name = settings_type.__name__.split('Settings')[0] + + with open(f'config/{String.convert_to_snake_case(settings_name).lower()}.json', encoding='utf-8') as cfg: + json_cfg = json.load(cfg) + for index in json_cfg: + settings: ConfigurationModelABC = settings_type() + settings.from_dict(json_cfg[index]) + self._config.add_configuration(f'{type(module).__name__}_{index}', settings) + self._logger.debug(__name__, f'Added config: {type(module).__name__}_{index}') modules.append(module) diff --git a/src/modules/base/base.py b/src/modules/base/base.py index 1d851bc..b323a47 100644 --- a/src/modules/base/base.py +++ b/src/modules/base/base.py @@ -70,7 +70,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS OnMessageABC: 30, OnVoiceStateUpdateABC: 10 }, - BaseSettings + [BaseSettings] ) self._bot.add_cog(base_command_service) self._logger.info(__name__, f'Module {type(self)} loaded') diff --git a/src/modules/boot_log/boot_log.py b/src/modules/boot_log/boot_log.py index 0b03ffd..00732da 100644 --- a/src/modules/boot_log/boot_log.py +++ b/src/modules/boot_log/boot_log.py @@ -33,7 +33,7 @@ class BootLog(ModuleABC, OnReadyABC): { OnReadyABC: 10 }, - BootLogSettings + [BootLogSettings] ) self._logger.info(__name__, f'Module {type(self)} loaded') diff --git a/src/modules/database/database.py b/src/modules/database/database.py index 0fd7daf..b3427dd 100644 --- a/src/modules/database/database.py +++ b/src/modules/database/database.py @@ -3,11 +3,11 @@ from datetime import datetime import discord from cpl_core.configuration import ConfigurationABC +from cpl_core.database import DatabaseSettings 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 \ @@ -56,7 +56,7 @@ class Database(ModuleABC, OnReadyABC): ModuleABC.__init__( self, {OnReadyABC: 0}, - None + [DatabaseSettings, BaseSettings] ) self._logger.info(__name__, f'Module {type(self)} loaded') @@ -274,7 +274,7 @@ class Database(ModuleABC, OnReadyABC): self._logger.warn(__name__, f'Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}') join.leaved_on = datetime.now() - settings: BaseSettings = self._config.get_configuration(f'DSERVER_{guild.id}') + settings: BaseSettings = self._config.get_configuration(f'base_{guild.id}') if ((join.leaved_on - join.joined_on).total_seconds()/60/60) > settings.max_voice_state_hours: join.leaved_on = join.joined_on + datetime.timedelta(hours=settings.max_voice_state_hours) diff --git a/src/modules/permission/permission.py b/src/modules/permission/permission.py index b769fe2..210ae04 100644 --- a/src/modules/permission/permission.py +++ b/src/modules/permission/permission.py @@ -21,7 +21,7 @@ class Permission(ModuleABC, OnReadyABC, OnMemberUpdateABC): ModuleABC.__init__( self, {OnReadyABC: 1, OnMemberUpdateABC: 0}, - PermissionSettings + [PermissionSettings] ) self._logger.info(__name__, f'Module {type(self)} loaded')