Reload config after change #334
This commit is contained in:
parent
e549341196
commit
113b188a40
@ -11,6 +11,7 @@ from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.events.core_on_ready_event import CoreOnReadyEvent
|
||||
from bot_core.pipes.date_time_offset_pipe import DateTimeOffsetPipe
|
||||
from bot_core.service.client_utils_service import ClientUtilsService
|
||||
from bot_core.service.config_service import ConfigService
|
||||
from bot_core.service.data_integrity_service import DataIntegrityService
|
||||
from bot_core.service.message_service import MessageService
|
||||
|
||||
@ -23,6 +24,7 @@ class CoreModule(ModuleABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_transient(ConfigService)
|
||||
services.add_transient(MessageServiceABC, MessageService)
|
||||
services.add_transient(ClientUtilsABC, ClientUtilsService)
|
||||
services.add_transient(DataIntegrityService)
|
||||
|
30
kdb-bot/src/bot_core/service/config_service.py
Normal file
30
kdb-bot/src/bot_core/service/config_service.py
Normal file
@ -0,0 +1,30 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.server import Server
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
|
||||
|
||||
class ConfigService:
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
technician_config_repo: TechnicianConfigRepositoryABC,
|
||||
server_config_repo: ServerConfigRepositoryABC,
|
||||
):
|
||||
self._config = config
|
||||
self._technician_config_repo = technician_config_repo
|
||||
self._server_config_repo = server_config_repo
|
||||
|
||||
def reload_technician_config(self):
|
||||
technician_config = self._technician_config_repo.get_technician_config()
|
||||
self._config.add_configuration(TechnicianConfig, technician_config)
|
||||
self._config.add_configuration(FeatureFlagsSettings, FeatureFlagsSettings(**technician_config.feature_flags))
|
||||
|
||||
def reload_server_config(self, server: Server):
|
||||
server_config = self._server_config_repo.get_server_config_by_server(server.id)
|
||||
self._config.add_configuration(
|
||||
f"{type(server_config).__name__}_{server_config.server.discord_id}", server_config
|
||||
)
|
@ -4,6 +4,7 @@ from cpl_query.extension import List
|
||||
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.route.route import Route
|
||||
from bot_core.service.config_service import ConfigService
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.model.server_afk_channel_ids_config import ServerAFKChannelIdsConfig
|
||||
@ -12,6 +13,7 @@ from bot_data.model.server_team_role_ids_config import ServerTeamRoleIdsConfig
|
||||
from bot_data.model.team_member_type_enum import TeamMemberTypeEnum
|
||||
from bot_data.model.user_role_enum import UserRoleEnum
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class ServerConfigMutation(QueryABC):
|
||||
@ -22,6 +24,8 @@ class ServerConfigMutation(QueryABC):
|
||||
servers: ServerRepositoryABC,
|
||||
server_configs: ServerConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
config_service: ConfigService,
|
||||
permissions: PermissionServiceABC,
|
||||
):
|
||||
QueryABC.__init__(self, "ServerConfigMutation")
|
||||
|
||||
@ -30,6 +34,8 @@ class ServerConfigMutation(QueryABC):
|
||||
self._servers = servers
|
||||
self._server_configs = server_configs
|
||||
self._db = db
|
||||
self._config_service = config_service
|
||||
self._permissions = permissions
|
||||
|
||||
self.set_field("updateServerConfig", self.resolve_update_server_config)
|
||||
|
||||
@ -168,5 +174,5 @@ class ServerConfigMutation(QueryABC):
|
||||
|
||||
self._server_configs.add_server_team_role_id_config(role_id)
|
||||
|
||||
# todo reload config
|
||||
# reload permissions
|
||||
self._config_service.reload_server_config(new_config.server)
|
||||
self._permissions.on_ready()
|
||||
|
@ -4,6 +4,7 @@ from cpl_query.extension import List
|
||||
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.route.route import Route
|
||||
from bot_core.service.config_service import ConfigService
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
@ -23,6 +24,7 @@ class TechnicianConfigMutation(QueryABC):
|
||||
technician_configs: TechnicianConfigRepositoryABC,
|
||||
db: DatabaseContextABC,
|
||||
permissions: PermissionServiceABC,
|
||||
config_service: ConfigService,
|
||||
):
|
||||
QueryABC.__init__(self, "TechnicianConfigMutation")
|
||||
|
||||
@ -32,6 +34,7 @@ class TechnicianConfigMutation(QueryABC):
|
||||
self._technician_configs = technician_configs
|
||||
self._db = db
|
||||
self._permissions = permissions
|
||||
self._config_service = config_service
|
||||
|
||||
self.set_field("updateTechnicianConfig", self.resolve_update_technician_config)
|
||||
|
||||
@ -110,5 +113,5 @@ class TechnicianConfigMutation(QueryABC):
|
||||
|
||||
self._technician_configs.add_technician_id_config(TechnicianIdConfig(technician_id))
|
||||
|
||||
# todo reload config
|
||||
self._config_service.reload_technician_config()
|
||||
self._permissions.on_ready()
|
||||
|
@ -5,8 +5,7 @@ from cpl_core.logging import LoggerABC
|
||||
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
from bot_core.service.config_service import ConfigService
|
||||
|
||||
|
||||
class ConfigExtension(ApplicationExtensionABC):
|
||||
@ -19,6 +18,5 @@ class ConfigExtension(ApplicationExtensionABC):
|
||||
return
|
||||
logger: LoggerABC = services.get_service(LoggerABC)
|
||||
logger.debug(__name__, "Config extension started")
|
||||
technician_config_repo: TechnicianConfigRepositoryABC = services.get_service(TechnicianConfigRepositoryABC)
|
||||
technician_config = technician_config_repo.get_technician_config()
|
||||
config.add_configuration(TechnicianConfig, technician_config)
|
||||
config: ConfigService = services.get_service(ConfigService)
|
||||
config.reload_technician_config()
|
||||
|
@ -1,10 +1,9 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.container import Guild
|
||||
from cpl_discord.events import OnReadyABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
|
||||
from bot_core.service.config_service import ConfigService
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
|
||||
|
||||
@ -15,7 +14,7 @@ class ConfigOnReadyEvent(OnReadyABC):
|
||||
logger: LoggerABC,
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
server_config_repo: ServerConfigRepositoryABC,
|
||||
config_service: ConfigService,
|
||||
):
|
||||
OnReadyABC.__init__(self)
|
||||
|
||||
@ -23,13 +22,8 @@ class ConfigOnReadyEvent(OnReadyABC):
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._servers = servers
|
||||
self._server_config_repo = server_config_repo
|
||||
self._config_service = config_service
|
||||
|
||||
async def on_ready(self):
|
||||
for guild in self._bot.guilds:
|
||||
guild: Guild = guild
|
||||
server = self._servers.get_server_by_discord_id(guild.id)
|
||||
server_config = self._server_config_repo.get_server_config_by_server(server.id)
|
||||
self._config.add_configuration(
|
||||
f"{type(server_config).__name__}_{server_config.server.discord_id}", server_config
|
||||
)
|
||||
self._config_service.reload_server_config(self._servers.get_server_by_discord_id(guild.id))
|
||||
|
Loading…
Reference in New Issue
Block a user