Fixed module loading & added config
This commit is contained in:
		 Submodule src/gismo/config updated: 370e96c5b1...3d4e93d4d6
									
								
							| @@ -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: | ||||
|   | ||||
| @@ -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) | ||||
|          | ||||
|   | ||||
| @@ -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') | ||||
|   | ||||
| @@ -33,7 +33,7 @@ class BootLog(ModuleABC, OnReadyABC): | ||||
|             { | ||||
|                 OnReadyABC: 10 | ||||
|             }, | ||||
|             BootLogSettings | ||||
|             [BootLogSettings] | ||||
|         ) | ||||
|         self._logger.info(__name__, f'Module {type(self)} loaded') | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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') | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user