From 3ea0acd48b6c5bc5c15053fc75daec8dbf102c02 Mon Sep 17 00:00:00 2001 From: snowy Date: Sun, 26 May 2024 16:38:38 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BF=AE=E6=94=B9=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E9=80=BB=E8=BE=91=E5=92=8C=E6=8F=92=E4=BB=B6=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/liteyuki_main/__init__.py | 1 - liteyuki/liteyuki_main/loader.py | 36 +++-- .../liteyuki_crt_utils/crt_matchers.py | 12 +- liteyuki/resources/liteyuki_crt/lang/en.lang | 3 + .../resources/liteyuki_crt/lang/zh-CN.lang | 3 + .../liteyuki_crt/templates/crt_route.html | 145 +++++++++++++++++- .../liteyuki_crt/templates/css/crt_route.css | 0 .../liteyuki_crt/templates/js/crt_route.js | 9 +- .../templates/js/weather_now.js | 2 +- liteyuki/utils/base/language.py | 17 +- main.py | 21 +-- 11 files changed, 206 insertions(+), 43 deletions(-) create mode 100644 liteyuki/resources/liteyuki_crt/lang/en.lang create mode 100644 liteyuki/resources/liteyuki_crt/lang/zh-CN.lang create mode 100644 liteyuki/resources/liteyuki_crt/templates/css/crt_route.css diff --git a/liteyuki/liteyuki_main/__init__.py b/liteyuki/liteyuki_main/__init__.py index 9f04f2d..7549fc5 100644 --- a/liteyuki/liteyuki_main/__init__.py +++ b/liteyuki/liteyuki_main/__init__.py @@ -32,4 +32,3 @@ $$$$$$$$/ $$$$$$/ $$/ $$$$$$$$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ sys_lang = Language(get_default_lang_code()) nonebot.logger.info(sys_lang.get("main.current_language", LANG=sys_lang.get("language.name"))) -# nonebot.logger.info(sys_lang.get("main.enable_webdash", URL=f"http://127.0.0.1:{config.get('port', 20216)}")) diff --git a/liteyuki/liteyuki_main/loader.py b/liteyuki/liteyuki_main/loader.py index 2b18966..11a4ba4 100644 --- a/liteyuki/liteyuki_main/loader.py +++ b/liteyuki/liteyuki_main/loader.py @@ -1,5 +1,5 @@ import nonebot.plugin - +from nonebot import get_driver from liteyuki.utils import init_log from liteyuki.utils.base.config import get_config from liteyuki.utils.base.data_manager import InstalledPlugin, plugin_db @@ -9,19 +9,25 @@ from liteyuki.utils.message.tools import check_for_package load_resources() init_log() -nonebot.plugin.load_plugins("liteyuki/plugins") -# 从数据库读取已安装的插件 -if not get_config("safe_mode", False): - # 安全模式下,不加载插件 +driver = get_driver() - installed_plugins: list[InstalledPlugin] = plugin_db.where_all(InstalledPlugin()) - if installed_plugins: - for installed_plugin in installed_plugins: - if not check_for_package(installed_plugin.module_name): - nonebot.logger.error(f"{installed_plugin.module_name} not installed, but in loading database. please run `npm fixup` in chat to reinstall it.") - else: - nonebot.load_plugin(installed_plugin.module_name) - nonebot.plugin.load_plugins("plugins") -else: - nonebot.logger.info("Safe mode is on, no plugin loaded.") +@driver.on_startup +async def load_plugins(): + nonebot.plugin.load_plugins("liteyuki/plugins") + # 从数据库读取已安装的插件 + if not get_config("safe_mode", False): + # 安全模式下,不加载插件 + + installed_plugins: list[InstalledPlugin] = plugin_db.where_all(InstalledPlugin()) + if installed_plugins: + for installed_plugin in installed_plugins: + if not check_for_package(installed_plugin.module_name): + nonebot.logger.error( + f"{installed_plugin.module_name} not installed, but in loading database. please run `npm fixup` in chat to reinstall it.") + else: + nonebot.load_plugin(installed_plugin.module_name) + + nonebot.plugin.load_plugins("plugins") + else: + nonebot.logger.info("Safe mode is on, no plugin loaded.") diff --git a/liteyuki/plugins/liteyuki_crt_utils/crt_matchers.py b/liteyuki/plugins/liteyuki_crt_utils/crt_matchers.py index 524d94f..cccebe8 100644 --- a/liteyuki/plugins/liteyuki_crt_utils/crt_matchers.py +++ b/liteyuki/plugins/liteyuki_crt_utils/crt_matchers.py @@ -36,7 +36,7 @@ async def _(result: Arparma, event: T_MessageEvent): end = quote(quote(result.other_args.get("end"))) # 判断参数语言 - query_lang_code = "Eng" if ulang.lang_code not in ["zh-CN", "zh-HK"] else "" + query_lang_code = "" if start.isalpha() and end.isalpha(): query_lang_code = "Eng" @@ -55,9 +55,15 @@ async def _(result: Arparma, event: T_MessageEvent): # 模板传参定义 templates = { - "data": { + "data" : { "result": result["result"], - } + }, + "localization": ulang.get_many( + "crt.station", + "crt.hour", + "crt.minute", + ) + } # 生成图片 diff --git a/liteyuki/resources/liteyuki_crt/lang/en.lang b/liteyuki/resources/liteyuki_crt/lang/en.lang new file mode 100644 index 0000000..e5b7763 --- /dev/null +++ b/liteyuki/resources/liteyuki_crt/lang/en.lang @@ -0,0 +1,3 @@ +crt.station=Station(s) +crt.hour=Hour(s) +crt.minute=Min(s) \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_crt/lang/zh-CN.lang b/liteyuki/resources/liteyuki_crt/lang/zh-CN.lang new file mode 100644 index 0000000..6859336 --- /dev/null +++ b/liteyuki/resources/liteyuki_crt/lang/zh-CN.lang @@ -0,0 +1,3 @@ +crt.station=站 +crt.hour=小时 +crt.minute=分钟 \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_crt/templates/crt_route.html b/liteyuki/resources/liteyuki_crt/templates/crt_route.html index 71d5183..9140edd 100644 --- a/liteyuki/resources/liteyuki_crt/templates/crt_route.html +++ b/liteyuki/resources/liteyuki_crt/templates/crt_route.html @@ -6,15 +6,154 @@ +
{{ data | tojson }}
-