diff --git a/kdb-bot/src/bot/bot.json b/kdb-bot/src/bot/bot.json index dd99aa8d..41e95b38 100644 --- a/kdb-bot/src/bot/bot.json +++ b/kdb-bot/src/bot/bot.json @@ -16,10 +16,10 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core==2023.4.0.post1", - "cpl-translation==2023.4.0", - "cpl-query==2023.4.0", - "cpl-discord==2023.4.0", + "cpl-core==2023.4.0.post2", + "cpl-translation==2023.4.0.post1", + "cpl-query==2023.4.0.post1", + "cpl-discord==2023.4.0.post2", "Flask==2.3.2", "Flask-Classful==0.14.2", "Flask-Cors==3.0.10", @@ -32,7 +32,7 @@ "ariadne==0.19.1" ], "DevDependencies": [ - "cpl-cli==2023.4.0.post1", + "cpl-cli==2023.4.0.post3", "pygount==1.5.1" ], "PythonVersion": ">=3.10.4", diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index 0c946375..e1c1efac 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit 0c9463753731ab1f5d0f916d21ac7ea304742995 +Subproject commit e1c1efac984a04826c0c2713a26129b9d34b21d6 diff --git a/kdb-bot/src/bot_api/controller/graphql_controller.py b/kdb-bot/src/bot_api/controller/graphql_controller.py index d9072029..aefd8f13 100644 --- a/kdb-bot/src/bot_api/controller/graphql_controller.py +++ b/kdb-bot/src/bot_api/controller/graphql_controller.py @@ -1,5 +1,5 @@ from ariadne import graphql_sync -from ariadne.constants import PLAYGROUND_HTML +from ariadne.explorer import ExplorerGraphiQL from cpl_core.configuration import ConfigurationABC from cpl_core.environment import ApplicationEnvironmentABC from flask import request, jsonify @@ -30,7 +30,7 @@ class GraphQLController: if self._env.environment_name != "development": return "", 403 - return PLAYGROUND_HTML, 200 + return ExplorerGraphiQL().html(None), 200 @Route.post(f"{BasePath}") @Route.authorize(by_api_key=True) diff --git a/kdb-bot/src/bot_core/configuration/bot_logging_settings.py b/kdb-bot/src/bot_core/configuration/bot_logging_settings.py index b69e2c73..a91c5638 100644 --- a/kdb-bot/src/bot_core/configuration/bot_logging_settings.py +++ b/kdb-bot/src/bot_core/configuration/bot_logging_settings.py @@ -1,32 +1,43 @@ -import traceback - from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC -from cpl_core.console import Console, ForegroundColorEnum +from cpl_core.utils.json_processor import JSONProcessor from cpl_query.extension import List from bot_core.configuration.file_logging_settings import FileLoggingSettings class BotLoggingSettings(ConfigurationModelABC): - def __init__(self): + def __init__(self, custom_logs: dict = None): ConfigurationModelABC.__init__(self) self._files: List[FileLoggingSettings] = List(FileLoggingSettings) + if custom_logs is not None: + self._files_from_dict(custom_logs) + @property def files(self) -> List[FileLoggingSettings]: return self._files - def from_dict(self, settings: dict): - try: - files = List(FileLoggingSettings) - for s in settings: - st = FileLoggingSettings() - settings[s]["Key"] = s - st.from_dict(settings[s]) - files.append(st) - self._files = files - except Exception as e: - Console.set_foreground_color(ForegroundColorEnum.red) - Console.write_line(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings") - Console.write_line(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}") - Console.set_foreground_color(ForegroundColorEnum.default) + def _files_from_dict(self, settings: dict): + files = List(FileLoggingSettings) + for s in settings: + # st = FileLoggingSettings(s) + settings[s]["Key"] = s + # st.from_dict(settings[s]) + st = JSONProcessor.process(FileLoggingSettings, settings[s]) + files.append(st) + self._files = files + + # def from_dict(self, settings: dict): + # try: + # files = List(FileLoggingSettings) + # for s in settings: + # st = FileLoggingSettings() + # settings[s]["Key"] = s + # st.from_dict(settings[s]) + # files.append(st) + # self._files = files + # except Exception as e: + # Console.set_foreground_color(ForegroundColorEnum.red) + # Console.write_line(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings") + # Console.write_line(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}") + # Console.set_foreground_color(ForegroundColorEnum.default) diff --git a/kdb-bot/src/bot_core/configuration/file_logging_settings.py b/kdb-bot/src/bot_core/configuration/file_logging_settings.py index 58d461b9..b941601d 100644 --- a/kdb-bot/src/bot_core/configuration/file_logging_settings.py +++ b/kdb-bot/src/bot_core/configuration/file_logging_settings.py @@ -1,23 +1,27 @@ -import traceback - -from cpl_core.console import Console -from cpl_core.logging import LoggingSettings +from cpl_core.logging import LoggingSettings, LoggingLevelEnum class FileLoggingSettings(LoggingSettings): - def __init__(self): - LoggingSettings.__init__(self) + def __init__( + self, + key: str, + path: str = None, + filename: str = None, + console_log_level: LoggingLevelEnum = None, + file_log_level: LoggingLevelEnum = None, + ): + LoggingSettings.__init__(self, path, filename, console_log_level, file_log_level) - self._key = "" + self._key = key @property def key(self) -> str: return self._key - def from_dict(self, settings: dict): - try: - self._key = settings["Key"] - super().from_dict(settings) - except Exception as e: - Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings") - Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}") + # def from_dict(self, settings: dict): + # try: + # self._key = settings["Key"] + # super().from_dict(settings) + # except Exception as e: + # Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings") + # Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")