From 86c7b70e63e1695a68a455ae46edcc3a17cb6bb0 Mon Sep 17 00:00:00 2001 From: snowy Date: Sat, 27 Apr 2024 02:20:44 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=BD=BB=E9=9B=AA=E5=A4=A9?= =?UTF-8?q?=E6=B0=94=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/usage/extra_command.md | 8 +- liteyuki/liteyuki_main/core.py | 12 +- liteyuki/plugins/liteyuki_eventpush.py | 4 +- liteyuki/plugins/liteyuki_pacman/common.py | 8 +- liteyuki/plugins/liteyuki_pacman/npm.py | 2 +- liteyuki/plugins/liteyuki_status/api.py | 30 +-- .../plugins/liteyuki_user/profile_manager.py | 2 +- liteyuki/plugins/liteyuki_weather/__init__.py | 18 +- liteyuki/plugins/liteyuki_weather/qw_api.py | 46 ++++- liteyuki/plugins/liteyuki_weather/qweather.py | 49 +++-- .../resources/liteyuki_weather/lang/en.lang | 11 ++ .../resources/liteyuki_weather/lang/ja.lang | 11 ++ .../liteyuki_weather/lang/zh-CN.lang | 11 ++ .../resources/liteyuki_weather/metadata.yml | 3 + .../templates/css/weather_now.css | 184 ++++++++++++++++++ .../templates/img/qw_icon/100.png | Bin .../templates/img/qw_icon/101.png | Bin .../templates/img/qw_icon/102.png | Bin .../templates/img/qw_icon/103.png | Bin .../templates/img/qw_icon/104.png | Bin .../templates/img/qw_icon/150.png | Bin .../templates/img/qw_icon/151.png | Bin .../templates/img/qw_icon/152.png | Bin .../templates/img/qw_icon/153.png | Bin .../templates/img/qw_icon/154.png | Bin .../templates/img/qw_icon/300.png | Bin .../templates/img/qw_icon/301.png | Bin .../templates/img/qw_icon/302.png | Bin .../templates/img/qw_icon/303.png | Bin .../templates/img/qw_icon/304.png | Bin .../templates/img/qw_icon/305.png | Bin .../templates/img/qw_icon/306.png | Bin .../templates/img/qw_icon/307.png | Bin .../templates/img/qw_icon/308.png | Bin .../templates/img/qw_icon/309.png | Bin .../templates/img/qw_icon/310.png | Bin .../templates/img/qw_icon/311.png | Bin .../templates/img/qw_icon/312.png | Bin .../templates/img/qw_icon/313.png | Bin .../templates/img/qw_icon/314.png | Bin .../templates/img/qw_icon/315.png | Bin .../templates/img/qw_icon/316.png | Bin .../templates/img/qw_icon/317.png | Bin .../templates/img/qw_icon/318.png | Bin .../templates/img/qw_icon/350.png | Bin .../templates/img/qw_icon/351.png | Bin .../templates/img/qw_icon/399.png | Bin .../templates/img/qw_icon/400.png | Bin .../templates/img/qw_icon/401.png | Bin .../templates/img/qw_icon/402.png | Bin .../templates/img/qw_icon/403.png | Bin .../templates/img/qw_icon/404.png | Bin .../templates/img/qw_icon/405.png | Bin .../templates/img/qw_icon/406.png | Bin .../templates/img/qw_icon/407.png | Bin .../templates/img/qw_icon/408.png | Bin .../templates/img/qw_icon/409.png | Bin .../templates/img/qw_icon/410.png | Bin .../templates/img/qw_icon/456.png | Bin .../templates/img/qw_icon/457.png | Bin .../templates/img/qw_icon/499.png | Bin .../templates/img/qw_icon/500.png | Bin .../templates/img/qw_icon/501.png | Bin .../templates/img/qw_icon/502.png | Bin .../templates/img/qw_icon/503.png | Bin .../templates/img/qw_icon/504.png | Bin .../templates/img/qw_icon/507.png | Bin .../templates/img/qw_icon/508.png | Bin .../templates/img/qw_icon/509.png | Bin .../templates/img/qw_icon/510.png | Bin .../templates/img/qw_icon/511.png | Bin .../templates/img/qw_icon/512.png | Bin .../templates/img/qw_icon/513.png | Bin .../templates/img/qw_icon/514.png | Bin .../templates/img/qw_icon/515.png | Bin .../templates/img/qw_icon/800.png | Bin .../templates/img/qw_icon/801.png | Bin .../templates/img/qw_icon/802.png | Bin .../templates/img/qw_icon/803.png | Bin .../templates/img/qw_icon/804.png | Bin .../templates/img/qw_icon/805.png | Bin .../templates/img/qw_icon/806.png | Bin .../templates/img/qw_icon/807.png | Bin .../templates/img/qw_icon/900.png | Bin .../templates/img/qw_icon/901.png | Bin .../templates/img/qw_icon/999.png | Bin .../templates/js/weather_now.js | 114 +++++++++++ .../templates/weather_now.html | 73 +++++++ .../resources/vanilla_language/lang/de.lang | 3 +- .../resources/vanilla_language/lang/en.lang | 3 +- .../resources/vanilla_language/lang/es.lang | 3 +- .../resources/vanilla_language/lang/ja.lang | 3 +- .../vanilla_language/lang/zh-CN.lang | 3 +- .../vanilla_resource/templates/css/card.css | 8 +- .../vanilla_resource/templates/css/status.css | 23 +-- .../templates/css/weather_now.css | 83 -------- .../vanilla_resource/templates/js/card.js | 6 + .../vanilla_resource/templates/js/status.js | 2 + .../templates/js/weather_now.js | 59 ------ .../templates/weather_now.html | 48 ----- liteyuki/utils/__init__.py | 2 +- liteyuki/utils/base/config.py | 8 +- liteyuki/utils/base/data.py | 2 +- liteyuki/utils/base/data_manager.py | 33 ++++ liteyuki/utils/base/language.py | 3 +- liteyuki/utils/base/ly_typing.py | 2 +- liteyuki/utils/message/html_tool.py | 9 +- 107 files changed, 616 insertions(+), 273 deletions(-) create mode 100644 liteyuki/resources/liteyuki_weather/lang/en.lang create mode 100644 liteyuki/resources/liteyuki_weather/lang/ja.lang create mode 100644 liteyuki/resources/liteyuki_weather/lang/zh-CN.lang create mode 100644 liteyuki/resources/liteyuki_weather/metadata.yml create mode 100644 liteyuki/resources/liteyuki_weather/templates/css/weather_now.css rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/100.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/101.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/102.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/103.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/104.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/150.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/151.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/152.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/153.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/154.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/300.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/301.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/302.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/303.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/304.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/305.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/306.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/307.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/308.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/309.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/310.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/311.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/312.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/313.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/314.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/315.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/316.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/317.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/318.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/350.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/351.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/399.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/400.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/401.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/402.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/403.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/404.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/405.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/406.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/407.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/408.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/409.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/410.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/456.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/457.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/499.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/500.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/501.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/502.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/503.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/504.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/507.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/508.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/509.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/510.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/511.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/512.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/513.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/514.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/515.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/800.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/801.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/802.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/803.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/804.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/805.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/806.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/807.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/900.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/901.png (100%) rename liteyuki/resources/{vanilla_resource => liteyuki_weather}/templates/img/qw_icon/999.png (100%) create mode 100644 liteyuki/resources/liteyuki_weather/templates/js/weather_now.js create mode 100644 liteyuki/resources/liteyuki_weather/templates/weather_now.html delete mode 100644 liteyuki/resources/vanilla_resource/templates/css/weather_now.css delete mode 100644 liteyuki/resources/vanilla_resource/templates/js/weather_now.js delete mode 100644 liteyuki/resources/vanilla_resource/templates/weather_now.html diff --git a/docs/usage/extra_command.md b/docs/usage/extra_command.md index 5e094d16..a4232d2d 100644 --- a/docs/usage/extra_command.md +++ b/docs/usage/extra_command.md @@ -5,23 +5,25 @@ order: 2 category: 使用手册 --- - ## 功能插件命令 ### **轻雪天气`liteyuki_weather`** + 配置项 + ```yaml -weather_key: "" # 和风天气的天气key -weather_dev: false # 是否为开发版 +weather_key: "" # 和风天气的天气key,会自动判断key版本 ``` 命令 + ```shell weather # 查询目标地实时天气,例如:"天气 北京 海淀", "weather Tokyo Shinjuku" bind-city # 绑定查询城市,个人全局生效 ``` 命令别名 + ```shell weather 天气, bind-city 绑定城市 ``` \ No newline at end of file diff --git a/liteyuki/liteyuki_main/core.py b/liteyuki/liteyuki_main/core.py index 6407fe61..8eb48028 100644 --- a/liteyuki/liteyuki_main/core.py +++ b/liteyuki/liteyuki_main/core.py @@ -83,7 +83,7 @@ async def _(matcher: Matcher, bot: T_Bot, event: T_MessageEvent): } ) - common_db.upsert(temp_data) + common_db.save(temp_data) Reloader.reload(0) @@ -120,7 +120,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot, matcher: Matcher except: pass stored_config.config[key] = value - common_db.upsert(stored_config) + common_db.save(stored_config) await matcher.finish(f"{ulang.get('liteyuki.config_set_success', KEY=key, VAL=value)}") elif result.subcommands.get("get"): key = result.subcommands.get("get").args.get("key") @@ -144,7 +144,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot, matcher: Matcher key = result.subcommands.get("remove").args.get("key") if key in stored_config.config: stored_config.config.pop(key) - common_db.upsert(stored_config) + common_db.save(stored_config) await matcher.finish(f"{ulang.get('liteyuki.config_remove_success', KEY=key)}") else: await matcher.finish(f"{ulang.get('liteyuki.invalid_command', TEXT=key)}") @@ -164,7 +164,7 @@ async def _(event: T_MessageEvent, matcher: Matcher): stored_config: StoredConfig = common_db.first(StoredConfig(), default=StoredConfig()) stored_config.config["markdown_image"] = not stored_config.config.get("markdown_image", False) markdown_image = stored_config.config["markdown_image"] - common_db.upsert(stored_config) + common_db.save(stored_config) await matcher.finish(ulang.get("liteyuki.image_mode_on" if stored_config.config["markdown_image"] else "liteyuki.image_mode_off")) @@ -258,7 +258,7 @@ async def on_startup(): if temp_data.data.get("reload", False): delta_time = time.time() - temp_data.data.get("reload_time", 0) temp_data.data["delta_time"] = delta_time - common_db.upsert(temp_data) # 更新数据 + common_db.save(temp_data) # 更新数据 @driver.on_shutdown @@ -278,7 +278,7 @@ async def _(bot: T_Bot): reload_session_type = temp_data.data.get("reload_session_type", "private") reload_session_id = temp_data.data.get("reload_session_id", 0) delta_time = temp_data.data.get("delta_time", 0) - common_db.upsert(temp_data) # 更新数据 + common_db.save(temp_data) # 更新数据 await bot.call_api( "send_msg", message_type=reload_session_type, diff --git a/liteyuki/plugins/liteyuki_eventpush.py b/liteyuki/plugins/liteyuki_eventpush.py index 8196634a..12bc001a 100644 --- a/liteyuki/plugins/liteyuki_eventpush.py +++ b/liteyuki/plugins/liteyuki_eventpush.py @@ -66,7 +66,7 @@ async def _(result: Arparma): target=Node(bot_id=target[0], session_type=target[1], session_id=target[2]), inde=len(pushes_db.all(Push(), default=[])) ) - pushes_db.upsert(push1) + pushes_db.save(push1) if result.subcommands["add"].args.get("bidirectional"): push2 = Push( @@ -74,7 +74,7 @@ async def _(result: Arparma): target=Node(bot_id=source[0], session_type=source[1], session_id=source[2]), inde=len(pushes_db.all(Push(), default=[])) ) - pushes_db.upsert(push2) + pushes_db.save(push2) await add_push.finish("添加成功") else: await add_push.finish("参数缺失") diff --git a/liteyuki/plugins/liteyuki_pacman/common.py b/liteyuki/plugins/liteyuki_pacman/common.py index 47f2c192..e72019b9 100644 --- a/liteyuki/plugins/liteyuki_pacman/common.py +++ b/liteyuki/plugins/liteyuki_pacman/common.py @@ -150,10 +150,10 @@ def set_plugin_session_enable(event: T_MessageEvent, plugin_name: str, enable: b if event.message_type == "group": __group_data[str(event.group_id)] = session print(session) - group_db.upsert(session) + group_db.save(session) else: __user_data[str(event.user_id)] = session - user_db.upsert(session) + user_db.save(session) def get_plugin_global_enable(plugin_name: str) -> bool: @@ -193,7 +193,7 @@ def set_plugin_global_enable(plugin_name: str, enable: bool): default=GlobalPlugin(module_name=plugin_name, enabled=True)) plugin.enabled = enable - plugin_db.upsert(plugin) + plugin_db.save(plugin) __global_enable[plugin_name] = enable @@ -242,4 +242,4 @@ def set_group_enable(group_id: str, enable: bool): group.enable = enable __group_data[group_id] = group - group_db.upsert(group) + group_db.save(group) diff --git a/liteyuki/plugins/liteyuki_pacman/npm.py b/liteyuki/plugins/liteyuki_pacman/npm.py index 3c346f7f..d02f5236 100644 --- a/liteyuki/plugins/liteyuki_pacman/npm.py +++ b/liteyuki/plugins/liteyuki_pacman/npm.py @@ -225,7 +225,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot, npm: Matcher): found_in_db_plugin = plugin_db.first(InstalledPlugin(), "module_name = ?", plugin_name) # 查询数据库中是否已经安装 if r_load: if found_in_db_plugin is None: - plugin_db.upsert(installed_plugin) + plugin_db.save(installed_plugin) info = md.escape(ulang.get("npm.install_success", NAME=store_plugin.name)) # markdown转义 await md.send_md( f"{info}\n\n" diff --git a/liteyuki/plugins/liteyuki_status/api.py b/liteyuki/plugins/liteyuki_status/api.py index 42f3c819..ba276a74 100644 --- a/liteyuki/plugins/liteyuki_status/api.py +++ b/liteyuki/plugins/liteyuki_status/api.py @@ -55,18 +55,22 @@ data """ -async def generate_status_card(bot: dict, hardware: dict, liteyuki: dict, lang="zh-CN", bot_id="0") -> bytes: - return await template2image( - get_path("templates/status.html", abs_path=True), - { - "data": { - "bot" : bot, - "hardware" : hardware, - "liteyuki" : liteyuki, - "localization": get_local_data(lang) - } - } - ) +async def generate_status_card(bot: dict, hardware: dict, liteyuki: dict, lang="zh-CN", bot_id="0", use_cache=False) -> bytes: + if not use_cache: + return await template2image( + get_path("templates/status.html", abs_path=True), + { + "data": { + "bot" : bot, + "hardware" : hardware, + "liteyuki" : liteyuki, + "localization": get_local_data(lang) + } + }, + debug=True + ) + else: + pass def get_local_data(lang_code) -> dict: @@ -97,7 +101,7 @@ def get_local_data(lang_code) -> dict: "cores" : lang.get("status.cores"), "process" : lang.get("status.process"), "resources" : lang.get("status.resources"), - + "description" : lang.get("status.description"), } diff --git a/liteyuki/plugins/liteyuki_user/profile_manager.py b/liteyuki/plugins/liteyuki_user/profile_manager.py index 23cd2f5a..b04fad95 100644 --- a/liteyuki/plugins/liteyuki_user/profile_manager.py +++ b/liteyuki/plugins/liteyuki_user/profile_manager.py @@ -49,7 +49,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot): r = set_profile(result.args["key"], result.args["value"], str(event.user_id)) if r: user.profile[result.args["key"]] = result.args["value"] - user_db.upsert(user) # 数据库保存 + user_db.save(user) # 数据库保存 await profile_alc.finish( ulang.get( "user.profile.set_success", diff --git a/liteyuki/plugins/liteyuki_weather/__init__.py b/liteyuki/plugins/liteyuki_weather/__init__.py index 54cd1480..2127a6ac 100644 --- a/liteyuki/plugins/liteyuki_weather/__init__.py +++ b/liteyuki/plugins/liteyuki_weather/__init__.py @@ -1,7 +1,7 @@ from nonebot.plugin import PluginMetadata +from nonebot import get_driver from .qweather import * - __plugin_meta__ = PluginMetadata( name="轻雪天气", description="基于和风天气api的天气插件", @@ -9,9 +9,19 @@ __plugin_meta__ = PluginMetadata( type="application", homepage="https://github.com/snowykami/LiteyukiBot", extra={ - "liteyuki": True, - "toggleable" : True, - "default_enable" : True, + "liteyuki" : True, + "toggleable" : True, + "default_enable": True, } ) +from ...utils.base.data_manager import set_memory_data + +driver = get_driver() + + +@driver.on_startup +async def _(): + # 检查是否为开发者模式 + is_dev = await check_key_dev(get_config("weather_key", "")) + set_memory_data("weather.is_dev", is_dev) diff --git a/liteyuki/plugins/liteyuki_weather/qw_api.py b/liteyuki/plugins/liteyuki_weather/qw_api.py index 1bc33831..ebe334a6 100644 --- a/liteyuki/plugins/liteyuki_weather/qw_api.py +++ b/liteyuki/plugins/liteyuki_weather/qw_api.py @@ -1,6 +1,8 @@ from .qw_models import * import httpx +from ...utils.base.data_manager import get_memory_data +from ...utils.base.language import Language dev_url = "https://devapi.qweather.com/" # 开发HBa com_url = "https://api.qweather.com/" # 正式环境 @@ -17,6 +19,42 @@ def get_qw_lang(lang: str) -> str: return lang +async def check_key_dev(key: str) -> bool: + url = "https://api.qweather.com/v7/weather/now?" + params = { + "location": "101010100", + "key" : key, + } + async with httpx.AsyncClient() as client: + resp = await client.get(url, params=params) + return resp.json().get("code") != "200" # 查询不到付费数据为开发版 + + +def get_local_data(ulang_code: str) -> dict: + """ + 获取本地化数据 + Args: + ulang_code: + + Returns: + + """ + ulang = Language(ulang_code) + return { + "monday" : ulang.get("weather.monday"), + "tuesday" : ulang.get("weather.tuesday"), + "wednesday": ulang.get("weather.wednesday"), + "thursday" : ulang.get("weather.thursday"), + "friday" : ulang.get("weather.friday"), + "saturday" : ulang.get("weather.saturday"), + "sunday" : ulang.get("weather.sunday"), + "today" : ulang.get("weather.today"), + "tomorrow" : ulang.get("weather.tomorrow"), + "day" : ulang.get("weather.day"), + "night" : ulang.get("weather.night"), + } + + async def city_lookup( location: str, key: str, @@ -54,7 +92,7 @@ async def get_weather_now( location: str, lang: str = "zh", unit: str = "m", - dev: bool = True, + dev: bool = get_memory_data("is_dev", True), ) -> dict: url_path = "v7/weather/now?" url = dev_url + url_path if dev else com_url + url_path @@ -74,7 +112,7 @@ async def get_weather_daily( location: str, lang: str = "zh", unit: str = "m", - dev: bool = True, + dev: bool = get_memory_data("is_dev", True), ) -> dict: url_path = "v7/weather/%dd?" % (7 if dev else 30) url = dev_url + url_path if dev else com_url + url_path @@ -94,7 +132,7 @@ async def get_weather_hourly( location: str, lang: str = "zh", unit: str = "m", - dev: bool = True, + dev: bool = get_memory_data("is_dev", True), ) -> dict: url_path = "v7/weather/%dh?" % (24 if dev else 168) url = dev_url + url_path if dev else com_url + url_path @@ -115,7 +153,7 @@ async def get_airquality( lang: str, pollutant: bool = False, station: bool = False, - dev: bool = True + dev: bool = get_memory_data("is_dev", True), ) -> dict: url_path = f"airquality/v1/now/{location}?" url = dev_url + url_path if dev else com_url + url_path diff --git a/liteyuki/plugins/liteyuki_weather/qweather.py b/liteyuki/plugins/liteyuki_weather/qweather.py index a224d915..a0a499bc 100644 --- a/liteyuki/plugins/liteyuki_weather/qweather.py +++ b/liteyuki/plugins/liteyuki_weather/qweather.py @@ -1,4 +1,4 @@ -from nonebot import require +from nonebot import require, on_endswith from nonebot.adapters.onebot.v11 import MessageSegment from nonebot.internal.matcher import Matcher @@ -7,7 +7,7 @@ from liteyuki.utils.base.ly_typing import T_MessageEvent from .qw_api import * from liteyuki.utils.base.data_manager import User, user_db -from liteyuki.utils.base.language import get_user_lang +from liteyuki.utils.base.language import Language, get_user_lang from liteyuki.utils.base.resource import get_path from liteyuki.utils.message.html_tool import template2image @@ -24,40 +24,50 @@ from nonebot_plugin_alconna import on_alconna, Alconna, Args, MultiVar, Arparma ).handle() async def _(result: Arparma, event: T_MessageEvent, matcher: Matcher): """await alconna.send("weather", city)""" - ulang = get_user_lang(str(event.user_id)) + kws = result.main_args.get("keywords") + image = await get_weather_now_card(matcher, event, kws) + await matcher.finish(MessageSegment.image(image)) + + +@on_endswith(("天气", "weather")).handle() +async def _(event: T_MessageEvent, matcher: Matcher): + """await alconna.send("weather", city)""" + kws = event.message.extract_plain_text() + image = await get_weather_now_card(matcher, event, [kws.replace("天气", "").replace("weather", "")], False) + await matcher.finish(MessageSegment.image(image)) + + +async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword: list[str], tip: bool = True): + ulang = get_user_lang(event.user_id) qw_lang = get_qw_lang(ulang.lang_code) key = get_config("weather_key") - is_dev = get_config("weather_dev") - - user: User = user_db.first(User(), "user_id = ?", str(event.user_id), default=User()) - + is_dev = get_memory_data("weather.is_dev", True) + user: User = user_db.first(User(), "user_id = ?", event.user_id, default=User()) # params unit = user.profile.get("unit", "m") stored_location = user.profile.get("location", None) if not key: - await matcher.finish(ulang.get("weather.no_key")) + await matcher.finish(ulang.get("weather.no_key") if tip else None) - kws = result.main_args.get("keywords") - if kws: - if len(kws) >= 2: - adm = kws[0] - city = kws[-1] + if keyword: + if len(keyword) >= 2: + adm = keyword[0] + city = keyword[-1] else: adm = "" - city = kws[0] + city = keyword[0] city_info = await city_lookup(city, key, adm=adm, lang=qw_lang) - city_name = " ".join(kws) + city_name = " ".join(keyword) else: if not stored_location: - await matcher.finish(ulang.get("liteyuki.invalid_command", TEXT="location")) + await matcher.finish(ulang.get("liteyuki.invalid_command", TEXT="location") if tip else None) city_info = await city_lookup(stored_location, key, lang=qw_lang) city_name = stored_location if city_info.code == "200": location_data = city_info.location[0] else: - await matcher.finish(ulang.get("weather.city_not_found", CITY=city_name)) - + await matcher.finish(ulang.get("weather.city_not_found", CITY=city_name) if tip else None) weather_now = await get_weather_now(key, location_data.id, lang=qw_lang, unit=unit, dev=is_dev) weather_daily = await get_weather_daily(key, location_data.id, lang=qw_lang, unit=unit, dev=is_dev) weather_hourly = await get_weather_hourly(key, location_data.id, lang=qw_lang, unit=unit, dev=is_dev) @@ -76,9 +86,10 @@ async def _(result: Arparma, event: T_MessageEvent, matcher: Matcher): "weatherHourly": weather_hourly, "aqi" : aqi, "location" : location_data.dump(), + "localization" : get_local_data(ulang.lang_code) } }, debug=True, wait=1 ) - await matcher.finish(MessageSegment.image(image)) + return image diff --git a/liteyuki/resources/liteyuki_weather/lang/en.lang b/liteyuki/resources/liteyuki_weather/lang/en.lang new file mode 100644 index 00000000..b7fa8564 --- /dev/null +++ b/liteyuki/resources/liteyuki_weather/lang/en.lang @@ -0,0 +1,11 @@ +weather.monday=Mon +weather.tuesday=Tue +weather.wednesday=Wed +weather.thursday=Thu +weather.friday=Fri +weather.saturday=Sat +weather.sunday=Sun +weather.day=Day +weather.night=Night +weather.today=Today +weather.tomorrow=Tomorrow \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/lang/ja.lang b/liteyuki/resources/liteyuki_weather/lang/ja.lang new file mode 100644 index 00000000..56845377 --- /dev/null +++ b/liteyuki/resources/liteyuki_weather/lang/ja.lang @@ -0,0 +1,11 @@ +weather.monday=月 +weather.tuesday=火 +weather.wednesday=水 +weather.thursday=木 +weather.friday=金 +weather.saturday=土 +weather.sunday=日 +weather.day=昼 +weather.night=夜 +weather.today=今日 +weather.tomorrow=明日 \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/lang/zh-CN.lang b/liteyuki/resources/liteyuki_weather/lang/zh-CN.lang new file mode 100644 index 00000000..e2c8cd77 --- /dev/null +++ b/liteyuki/resources/liteyuki_weather/lang/zh-CN.lang @@ -0,0 +1,11 @@ +weather.monday=周一 +weather.tuesday=周二 +weather.wednesday=周三 +weather.thursday=周四 +weather.friday=周五 +weather.saturday=周六 +weather.sunday=周日 +weather.day=白天 +weather.night=夜晚 +weather.today=今天 +weather.tomorrow=明天 \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/metadata.yml b/liteyuki/resources/liteyuki_weather/metadata.yml new file mode 100644 index 00000000..10b0ba32 --- /dev/null +++ b/liteyuki/resources/liteyuki_weather/metadata.yml @@ -0,0 +1,3 @@ +name: 轻雪天气资源包 +description: For Liteyuki Weather +version: 2024.4.26 \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/templates/css/weather_now.css b/liteyuki/resources/liteyuki_weather/templates/css/weather_now.css new file mode 100644 index 00000000..7776e4b9 --- /dev/null +++ b/liteyuki/resources/liteyuki_weather/templates/css/weather_now.css @@ -0,0 +1,184 @@ +:root { + --main-text-color: #fff; + --sub-text-color: #ccc; + --tip-text-color: #999; + --device-info-width: 240px; + --sub-border-radius: 60px; +} + +#weather-info { + color: white; + /*justify-content: center;*/ + /*align-items: center;*/ + /*align-content: center;*/ +} + +.icon { +/* icon 类img阴影*/ + filter: drop-shadow(1px 1px 10px #00000044); +} + +#main-info { + display: flex; + justify-content: center; + align-items: center; +} + +#main-left { + display: flex; + justify-content: flex-end; + width: 50%; +} + +#main-right { + width: 50%; +} + +#time { + font-size: 25px; + font-weight: bold; + font-style: italic; + text-align: right; + color: var(--sub-text-color); + +} + +#adm { + font-size: 32px; + font-weight: bold; + text-align: center; + color: var(--sub-text-color); +} + +#city { + margin-top: 20px; + font-size: 70px; + font-weight: bold; + text-align: center; +} + +#temperature { + display: flex; + align-items: baseline; + +} + +#temperature-now { + font-size: 70px; + font-weight: bold; +} + +#temperature-range { + font-size: 40px; + font-weight: bold; + color: var(--sub-text-color); +} + +#description { + font-size: 50px; + font-weight: bold; +} + + +#aqi { + height: 50px; + display: flex; + border-radius: 60px; + padding: 5px; + font-size: 40px; + text-align: center; + align-content: center; + align-items: center; + justify-content: center; +} + +#aqi-dot { + height: 80%; + aspect-ratio: 1 / 1; + border-radius: 50%; + background-color: var(--sub-text-color); + margin-right: 20px; +} + +.main-icon { + width: 240px; + height: 240px; +} + +#hours-info { + display: flex; + justify-content: space-between; +} + +.hourly-item { + text-align: center; + background-color: #ffffff44; + border-radius: var(--sub-border-radius); + align-items: center; + padding: 20px 10px; +} + +.hourly-icon{ + width: 80%; + margin-bottom: 20px; +} + +.hourly-temperature { + text-align: center; + color: var(--main-text-color); + font-size: 30px; + margin-bottom: 20px; +} + +.hourly-time { + text-align: center; + color: var(--main-text-color); + font-size: 25px; + margin-bottom: 10px; +} + +/**/ +.daily-item { + display: flex; + position: relative; + justify-content: space-between; + align-items: center; + background-color: #ffffff44; + height: 90px; + border-radius: var(--sub-border-radius); + margin-bottom: 20px; + padding: 0 30px; +} + +/*最后一个没有margin_button*/ +.daily-item:last-child { + margin-bottom: 0; +} + +.icon-day { + position: absolute; + left: 60%; + height: 80px; +} + +.icon-night { + position: absolute; + left: 70%; + height: 80px; +} + +.daily-weather{ + position: absolute; + left: 30%; +} + +.daily-temperature{ + position: absolute; + left: 83%; +} + +.daily-day, .daily-weather, .daily-temperature { + text-align: center; + color: var(--main-text-color); + font-size: 30px; +} \ No newline at end of file diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/100.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/100.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/100.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/100.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/101.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/101.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/101.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/101.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/102.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/102.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/102.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/102.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/103.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/103.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/103.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/103.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/104.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/104.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/104.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/104.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/150.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/150.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/150.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/150.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/151.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/151.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/151.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/151.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/152.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/152.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/152.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/152.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/153.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/153.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/153.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/153.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/154.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/154.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/154.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/154.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/300.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/300.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/300.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/300.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/301.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/301.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/301.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/301.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/302.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/302.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/302.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/302.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/303.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/303.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/303.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/303.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/304.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/304.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/304.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/304.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/305.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/305.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/305.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/305.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/306.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/306.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/306.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/306.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/307.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/307.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/307.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/307.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/308.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/308.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/308.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/308.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/309.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/309.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/309.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/309.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/310.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/310.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/310.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/310.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/311.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/311.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/311.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/311.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/312.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/312.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/312.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/312.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/313.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/313.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/313.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/313.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/314.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/314.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/314.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/314.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/315.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/315.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/315.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/315.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/316.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/316.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/316.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/316.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/317.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/317.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/317.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/317.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/318.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/318.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/318.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/318.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/350.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/350.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/350.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/350.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/351.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/351.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/351.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/351.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/399.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/399.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/399.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/399.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/400.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/400.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/400.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/400.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/401.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/401.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/401.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/401.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/402.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/402.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/402.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/402.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/403.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/403.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/403.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/403.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/404.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/404.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/404.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/404.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/405.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/405.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/405.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/405.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/406.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/406.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/406.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/406.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/407.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/407.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/407.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/407.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/408.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/408.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/408.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/408.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/409.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/409.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/409.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/409.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/410.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/410.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/410.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/410.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/456.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/456.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/456.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/456.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/457.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/457.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/457.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/457.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/499.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/499.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/499.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/499.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/500.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/500.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/500.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/500.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/501.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/501.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/501.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/501.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/502.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/502.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/502.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/502.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/503.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/503.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/503.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/503.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/504.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/504.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/504.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/504.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/507.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/507.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/507.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/507.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/508.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/508.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/508.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/508.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/509.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/509.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/509.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/509.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/510.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/510.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/510.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/510.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/511.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/511.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/511.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/511.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/512.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/512.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/512.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/512.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/513.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/513.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/513.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/513.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/514.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/514.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/514.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/514.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/515.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/515.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/515.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/515.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/800.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/800.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/800.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/800.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/801.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/801.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/801.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/801.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/802.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/802.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/802.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/802.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/803.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/803.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/803.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/803.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/804.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/804.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/804.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/804.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/805.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/805.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/805.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/805.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/806.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/806.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/806.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/806.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/807.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/807.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/807.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/807.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/900.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/900.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/900.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/900.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/901.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/901.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/901.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/901.png diff --git a/liteyuki/resources/vanilla_resource/templates/img/qw_icon/999.png b/liteyuki/resources/liteyuki_weather/templates/img/qw_icon/999.png similarity index 100% rename from liteyuki/resources/vanilla_resource/templates/img/qw_icon/999.png rename to liteyuki/resources/liteyuki_weather/templates/img/qw_icon/999.png diff --git a/liteyuki/resources/liteyuki_weather/templates/js/weather_now.js b/liteyuki/resources/liteyuki_weather/templates/js/weather_now.js new file mode 100644 index 00000000..86ce2fc6 --- /dev/null +++ b/liteyuki/resources/liteyuki_weather/templates/js/weather_now.js @@ -0,0 +1,114 @@ +/** + * @typedef {Object} Location + * @property {string} city - The city name. + * @property {string} country - The country name. + * + * @typedef {Object} Weather + * @property {number} temperature - The current temperature. + * @property {string} description - The weather description. + * + * @typedef {Object} Data + * @property {Location} location - The location data. + * @property {Weather} weather - The weather data. + */ + +/** @type {Data} */ + +let data = JSON.parse(document.getElementById("data").innerText) + +let localData = data["localization"] // 本地化数据 + +let weatherNow = data["weatherNow"] + +let weatherDaily = data["weatherDaily"] +let weatherHourly = data["weatherHourly"] +let aqi = data["aqi"] + +let locationData = data["location"] + +// 处理aqi +let aqiValue = 0 +aqi["aqi"].forEach( + (item) => { + if (item["defaultLocalAqi"]) { + document.getElementById("aqi-data").innerText = "AQI " + item["valueDisplay"] + " " + item["category"] + // 将(255,255,255)这种格式的颜色设置给css + document.getElementById("aqi-dot").style.backgroundColor = "rgb(" + item["color"] + ")" + } + } +) + +templates = { + "time": weatherNow["now"]["obsTime"], + "city": locationData["name"], + "adm": locationData["country"] + " " + locationData["adm1"] + " " + locationData["adm2"], + "temperature-now": weatherNow["now"]["temp"] + "°", + "temperature-range": weatherDaily["daily"][0]["tempMin"] + "°/" + weatherDaily["daily"][0]["tempMax"] + "°", + "description": weatherNow["now"]["text"] +} + +// 遍历每一个id,给其赋值 +for (let id in templates) { + document.getElementById(id).innerText = templates[id] +} + +let maxHourlyItem = 8 +let percentWidth = 1 / (maxHourlyItem * 1.5) * 100 +let hourlyStep = 2 // n小时一个数据 +let hourlyCount = 0 +weatherHourly['hourly'].forEach( + (item, index) => { + if (index % hourlyStep !== 0) { + return + } + if (hourlyCount >= maxHourlyItem) { + return + } + + let hourlyItemDiv = document.importNode(document.getElementById("hourly-item-template").content, true) + hourlyItemDiv.className = "hourly-item" + hourlyItemDiv.querySelector('.hourly-icon').setAttribute("src", `./img/qw_icon/${item["icon"]}.png`) + hourlyItemDiv.querySelector('.hourly-time').innerText = get_time_hour(item["fxTime"]) + hourlyItemDiv.querySelector('.hourly-temperature').innerText = " " + item["temp"] + "°" + // 设置最大宽度 + hourlyItemDiv.querySelector('.hourly-item').style.maxWidth = percentWidth + "%" + hourlyItemDiv.querySelector('.hourly-icon').style.maxWidth = "100%" + document.getElementById("hours-info").appendChild(hourlyItemDiv) + hourlyCount++ + } +) + +let maxDailyItem = 7 +// 第一和第二天用today和tomorrow,后面用星期X英文小写 +let daysStandard = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] +let todayDay = new Date().getDay() +let days = [localData['today'], localData['tomorrow']] +for (let i = 0; i < 5; i++) { + days.push(localData[daysStandard[(todayDay + i) % 7]]) +} +weatherDaily['daily'].forEach( + (item, index) => { + if (index >= maxDailyItem) { + return + } + let today = days[index] + if (index >= 2){ + today += `(${item["fxDate"].split("-")[1]}.${item["fxDate"].split("-")[2]})` + } + let dailyItemDiv = document.importNode(document.getElementById("daily-item-template").content, true) + dailyItemDiv.querySelector('.icon-day').setAttribute("src", `./img/qw_icon/${item["iconDay"]}.png`) + dailyItemDiv.querySelector('.icon-night').setAttribute("src", `./img/qw_icon/${item["iconNight"]}.png`) + + dailyItemDiv.querySelector('.daily-day').innerText = today + + dailyItemDiv.querySelector('.daily-weather').innerText = item["textDay"] + dailyItemDiv.querySelector('.daily-temperature').innerText = item["tempMin"] + "°~" + item["tempMax"] + "°" + + document.getElementById('days-info').appendChild(dailyItemDiv) + } +) + +function get_time_hour(fxTime) { +// fxTime 2024-05-03T02:00+08:00' + return fxTime.split("T")[1].split("+")[0] +} \ No newline at end of file diff --git a/liteyuki/resources/liteyuki_weather/templates/weather_now.html b/liteyuki/resources/liteyuki_weather/templates/weather_now.html new file mode 100644 index 00000000..df8bfcb2 --- /dev/null +++ b/liteyuki/resources/liteyuki_weather/templates/weather_now.html @@ -0,0 +1,73 @@ + + + + + Liteyuki Status + + + + + + + + + + +
{{ data | tojson }}
+
+
+
2045-01-12 22:22:22
+
枫丹 白露 白露区
+
白露区
+
+
+
+ WeatherIcon +
+
+
+
+ 90° +
+
+ 10°~90° +
+
+
+ 示例天气 +
+
+
+
+
+
AQI 114 优
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/liteyuki/resources/vanilla_language/lang/de.lang b/liteyuki/resources/vanilla_language/lang/de.lang index 82db1a02..250dabb9 100644 --- a/liteyuki/resources/vanilla_language/lang/de.lang +++ b/liteyuki/resources/vanilla_language/lang/de.lang @@ -156,4 +156,5 @@ status.minutes=Minuten status.seconds=Sekunden status.cores=Kerne status.threads=Threads -status.process=Prozesse \ No newline at end of file +status.process=Prozesse +status.description=Liteyuki Bot-Status \ No newline at end of file diff --git a/liteyuki/resources/vanilla_language/lang/en.lang b/liteyuki/resources/vanilla_language/lang/en.lang index 3649d03e..062bfd4b 100644 --- a/liteyuki/resources/vanilla_language/lang/en.lang +++ b/liteyuki/resources/vanilla_language/lang/en.lang @@ -156,4 +156,5 @@ status.minutes=Minutes status.seconds=Seconds status.cores=Cores status.threads=Threads -status.process=Processes \ No newline at end of file +status.process=Processes +status.description=Liteyuki Dashboard \ No newline at end of file diff --git a/liteyuki/resources/vanilla_language/lang/es.lang b/liteyuki/resources/vanilla_language/lang/es.lang index 4f69d6c4..53620c3a 100644 --- a/liteyuki/resources/vanilla_language/lang/es.lang +++ b/liteyuki/resources/vanilla_language/lang/es.lang @@ -156,4 +156,5 @@ status.minutes=Minutos status.seconds=Segundos status.cores=Núcleos status.threads=Hilos -status.process=Procesos \ No newline at end of file +status.process=Procesos +status.description=Liteyuki Dashboard Status \ No newline at end of file diff --git a/liteyuki/resources/vanilla_language/lang/ja.lang b/liteyuki/resources/vanilla_language/lang/ja.lang index 2dbdac87..2c9a7435 100644 --- a/liteyuki/resources/vanilla_language/lang/ja.lang +++ b/liteyuki/resources/vanilla_language/lang/ja.lang @@ -156,4 +156,5 @@ status.minutes=分 status.seconds=秒 status.cores=コア status.threads=スレッド -status.process=プロセス \ No newline at end of file +status.process=プロセス +status.description=軽雪監視パネル \ No newline at end of file diff --git a/liteyuki/resources/vanilla_language/lang/zh-CN.lang b/liteyuki/resources/vanilla_language/lang/zh-CN.lang index 2b6dfab3..079644f2 100644 --- a/liteyuki/resources/vanilla_language/lang/zh-CN.lang +++ b/liteyuki/resources/vanilla_language/lang/zh-CN.lang @@ -156,4 +156,5 @@ status.minutes=分 status.seconds=秒 status.cores=核心 status.threads=线程 -status.process=进程 \ No newline at end of file +status.process=进程 +status.description=轻雪机器人状态面板 \ No newline at end of file diff --git a/liteyuki/resources/vanilla_resource/templates/css/card.css b/liteyuki/resources/vanilla_resource/templates/css/card.css index d37f9db4..0455d4ab 100644 --- a/liteyuki/resources/vanilla_resource/templates/css/card.css +++ b/liteyuki/resources/vanilla_resource/templates/css/card.css @@ -11,9 +11,15 @@ body { } .info-box { - border-radius: 30px; + border-radius: 50px; padding: 30px; backdrop-filter: blur(10px); background-color: rgba(0, 0, 0, 0.5); margin-bottom: 20px; +} + +#author-description { + text-align: center; + color: var(--sub-text-color); + font-size: 30px; } \ No newline at end of file diff --git a/liteyuki/resources/vanilla_resource/templates/css/status.css b/liteyuki/resources/vanilla_resource/templates/css/status.css index 2f584093..250d3772 100644 --- a/liteyuki/resources/vanilla_resource/templates/css/status.css +++ b/liteyuki/resources/vanilla_resource/templates/css/status.css @@ -1,50 +1,46 @@ :root { --main-text-color: #fff; - --sub-text-color: #bbb; - --tip-text-color: #888; - + --sub-text-color: #ccc; + --tip-text-color: #999; --device-info-width: 240px; } .bot-info { display: flex; - height: 200px; } .bot-icon { display: flex; - height: 100%; - aspect-ratio: 1; + width: 220px; align-items: center; justify-content: center; margin-right: 20px; } .bot-icon-img { + height: 220px; border-radius: 50%; - height: 100%; - width: 100%; background-color: white; } .bot-name { color: var(--main-text-color); display: flex; - font-size: 40px; + font-size: 45px; flex-direction: column; justify-content: center; } .bot-tag { - white-space: nowrap; + white-space: break-spaces; color: var(--sub-text-color); - font-size: 27px; + font-size: 30px; font-weight: 700; line-height: 1.6; } .bot-tag[suffix="1"]::after { - content: " | "; + content: "|"; display: inline-block; margin: 0 5px; height: 30%; @@ -127,4 +123,5 @@ font-style: italic; color: var(--sub-text-color); text-align: right; -} \ No newline at end of file +} + diff --git a/liteyuki/resources/vanilla_resource/templates/css/weather_now.css b/liteyuki/resources/vanilla_resource/templates/css/weather_now.css deleted file mode 100644 index 143f7b8a..00000000 --- a/liteyuki/resources/vanilla_resource/templates/css/weather_now.css +++ /dev/null @@ -1,83 +0,0 @@ -#weather-info { - color: white; - /*justify-content: center;*/ - /*align-items: center;*/ - /*align-content: center;*/ -} - -#main-info { - display: flex; - justify-content: center; - align-items: center; -} - -#time { - font-size: 25px; - font-weight: bold; - font-style: italic; - text-align: right; - color: #aaa; - -} - -#adm { - font-size: 30px; - font-weight: bold; - text-align: center; - color: #aaa; -} - -#city { - margin-top: 20px; - font-size: 70px; - font-weight: bold; - text-align: center; -} - -#temperature { - display: flex; - align-items: baseline; - -} - -#temperature-now { - font-size: 70px; - font-weight: bold; -} - -#temperature-range { - font-size: 40px; - font-weight: bold; - color: #aaa; -} - -#description { - font-size: 50px; - font-weight: bold; -} - - -#aqi { - height: 50px; - display: flex; - border-radius: 60px; - padding: 5px; - font-size: 40px; - text-align: center; - align-content: center; - align-items: center; - justify-content: center; -} - -#aqi-dot { - height: 80%; - aspect-ratio: 1 / 1; - border-radius: 50%; - background-color: #aaa; - margin-right: 20px; -} - -.main-icon { - width: 240px; - height: 240px; -} \ No newline at end of file diff --git a/liteyuki/resources/vanilla_resource/templates/js/card.js b/liteyuki/resources/vanilla_resource/templates/js/card.js index e2f31c21..2974c9cb 100644 --- a/liteyuki/resources/vanilla_resource/templates/js/card.js +++ b/liteyuki/resources/vanilla_resource/templates/js/card.js @@ -9,3 +9,9 @@ const bgs = [ ] // 随机选择背景图片 document.body.style.backgroundImage = `url(./img/${bgs[Math.floor(Math.random() * bgs.length)]})`; +// body后插入info-box id=description +let descriptionDiv = document.createElement("div"); +descriptionDiv.className = 'info-box' +descriptionDiv.id = 'author-description' +descriptionDiv.innerText = 'Designed by SnowyKami' +document.body.appendChild(descriptionDiv); diff --git a/liteyuki/resources/vanilla_resource/templates/js/status.js b/liteyuki/resources/vanilla_resource/templates/js/status.js index 11a3f6a5..4930016c 100644 --- a/liteyuki/resources/vanilla_resource/templates/js/status.js +++ b/liteyuki/resources/vanilla_resource/templates/js/status.js @@ -290,6 +290,8 @@ function main() { document.getElementById('motto-text').innerText = mottoText document.getElementById('motto-from').innerText = mottoFrom + document.getElementById('author-description').innerText = localData['description'] + ' Powered by Liteyuki' + } diff --git a/liteyuki/resources/vanilla_resource/templates/js/weather_now.js b/liteyuki/resources/vanilla_resource/templates/js/weather_now.js deleted file mode 100644 index e3ab5461..00000000 --- a/liteyuki/resources/vanilla_resource/templates/js/weather_now.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @typedef {Object} Location - * @property {string} city - The city name. - * @property {string} country - The country name. - * - * @typedef {Object} Weather - * @property {number} temperature - The current temperature. - * @property {string} description - The weather description. - * - * @typedef {Object} Data - * @property {Location} location - The location data. - * @property {Weather} weather - The weather data. - */ - -/** @type {Data} */ - -let data = JSON.parse(document.getElementById("data").innerText) - -let weatherNow = data["weatherNow"] - -let weatherDaily = data["weatherDaily"] -let weatherHourly = data["weatherHourly"] -let aqi = data["aqi"] - -let locationData = data["location"] - -// set info -// document.getElementById("time").innerText = weatherNow["now"]["obsTime"] -// document.getElementById("city").innerText = locationData["name"] -// document.getElementById("adm").innerText = locationData["country"] + " " + locationData["adm1"] + " " + locationData["adm2"] -// document.getElementById("temperature-now").innerText = weatherNow["now"]["temp"] + "°" -// document.getElementById("temperature-range").innerText = weatherNow["now"]["feelsLike"] + "°" -// document.getElementById("description").innerText = weatherNow["now"]["text"] -// 处理aqi -let aqiValue = 0 -aqi["aqi"].forEach( - (item) => { - if (item["defaultLocalAqi"]) { - document.getElementById("aqi-data").innerText = "AQI " + item["valueDisplay"] + " " + item["category"] - // 将(255,255,255)这种格式的颜色设置给css - document.getElementById("aqi-dot").style.backgroundColor = "rgb(" + item["color"] + ")" - } - } -) - -templates = { - "time": weatherNow["now"]["obsTime"], - "city": locationData["name"], - "adm": locationData["country"] + " " + locationData["adm1"] + " " + locationData["adm2"], - "temperature-now": weatherNow["now"]["temp"] + "°", - "temperature-range": weatherDaily["daily"][0]["tempMin"] + "°/" + weatherDaily["daily"][0]["tempMax"] + "°", - "description": weatherNow["now"]["text"] -} - -// 遍历每一个id,给其赋值 - -for (let id in templates) { - document.getElementById(id).innerText = templates[id] -} \ No newline at end of file diff --git a/liteyuki/resources/vanilla_resource/templates/weather_now.html b/liteyuki/resources/vanilla_resource/templates/weather_now.html deleted file mode 100644 index acc64baa..00000000 --- a/liteyuki/resources/vanilla_resource/templates/weather_now.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - Liteyuki Status - - - - - - -
{{ data | tojson }}
-
-
-
1145-01-12 22:22:22
-
国家 一级 二级
-
城市
-
-
-
- AAA -
-
-
-
- 90° -
-
- 10°~90° -
-
-
- 好天气 -
-
-
-
-
-
AQI 114 优
-
-
-
-
-
- - - - \ No newline at end of file diff --git a/liteyuki/utils/__init__.py b/liteyuki/utils/__init__.py index 5429b881..9fb0b59f 100644 --- a/liteyuki/utils/__init__.py +++ b/liteyuki/utils/__init__.py @@ -58,7 +58,7 @@ def init(): exit(1) temp_data: TempConfig = common_db.first(TempConfig(), default=TempConfig()) temp_data.data["start_time"] = time.time() - common_db.upsert(temp_data) + common_db.save(temp_data) # 在加载完成语言后再初始化日志 nonebot.logger.info("Liteyuki is initializing...") diff --git a/liteyuki/utils/base/config.py b/liteyuki/utils/base/config.py index 943909fb..2ffd6cea 100644 --- a/liteyuki/utils/base/config.py +++ b/liteyuki/utils/base/config.py @@ -4,7 +4,7 @@ import nonebot import yaml from pydantic import BaseModel -from .data_manager import StoredConfig, common_db +from .data_manager import StoredConfig, TempConfig, common_db from .ly_typing import T_Bot from ..message.tools import random_hex_string @@ -64,6 +64,12 @@ def get_config(key: str, default=None): return default +def set_stored_config(key: str, value): + temp_config: TempConfig = common_db.first(TempConfig(), default=TempConfig()) + temp_config.data[key] = value + common_db.save(temp_config) + + def init_conf(conf: dict) -> dict: """ 初始化配置文件,确保配置文件中的必要字段存在,且不会冲突 diff --git a/liteyuki/utils/base/data.py b/liteyuki/utils/base/data.py index abca80ac..f5dd6e21 100644 --- a/liteyuki/utils/base/data.py +++ b/liteyuki/utils/base/data.py @@ -78,7 +78,7 @@ class Database: else: return [model_type(**self._load(dict(zip(fields, result)))) for result in results] - def upsert(self, *args: LiteModel): + def save(self, *args: LiteModel): """增/改操作 Args: *args: diff --git a/liteyuki/utils/base/data_manager.py b/liteyuki/utils/base/data_manager.py index 2a737cde..35bb2a10 100644 --- a/liteyuki/utils/base/data_manager.py +++ b/liteyuki/utils/base/data_manager.py @@ -11,6 +11,11 @@ group_db: Database = Database(os.path.join(DATA_PATH, "groups.ldb")) plugin_db: Database = Database(os.path.join(DATA_PATH, "plugins.ldb")) common_db: Database = Database(os.path.join(DATA_PATH, "common.ldb")) +# 内存数据库,临时用于存储数据 +memory_database = { + +} + class User(LiteModel): TABLE_NAME = "user" @@ -60,3 +65,31 @@ def auto_migrate(): group_db.auto_migrate(Group()) plugin_db.auto_migrate(InstalledPlugin(), GlobalPlugin()) common_db.auto_migrate(GlobalPlugin(), StoredConfig(), TempConfig()) + + +def set_memory_data(key: str, value) -> None: + """ + 设置内存数据库的数据,类似于redis + Args: + key: + value: + + Returns: + + """ + return memory_database.update({ + key: value + }) + + +def get_memory_data(key: str, default=None) -> any: + """ + 获取内存数据库的数据,类似于redis + Args: + key: + default: + + Returns: + + """ + return memory_database.get(key, default) diff --git a/liteyuki/utils/base/language.py b/liteyuki/utils/base/language.py index cf28bd06..3e709f89 100644 --- a/liteyuki/utils/base/language.py +++ b/liteyuki/utils/base/language.py @@ -149,7 +149,7 @@ def change_user_lang(user_id: str, lang_code: str): """ user = user_db.first(User(), "user_id = ?", user_id, default=User(user_id=user_id)) user.profile["lang"] = lang_code - user_db.upsert(user) + user_db.save(user) _user_lang[user_id] = lang_code @@ -160,6 +160,7 @@ def get_user_lang(user_id: str) -> Language: user_id = str(user_id) if user_id not in _user_lang: + nonebot.logger.debug(f"Loading user language for {user_id}") user = user_db.first( User(), "user_id = ?", user_id, default=User( user_id=user_id, diff --git a/liteyuki/utils/base/ly_typing.py b/liteyuki/utils/base/ly_typing.py index 102e8c9f..4a164337 100644 --- a/liteyuki/utils/base/ly_typing.py +++ b/liteyuki/utils/base/ly_typing.py @@ -4,4 +4,4 @@ T_Bot = v11.Bot | v12.Bot T_GroupMessageEvent = v11.GroupMessageEvent | v12.GroupMessageEvent T_PrivateMessageEvent = v11.PrivateMessageEvent | v12.PrivateMessageEvent T_MessageEvent = v11.MessageEvent | v12.MessageEvent -T_Message = v11.Message | v12.Message \ No newline at end of file +T_Message = v11.Message | v12.Message diff --git a/liteyuki/utils/message/html_tool.py b/liteyuki/utils/message/html_tool.py index 4a0a01e3..1cb1e4d1 100644 --- a/liteyuki/utils/message/html_tool.py +++ b/liteyuki/utils/message/html_tool.py @@ -13,6 +13,13 @@ require("nonebot_plugin_htmlrender") from nonebot_plugin_htmlrender import * +async def html2image( + html: str, + wait: int = 0, +): + pass + + async def template2html( template: str, templates: dict, @@ -62,7 +69,6 @@ async def template2image( if debug: # 重载资源 - raw_html = await template_to_html( template_name=template_name, template_path=template_path, @@ -109,4 +115,3 @@ async def url2image( type=type, quality=quality ) -