Fixed module loading & added config
This commit is contained in:
parent
ca7798987c
commit
9eef94baf2
@ -1 +1 @@
|
|||||||
Subproject commit 370e96c5b19290d8d229fd71febbaf5ca51544ae
|
Subproject commit 3d4e93d4d658e1c6c571756f99a3297efb8a7d64
|
@ -1,23 +1,22 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from cpl_core.configuration import ConfigurationModelABC
|
|
||||||
|
|
||||||
class ModuleABC(ABC):
|
class ModuleABC(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
@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._priorities = priorities
|
||||||
self._success = True
|
self._success = True
|
||||||
self._settings_type = settings_type
|
self._settings_types = settings_types
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return self._success
|
return self._success
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def settings_type(self) -> type:
|
def settings_types(self) -> list[type]:
|
||||||
return self._settings_type
|
return self._settings_types
|
||||||
|
|
||||||
def get_priority(self, t: type) -> int:
|
def get_priority(self, t: type) -> int:
|
||||||
if t not in self._priorities:
|
if t not in self._priorities:
|
||||||
|
@ -80,15 +80,18 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=CommandsMeta):
|
|||||||
if module is None:
|
if module is None:
|
||||||
self._logger.warn(__name__, f'Module {module_type} not found in services!')
|
self._logger.warn(__name__, f'Module {module_type} not found in services!')
|
||||||
break
|
break
|
||||||
|
|
||||||
if module.settings_type is not None:
|
if len(module.settings_types) > 0:
|
||||||
with open(f'config/{String.convert_to_snake_case(type(module).__name__).lower()}.json', encoding='utf-8') as cfg:
|
for settings_type in module.settings_types:
|
||||||
json_cfg = json.load(cfg)
|
settings_name = settings_type.__name__.split('Settings')[0]
|
||||||
for index in json_cfg:
|
|
||||||
settings: ConfigurationModelABC = module.settings_type()
|
with open(f'config/{String.convert_to_snake_case(settings_name).lower()}.json', encoding='utf-8') as cfg:
|
||||||
settings.from_dict(json_cfg[index])
|
json_cfg = json.load(cfg)
|
||||||
self._config.add_configuration(f'{type(module).__name__}_{index}', settings)
|
for index in json_cfg:
|
||||||
self._logger.debug(__name__, f'Added config: {type(module).__name__}_{index}')
|
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)
|
modules.append(module)
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
|
|||||||
OnMessageABC: 30,
|
OnMessageABC: 30,
|
||||||
OnVoiceStateUpdateABC: 10
|
OnVoiceStateUpdateABC: 10
|
||||||
},
|
},
|
||||||
BaseSettings
|
[BaseSettings]
|
||||||
)
|
)
|
||||||
self._bot.add_cog(base_command_service)
|
self._bot.add_cog(base_command_service)
|
||||||
self._logger.info(__name__, f'Module {type(self)} loaded')
|
self._logger.info(__name__, f'Module {type(self)} loaded')
|
||||||
|
@ -33,7 +33,7 @@ class BootLog(ModuleABC, OnReadyABC):
|
|||||||
{
|
{
|
||||||
OnReadyABC: 10
|
OnReadyABC: 10
|
||||||
},
|
},
|
||||||
BootLogSettings
|
[BootLogSettings]
|
||||||
)
|
)
|
||||||
self._logger.info(__name__, f'Module {type(self)} loaded')
|
self._logger.info(__name__, f'Module {type(self)} loaded')
|
||||||
|
|
||||||
|
@ -3,11 +3,11 @@ from datetime import datetime
|
|||||||
|
|
||||||
import discord
|
import discord
|
||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.database import DatabaseSettings
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
from cpl_core.logging import LoggerABC
|
from cpl_core.logging import LoggerABC
|
||||||
|
|
||||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
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.client_repository_abc import ClientRepositoryABC
|
||||||
from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||||
from gismo_data.abc.user_joined_server_repository_abc import \
|
from gismo_data.abc.user_joined_server_repository_abc import \
|
||||||
@ -56,7 +56,7 @@ class Database(ModuleABC, OnReadyABC):
|
|||||||
ModuleABC.__init__(
|
ModuleABC.__init__(
|
||||||
self,
|
self,
|
||||||
{OnReadyABC: 0},
|
{OnReadyABC: 0},
|
||||||
None
|
[DatabaseSettings, BaseSettings]
|
||||||
)
|
)
|
||||||
self._logger.info(__name__, f'Module {type(self)} loaded')
|
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}')
|
self._logger.warn(__name__, f'Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}')
|
||||||
join.leaved_on = datetime.now()
|
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:
|
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)
|
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__(
|
ModuleABC.__init__(
|
||||||
self,
|
self,
|
||||||
{OnReadyABC: 1, OnMemberUpdateABC: 0},
|
{OnReadyABC: 1, OnMemberUpdateABC: 0},
|
||||||
PermissionSettings
|
[PermissionSettings]
|
||||||
)
|
)
|
||||||
self._logger.info(__name__, f'Module {type(self)} loaded')
|
self._logger.info(__name__, f'Module {type(self)} loaded')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user