Fixed config loading #1.1.0.rc1
This commit is contained in:
parent
1f47636e8d
commit
456d939b47
@ -1,29 +1,45 @@
|
|||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
|
|
||||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||||
from bot_data.model.server import Server
|
from bot_data.model.server import Server
|
||||||
from bot_data.model.technician_config import TechnicianConfig
|
from bot_data.model.technician_config import TechnicianConfig
|
||||||
|
from bot_data.service.server_config_seeder import ServerConfigSeeder
|
||||||
|
from bot_data.service.technician_config_seeder import TechnicianConfigSeeder
|
||||||
|
|
||||||
|
|
||||||
class ConfigService:
|
class ConfigService:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config: ConfigurationABC,
|
config: ConfigurationABC,
|
||||||
|
services: ServiceProviderABC,
|
||||||
technician_config_repo: TechnicianConfigRepositoryABC,
|
technician_config_repo: TechnicianConfigRepositoryABC,
|
||||||
server_config_repo: ServerConfigRepositoryABC,
|
server_config_repo: ServerConfigRepositoryABC,
|
||||||
|
tech_seeder: TechnicianConfigSeeder,
|
||||||
|
server_seeder: ServerConfigSeeder,
|
||||||
):
|
):
|
||||||
self._config = config
|
self._config = config
|
||||||
|
self._services = services
|
||||||
self._technician_config_repo = technician_config_repo
|
self._technician_config_repo = technician_config_repo
|
||||||
self._server_config_repo = server_config_repo
|
self._server_config_repo = server_config_repo
|
||||||
|
|
||||||
def reload_technician_config(self):
|
self._tech_seeder = tech_seeder
|
||||||
|
self._server_seeder = server_seeder
|
||||||
|
|
||||||
|
async def reload_technician_config(self):
|
||||||
|
if not self._technician_config_repo.does_technician_config_exists():
|
||||||
|
await self._tech_seeder.seed()
|
||||||
|
|
||||||
technician_config = self._technician_config_repo.get_technician_config()
|
technician_config = self._technician_config_repo.get_technician_config()
|
||||||
self._config.add_configuration(TechnicianConfig, technician_config)
|
self._config.add_configuration(TechnicianConfig, technician_config)
|
||||||
self._config.add_configuration(FeatureFlagsSettings, FeatureFlagsSettings(**technician_config.feature_flags))
|
self._config.add_configuration(FeatureFlagsSettings, FeatureFlagsSettings(**technician_config.feature_flags))
|
||||||
|
|
||||||
def reload_server_config(self, server: Server):
|
async def reload_server_config(self, server: Server):
|
||||||
|
if not self._server_config_repo.does_server_config_exists(server.id):
|
||||||
|
await self._server_seeder.seed()
|
||||||
|
|
||||||
server_config = self._server_config_repo.get_server_config_by_server(server.id)
|
server_config = self._server_config_repo.get_server_config_by_server(server.id)
|
||||||
self._config.add_configuration(
|
self._config.add_configuration(
|
||||||
f"{type(server_config).__name__}_{server_config.server.discord_id}", server_config
|
f"{type(server_config).__name__}_{server_config.server.discord_id}", server_config
|
||||||
|
@ -74,14 +74,14 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def does_server_config_exists(self, server_id: int) -> bool:
|
def does_server_config_exists(self, server_id: int) -> bool:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_id_string(server_id)}")
|
self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_server_id_string(server_id)}")
|
||||||
result = self._context.select(ServerConfig.get_select_by_id_string(server_id))
|
result = self._context.select(ServerConfig.get_select_by_server_id_string(server_id))
|
||||||
|
|
||||||
return len(result) > 0
|
return len(result) > 0
|
||||||
|
|
||||||
def get_server_config_by_server(self, server_id: int) -> ServerConfig:
|
def get_server_config_by_server(self, server_id: int) -> ServerConfig:
|
||||||
self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_id_string(server_id)}")
|
self._logger.trace(__name__, f"Send SQL command: {ServerConfig.get_select_by_server_id_string(server_id)}")
|
||||||
result = self._context.select(ServerConfig.get_select_by_id_string(server_id))[0]
|
result = self._context.select(ServerConfig.get_select_by_server_id_string(server_id))[0]
|
||||||
|
|
||||||
return self._from_result(result)
|
return self._from_result(result)
|
||||||
|
|
||||||
|
@ -174,5 +174,5 @@ class ServerConfigMutation(QueryABC):
|
|||||||
|
|
||||||
self._server_configs.add_server_team_role_id_config(role_id)
|
self._server_configs.add_server_team_role_id_config(role_id)
|
||||||
|
|
||||||
self._config_service.reload_server_config(new_config.server)
|
self._bot.loop.create_task(self._config_service.reload_server_config(new_config.server))
|
||||||
self._permissions.on_ready()
|
self._permissions.on_ready()
|
||||||
|
@ -113,5 +113,5 @@ class TechnicianConfigMutation(QueryABC):
|
|||||||
|
|
||||||
self._technician_configs.add_technician_id_config(TechnicianIdConfig(technician_id))
|
self._technician_configs.add_technician_id_config(TechnicianIdConfig(technician_id))
|
||||||
|
|
||||||
self._config_service.reload_technician_config()
|
self._bot.loop.create_task(self._config_service.reload_technician_config())
|
||||||
self._permissions.on_ready()
|
self._permissions.on_ready()
|
||||||
|
@ -19,4 +19,4 @@ class ConfigExtension(ApplicationExtensionABC):
|
|||||||
logger: LoggerABC = services.get_service(LoggerABC)
|
logger: LoggerABC = services.get_service(LoggerABC)
|
||||||
logger.debug(__name__, "Config extension started")
|
logger.debug(__name__, "Config extension started")
|
||||||
config: ConfigService = services.get_service(ConfigService)
|
config: ConfigService = services.get_service(ConfigService)
|
||||||
config.reload_technician_config()
|
await config.reload_technician_config()
|
||||||
|
@ -26,4 +26,4 @@ class ConfigOnReadyEvent(OnReadyABC):
|
|||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
for guild in self._bot.guilds:
|
for guild in self._bot.guilds:
|
||||||
self._config_service.reload_server_config(self._servers.get_server_by_discord_id(guild.id))
|
await self._config_service.reload_server_config(self._servers.get_server_by_discord_id(guild.id))
|
||||||
|
Loading…
Reference in New Issue
Block a user