From 322ad1988972da7e0393f334ca527396a6658ff1 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 14:18:55 +0800 Subject: [PATCH 01/13] =?UTF-8?q?:bug:=20=E5=9C=A8=E4=BD=BF=E7=94=A8=20sat?= =?UTF-8?q?ori=20=E6=97=B6=E9=83=A8=E5=88=86=E6=8C=87=E4=BB=A4=E6=97=A0?= =?UTF-8?q?=E5=93=8D=E5=BA=94=20:bug:=20=E4=BD=BF=E7=94=A8=20onebot=20?= =?UTF-8?q?=E6=97=B6=E9=83=A8=E5=88=86=E4=BA=8B=E4=BB=B6=E5=9C=A8=20postpr?= =?UTF-8?q?ocessor=20=E9=98=B6=E6=AE=B5=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/liteyuki_statistics/stat_monitors.py | 14 +++++++++----- liteyuki/utils/base/ly_typing.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/liteyuki/plugins/liteyuki_statistics/stat_monitors.py b/liteyuki/plugins/liteyuki_statistics/stat_monitors.py index 63b20009..f66f15c4 100644 --- a/liteyuki/plugins/liteyuki_statistics/stat_monitors.py +++ b/liteyuki/plugins/liteyuki_statistics/stat_monitors.py @@ -14,14 +14,17 @@ from liteyuki.utils import satori_utils require("nonebot_plugin_alconna") -@event_postprocessor async def general_event_monitor(bot: T_Bot, event: T_MessageEvent): - if isinstance(bot, satori.Bot): - return await satori_event_monitor(bot, event) - elif isinstance(bot, v11.Bot): - return await onebot_v11_event_monitor(bot, event) + print("POST PROCESS") + # if isinstance(bot, satori.Bot): + # print("POST PROCESS SATORI EVENT") + # return await satori_event_monitor(bot, event) + # elif isinstance(bot, v11.Bot): + # print("POST PROCESS V11 EVENT") + # return await onebot_v11_event_monitor(bot, event) +@event_postprocessor async def onebot_v11_event_monitor(bot: v11.Bot, event: v11.MessageEvent): if event.message_type == "group": event: v11.GroupMessageEvent @@ -44,6 +47,7 @@ async def onebot_v11_event_monitor(bot: v11.Bot, event: v11.MessageEvent): msg_db.save(mem) +@event_postprocessor async def satori_event_monitor(bot: satori.Bot, event: satori.MessageEvent): if event.guild is not None: event: satori.MessageEvent diff --git a/liteyuki/utils/base/ly_typing.py b/liteyuki/utils/base/ly_typing.py index c13ce309..31242e18 100644 --- a/liteyuki/utils/base/ly_typing.py +++ b/liteyuki/utils/base/ly_typing.py @@ -4,5 +4,5 @@ from nonebot.adapters import satori T_Bot = v11.Bot | v12.Bot | satori.Bot T_GroupMessageEvent = v11.GroupMessageEvent | v12.GroupMessageEvent T_PrivateMessageEvent = v11.PrivateMessageEvent | v12.PrivateMessageEvent -T_MessageEvent = v11.MessageEvent | v12.MessageEvent # | satori.MessageEvent +T_MessageEvent = v11.MessageEvent | v12.MessageEvent | satori.MessageEvent T_Message = v11.Message | v12.Message | satori.Message From 077658c68d9c542ab135f4da23b6e353cae37eaf Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 14:42:37 +0800 Subject: [PATCH 02/13] =?UTF-8?q?:pencil:=20=E5=B0=86=20Satori=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=BC=93=E5=AD=98=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=9A=84=E8=BE=93=E5=87=BA=E6=97=B6=E6=9C=BA=E7=94=B1=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84=E6=AF=8F=E6=AC=A1=E8=B0=83=E7=94=A8=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=B0=83=E6=95=B4=E4=B8=BA=E6=AF=8F=E6=AC=A1=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E5=8F=91=E7=94=9F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteyuki_satori_user_info/auto_update.py | 8 ++--- liteyuki/utils/satori_utils/user_info.py | 30 +++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py b/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py index 08080f44..8b6199e3 100644 --- a/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py +++ b/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py @@ -1,3 +1,5 @@ +import nonebot + from liteyuki.utils import satori_utils from nonebot.message import event_preprocessor # from nonebot_plugin_alconna.typings import Event @@ -10,13 +12,11 @@ from liteyuki.plugins.liteyuki_status.counter_for_satori import satori_counter @event_preprocessor async def pre_handle(event: Event): - print("UPDATE_USER") - print(event.__dict__) if isinstance(event, satori.MessageEvent): if event.user.id == event.self_id: satori_counter.msg_sent += 1 else: satori_counter.msg_received += 1 if event.user.name is not None: - await satori_utils.user_infos.put(event.user) - print(event.user) + if await satori_utils.user_infos.put(event.user): + nonebot.logger.info(f"Satori user {event.user.name}<{event.user.id}> updated") diff --git a/liteyuki/utils/satori_utils/user_info.py b/liteyuki/utils/satori_utils/user_info.py index f4b9b4b0..6500e719 100644 --- a/liteyuki/utils/satori_utils/user_info.py +++ b/liteyuki/utils/satori_utils/user_info.py @@ -28,8 +28,34 @@ class UserInfo: except KeyError: return None - async def put(self, user: User): - self.user_infos[str(user.id)] = user + async def put(self, user: User) -> bool: + """ + 向用户信息数据库中添加/修改一项,返回值仅代表数据是否变更,不代表操作是否成功 + Args: + user: 要加入数据库的用户 + + Returns: 当数据库中用户信息发生变化时返回 True, 否则返回 False + + """ + try: + old_user: User = self.user_infos[str(user.id)] + attr_edited = False + if user.name is not None: + if old_user.name != user.name: + attr_edited = True + self.user_infos[str(user.id)].name = user.name + if user.nick is not None: + if old_user.nick != user.nick: + attr_edited = True + self.user_infos[str(user.id)].nick = user.nick + if user.avatar is not None: + if old_user.avatar != user.avatar: + attr_edited = True + self.user_infos[str(user.id)].avatar = user.avatar + return attr_edited + except KeyError: + self.user_infos[str(user.id)] = user + return True def __init__(self): pass From 309397b72ce8898323e63bb4d55fe85a7d2e6f69 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 15:00:01 +0800 Subject: [PATCH 03/13] =?UTF-8?q?:pencil:=20=E5=B0=86=E4=BB=8E=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E8=8E=B7=E5=8F=96=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0=E7=A7=BB=E5=8A=A8=E5=88=B0?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E7=9A=84=20utils.event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/liteyuki_main/core.py | 8 ++++---- liteyuki/plugins/liteyuki_pacman/common.py | 18 +++++++++--------- .../liteyuki_satori_user_info/auto_update.py | 1 - .../liteyuki_statistics/stat_matchers.py | 10 +++++----- .../liteyuki_statistics/stat_monitors.py | 4 ++-- liteyuki/plugins/liteyuki_status/status.py | 6 +++--- .../plugins/liteyuki_user/profile_manager.py | 10 +++++----- liteyuki/plugins/liteyuki_weather/qweather.py | 6 +++--- liteyuki/utils/event/__init__.py | 1 + .../event_tools.py => event/get_info.py} | 7 +++++++ liteyuki/utils/satori_utils/__init__.py | 2 -- .../utils/satori_utils/get_message_type.py | 10 ---------- 12 files changed, 39 insertions(+), 44 deletions(-) create mode 100644 liteyuki/utils/event/__init__.py rename liteyuki/utils/{satori_utils/event_tools.py => event/get_info.py} (66%) delete mode 100644 liteyuki/utils/satori_utils/get_message_type.py diff --git a/liteyuki/liteyuki_main/core.py b/liteyuki/liteyuki_main/core.py index ae0c70d4..4bbdfb61 100644 --- a/liteyuki/liteyuki_main/core.py +++ b/liteyuki/liteyuki_main/core.py @@ -17,7 +17,7 @@ from liteyuki.utils.base.language import get_user_lang from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent from liteyuki.utils.message.message import MarkdownMessage as md, broadcast_to_superusers from liteyuki.utils.base.reloader import Reloader -from liteyuki.utils import satori_utils +from liteyuki.utils import event as event_utils, satori_utils from .api import update_liteyuki require("nonebot_plugin_alconna") @@ -83,7 +83,7 @@ async def _(matcher: Matcher, bot: T_Bot, event: T_MessageEvent): "reload": True, "reload_time": time.time(), "reload_bot_id": bot.self_id, - "reload_session_type": satori_utils.get_message_type(event), + "reload_session_type": event_utils.get_message_type(event), "reload_session_id": (event.group_id if event.message_type == "group" else event.user_id) if not isinstance(event,satori.event.Event) else event.channel.id, "delta_time": 0 } @@ -118,7 +118,7 @@ async def _(matcher: Matcher, bot: T_Bot, event: T_MessageEvent): ).handle() # Satori OK async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot, matcher: Matcher): - ulang = get_user_lang(str(satori_utils.get_user_id(event))) + ulang = get_user_lang(str(event_utils.get_user_id(event))) stored_config: StoredConfig = common_db.where_one(StoredConfig(), default=StoredConfig()) if result.subcommands.get("set"): key, value = result.subcommands.get("set").args.get("key"), result.subcommands.get("set").args.get("value") @@ -168,7 +168,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot, matcher: Matcher async def _(event: T_MessageEvent, matcher: Matcher): global markdown_image # 切换图片模式,False以图片形式发送,True以markdown形式发送 - ulang = get_user_lang(str(satori_utils.get_user_id(event))) + ulang = get_user_lang(str(event_utils.get_user_id(event))) stored_config: StoredConfig = common_db.where_one(StoredConfig(), default=StoredConfig()) stored_config.config["markdown_image"] = not stored_config.config.get("markdown_image", False) markdown_image = stored_config.config["markdown_image"] diff --git a/liteyuki/plugins/liteyuki_pacman/common.py b/liteyuki/plugins/liteyuki_pacman/common.py index 519a0cf0..203ecc5d 100644 --- a/liteyuki/plugins/liteyuki_pacman/common.py +++ b/liteyuki/plugins/liteyuki_pacman/common.py @@ -5,7 +5,7 @@ import aiofiles import nonebot.plugin from nonebot.adapters import satori -from liteyuki.utils import satori_utils +from liteyuki.utils import event as event_utils from liteyuki.utils.base.data import LiteModel from liteyuki.utils.base.data_manager import GlobalPlugin, Group, User, group_db, plugin_db, user_db from liteyuki.utils.base.ly_typing import T_MessageEvent @@ -140,12 +140,12 @@ def set_plugin_session_enable(event: T_MessageEvent, plugin_name: str, enable: b Returns: """ - if satori_utils.get_message_type(event) == "group": - session = group_db.where_one(Group(), "group_id = ?", str(satori_utils.get_group_id(event)), - default=Group(group_id=str(satori_utils.get_group_id(event)))) + if event_utils.get_message_type(event) == "group": + session = group_db.where_one(Group(), "group_id = ?", str(event_utils.get_group_id(event)), + default=Group(group_id=str(event_utils.get_group_id(event)))) else: - session = user_db.where_one(User(), "user_id = ?", str(satori_utils.get_user_id(event)), - default=User(user_id=str(satori_utils.get_user_id(event)))) + session = user_db.where_one(User(), "user_id = ?", str(event_utils.get_user_id(event)), + default=User(user_id=str(event_utils.get_user_id(event)))) default_enable = get_plugin_default_enable(plugin_name) if default_enable: if enable: @@ -158,12 +158,12 @@ def set_plugin_session_enable(event: T_MessageEvent, plugin_name: str, enable: b else: session.enabled_plugins.remove(plugin_name) - if satori_utils.get_message_type(event) == "group": - __group_data[str(satori_utils.get_group_id(event))] = session + if event_utils.get_message_type(event) == "group": + __group_data[str(event_utils.get_group_id(event))] = session print(session) group_db.save(session) else: - __user_data[str(satori_utils.get_user_id(event))] = session + __user_data[str(event_utils.get_user_id(event))] = session user_db.save(session) diff --git a/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py b/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py index 8b6199e3..a611d758 100644 --- a/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py +++ b/liteyuki/plugins/liteyuki_satori_user_info/auto_update.py @@ -1,6 +1,5 @@ import nonebot -from liteyuki.utils import satori_utils from nonebot.message import event_preprocessor # from nonebot_plugin_alconna.typings import Event from liteyuki.utils.base.ly_typing import T_MessageEvent diff --git a/liteyuki/plugins/liteyuki_statistics/stat_matchers.py b/liteyuki/plugins/liteyuki_statistics/stat_matchers.py index 582043ad..2dac3c88 100644 --- a/liteyuki/plugins/liteyuki_statistics/stat_matchers.py +++ b/liteyuki/plugins/liteyuki_statistics/stat_matchers.py @@ -1,9 +1,9 @@ from nonebot import Bot, require from liteyuki.utils.message.npl import convert_duration, convert_time_to_seconds from .stat_api import * -from ...utils import satori_utils -from ...utils.base.language import Language -from ...utils.base.ly_typing import T_MessageEvent +from liteyuki.utils import event as event_utils +from liteyuki.utils.base.language import Language +from liteyuki.utils.base.ly_typing import T_MessageEvent require("nonebot_plugin_alconna") @@ -45,7 +45,7 @@ stat_msg = on_alconna( @stat_msg.assign("message") async def _(result: Arparma, event: T_MessageEvent, bot: Bot): - ulang = Language(satori_utils.get_user_id(event)) + ulang = Language(event_utils.get_user_id(event)) try: duration = convert_time_to_seconds(result.other_args.get("duration", "2d")) # 秒数 @@ -58,7 +58,7 @@ async def _(result: Arparma, event: T_MessageEvent, bot: Bot): bot_id = result.other_args.get("bot_id") if group_id in ["current", "c"]: - group_id = str(satori_utils.get_group_id(event)) + group_id = str(event_utils.get_group_id(event)) if group_id in ["all", "a"]: group_id = "all" diff --git a/liteyuki/plugins/liteyuki_statistics/stat_monitors.py b/liteyuki/plugins/liteyuki_statistics/stat_monitors.py index f66f15c4..27d82256 100644 --- a/liteyuki/plugins/liteyuki_statistics/stat_monitors.py +++ b/liteyuki/plugins/liteyuki_statistics/stat_monitors.py @@ -9,7 +9,7 @@ from liteyuki.utils.base.ly_typing import v11, satori from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent from .common import MessageEventModel, msg_db -from liteyuki.utils import satori_utils +from liteyuki.utils import event as event_utils require("nonebot_plugin_alconna") @@ -64,6 +64,6 @@ async def satori_event_monitor(bot: satori.Bot, event: satori.MessageEvent): message_id=str(event.message.id), message=event.message, message_text=event.message.content, - message_type=satori_utils.get_message_type(event), + message_type=event_utils.get_message_type(event), ) msg_db.save(mem) diff --git a/liteyuki/plugins/liteyuki_status/status.py b/liteyuki/plugins/liteyuki_status/status.py index 23a43a0d..7478d125 100644 --- a/liteyuki/plugins/liteyuki_status/status.py +++ b/liteyuki/plugins/liteyuki_status/status.py @@ -4,8 +4,8 @@ from liteyuki.utils.base.resource import get_path from liteyuki.utils.message.html_tool import template2image from liteyuki.utils.base.language import get_user_lang from .api import * -from ...utils import satori_utils -from ...utils.base.ly_typing import T_Bot, T_MessageEvent +from liteyuki.utils import event as event_utils +from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent require("nonebot_plugin_alconna") from nonebot_plugin_alconna import on_alconna, Alconna, Args, Subcommand, Arparma, UniMessage @@ -28,7 +28,7 @@ status_alc = on_alconna( @status_alc.handle() async def _(event: T_MessageEvent, bot: T_Bot): - ulang = get_user_lang(satori_utils.get_user_id(event)) + ulang = get_user_lang(event_utils.get_user_id(event)) if ulang.lang_code in status_card_cache: image = status_card_cache[ulang.lang_code] else: diff --git a/liteyuki/plugins/liteyuki_user/profile_manager.py b/liteyuki/plugins/liteyuki_user/profile_manager.py index bb6c1620..2688fa14 100644 --- a/liteyuki/plugins/liteyuki_user/profile_manager.py +++ b/liteyuki/plugins/liteyuki_user/profile_manager.py @@ -9,7 +9,7 @@ from liteyuki.utils.base.language import Language, change_user_lang, get_all_lan from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent from liteyuki.utils.message.message import MarkdownMessage as md from .const import representative_timezones_list -from ...utils import satori_utils +from liteyuki.utils import event as event_utils require("nonebot_plugin_alconna") from nonebot_plugin_alconna import Alconna, Args, Arparma, Subcommand, on_alconna @@ -42,13 +42,13 @@ class Profile(LiteModel): @profile_alc.handle() async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot): - user: User = user_db.where_one(User(), "user_id = ?", satori_utils.get_user_id(event), - default=User(user_id=str(satori_utils.get_user_id(event)))) - ulang = get_user_lang(str(satori_utils.get_user_id(event))) + user: User = user_db.where_one(User(), "user_id = ?", event_utils.get_user_id(event), + default=User(user_id=str(event_utils.get_user_id(event)))) + ulang = get_user_lang(str(event_utils.get_user_id(event))) if result.subcommands.get("set"): if result.subcommands["set"].args.get("value"): # 对合法性进行校验后设置 - r = set_profile(result.args["key"], result.args["value"], str(satori_utils.get_user_id(event))) + r = set_profile(result.args["key"], result.args["value"], str(event_utils.get_user_id(event))) if r: user.profile[result.args["key"]] = result.args["value"] user_db.save(user) # 数据库保存 diff --git a/liteyuki/plugins/liteyuki_weather/qweather.py b/liteyuki/plugins/liteyuki_weather/qweather.py index 7d55f707..77490635 100644 --- a/liteyuki/plugins/liteyuki_weather/qweather.py +++ b/liteyuki/plugins/liteyuki_weather/qweather.py @@ -11,7 +11,7 @@ from liteyuki.utils.base.data_manager import User, user_db 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 -from ...utils import satori_utils +from liteyuki.utils import event as event_utils require("nonebot_plugin_alconna") from nonebot_plugin_alconna import on_alconna, Alconna, Args, MultiVar, Arparma @@ -43,11 +43,11 @@ async def _(event: T_MessageEvent, matcher: Matcher): async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword: list[str], tip: bool = True): - ulang = get_user_lang(satori_utils.get_user_id(event)) + ulang = get_user_lang(event_utils.get_user_id(event)) qw_lang = get_qw_lang(ulang.lang_code) key = get_config("weather_key") is_dev = get_memory_data("weather.is_dev", True) - user: User = user_db.where_one(User(), "user_id = ?", satori_utils.get_user_id(event), default=User()) + user: User = user_db.where_one(User(), "user_id = ?", event_utils.get_user_id(event), default=User()) # params unit = user.profile.get("unit", "m") stored_location = user.profile.get("location", None) diff --git a/liteyuki/utils/event/__init__.py b/liteyuki/utils/event/__init__.py new file mode 100644 index 00000000..b028cac6 --- /dev/null +++ b/liteyuki/utils/event/__init__.py @@ -0,0 +1 @@ +from .get_info import * diff --git a/liteyuki/utils/satori_utils/event_tools.py b/liteyuki/utils/event/get_info.py similarity index 66% rename from liteyuki/utils/satori_utils/event_tools.py rename to liteyuki/utils/event/get_info.py index dbc94234..d6fa5695 100644 --- a/liteyuki/utils/satori_utils/event_tools.py +++ b/liteyuki/utils/event/get_info.py @@ -15,3 +15,10 @@ def get_group_id(event: T_MessageEvent): return event.guild.id else: return event.group_id + + +def get_message_type(event: T_MessageEvent) -> str: + if isinstance(event, satori.event.Event): + return "private" if event.guild is None else "group" + else: + return event.message_type diff --git a/liteyuki/utils/satori_utils/__init__.py b/liteyuki/utils/satori_utils/__init__.py index b0f1550f..192714bb 100644 --- a/liteyuki/utils/satori_utils/__init__.py +++ b/liteyuki/utils/satori_utils/__init__.py @@ -1,5 +1,3 @@ from .user_info import user_infos -from .get_message_type import get_message_type -from .event_tools import * from .count_friends import count_friends from .count_groups import count_groups diff --git a/liteyuki/utils/satori_utils/get_message_type.py b/liteyuki/utils/satori_utils/get_message_type.py deleted file mode 100644 index df5ab604..00000000 --- a/liteyuki/utils/satori_utils/get_message_type.py +++ /dev/null @@ -1,10 +0,0 @@ -from nonebot.adapters import satori - -from liteyuki.utils.base.ly_typing import T_MessageEvent - - -def get_message_type(event: T_MessageEvent) -> str: - if isinstance(event, satori.event.Event): - return "private" if event.guild is None else "group" - else: - return event.message_type From a72eeb4c3f30e3a20ff51ef6465b09d62b626d49 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 16:26:30 +0800 Subject: [PATCH 04/13] =?UTF-8?q?:pencil:=20=E4=BD=BF=E7=94=A8=20driver=5F?= =?UTF-8?q?manager=E8=87=AA=E5=8A=A8=E7=AE=A1=E7=90=86=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=A9=B1=E5=8A=A8=E5=99=A8=EF=BC=8C=E6=97=A0=E9=9C=80?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E9=85=8D=E7=BD=AE=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=20(=E5=BD=93=E9=85=8D=E7=BD=AE=E4=BA=86=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E6=97=B6=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E4=BC=98=E5=85=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/driver_manager/__init__.py | 6 ++++++ liteyuki/driver_manager/auto_set_env.py | 20 ++++++++++++++++++++ liteyuki/driver_manager/defines.py | 17 +++++++++++++++++ main.py | 4 +++- requirements.txt | 4 ++++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 liteyuki/driver_manager/__init__.py create mode 100644 liteyuki/driver_manager/auto_set_env.py create mode 100644 liteyuki/driver_manager/defines.py diff --git a/liteyuki/driver_manager/__init__.py b/liteyuki/driver_manager/__init__.py new file mode 100644 index 00000000..89d90097 --- /dev/null +++ b/liteyuki/driver_manager/__init__.py @@ -0,0 +1,6 @@ +from .auto_set_env import auto_set_env + + +def init(config: dict): + auto_set_env(config) + return diff --git a/liteyuki/driver_manager/auto_set_env.py b/liteyuki/driver_manager/auto_set_env.py new file mode 100644 index 00000000..2568d80f --- /dev/null +++ b/liteyuki/driver_manager/auto_set_env.py @@ -0,0 +1,20 @@ +import os + +import dotenv +import nonebot + +from .defines import * + + +def auto_set_env(config: dict): + dotenv.load_dotenv() + if os.getenv("DRIVER", None) is not None: + nonebot.logger.info("Driver already set in environment variable, skip auto configure.") + return + if config.get("enable_satori", False): + os.environ["DRIVER"] = get_driver_string(ASGI_DRIVER, HTTPX_DRIVER, WEBSOCKETS_DRIVER) + nonebot.logger.info("Enable Satori, set driver to ASGI+HTTPX+WEBSOCKETS") + else: + os.environ["DRIVER"] = get_driver_string(ASGI_DRIVER) + nonebot.logger.info("Disable Satori, set driver to ASGI") + return diff --git a/liteyuki/driver_manager/defines.py b/liteyuki/driver_manager/defines.py new file mode 100644 index 00000000..b4756bf5 --- /dev/null +++ b/liteyuki/driver_manager/defines.py @@ -0,0 +1,17 @@ +ASGI_DRIVER = "~fastapi" +HTTPX_DRIVER = "~httpx" +WEBSOCKETS_DRIVER = "~websockets" + + +def get_driver_string(*argv): + output_string = "" + if ASGI_DRIVER in argv: + output_string += ASGI_DRIVER + for arg in argv: + if arg != ASGI_DRIVER: + output_string = f"{output_string}+{arg}" + return output_string + + +def get_driver_full_string(*argv): + return f"DRIVER={get_driver_string(argv)}" diff --git a/main.py b/main.py index b332f58c..9e7f152b 100644 --- a/main.py +++ b/main.py @@ -5,12 +5,14 @@ from liteyuki.utils import init from liteyuki.utils.base.config import load_from_yaml from liteyuki.utils.base.data_manager import StoredConfig, common_db from liteyuki.utils.base.ly_api import liteyuki_api +from liteyuki import driver_manager if __name__ == "__mp_main__": init() store_config: dict = common_db.where_one(StoredConfig(), default=StoredConfig()).config static_config = load_from_yaml("config.yml") store_config.update(static_config) + driver_manager.init(config=store_config) nonebot.init(**store_config) if not store_config.get("enable_satori", False): @@ -18,7 +20,7 @@ if __name__ == "__mp_main__": else: adapters = [v11.Adapter, v12.Adapter, satori.Adapter] driver = nonebot.get_driver() - + # print(driver.__dict__) for adapter in adapters: driver.register_adapter(adapter) diff --git a/requirements.txt b/requirements.txt index 960afaad..b7b74933 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,7 @@ importlib_metadata~=7.0.2 requests~=2.31.0 watchdog~=4.0.0 pillow~=10.2.0 + +pip~=23.2.1 +fastapi~=0.110.0 +python-dotenv~=1.0.1 \ No newline at end of file From 6509b293db442282176b0719a1b45a0ee631f651 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 16:33:48 +0800 Subject: [PATCH 05/13] =?UTF-8?q?:pencil:=20=E4=BD=BF=E7=94=A8=20driver=5F?= =?UTF-8?q?manager=20=E8=87=AA=E5=8A=A8=E7=AE=A1=E7=90=86=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=A9=B1=E5=8A=A8=E5=99=A8=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E9=9C=80=E6=89=8B=E5=8A=A8=E9=85=8D=E7=BD=AE=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=20(=E5=BD=93=E9=85=8D=E7=BD=AE=E4=BA=86?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E6=97=B6=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E4=BC=98=E5=85=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/{ => utils}/driver_manager/__init__.py | 0 liteyuki/{ => utils}/driver_manager/auto_set_env.py | 0 liteyuki/{ => utils}/driver_manager/defines.py | 0 main.py | 3 +-- 4 files changed, 1 insertion(+), 2 deletions(-) rename liteyuki/{ => utils}/driver_manager/__init__.py (100%) rename liteyuki/{ => utils}/driver_manager/auto_set_env.py (100%) rename liteyuki/{ => utils}/driver_manager/defines.py (100%) diff --git a/liteyuki/driver_manager/__init__.py b/liteyuki/utils/driver_manager/__init__.py similarity index 100% rename from liteyuki/driver_manager/__init__.py rename to liteyuki/utils/driver_manager/__init__.py diff --git a/liteyuki/driver_manager/auto_set_env.py b/liteyuki/utils/driver_manager/auto_set_env.py similarity index 100% rename from liteyuki/driver_manager/auto_set_env.py rename to liteyuki/utils/driver_manager/auto_set_env.py diff --git a/liteyuki/driver_manager/defines.py b/liteyuki/utils/driver_manager/defines.py similarity index 100% rename from liteyuki/driver_manager/defines.py rename to liteyuki/utils/driver_manager/defines.py diff --git a/main.py b/main.py index 9e7f152b..c7248751 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,10 @@ import nonebot from nonebot.adapters.onebot import v11, v12 from nonebot.adapters import satori -from liteyuki.utils import init +from liteyuki.utils import init, driver_manager from liteyuki.utils.base.config import load_from_yaml from liteyuki.utils.base.data_manager import StoredConfig, common_db from liteyuki.utils.base.ly_api import liteyuki_api -from liteyuki import driver_manager if __name__ == "__mp_main__": init() From c914ddc0ee469cae74b91de4a1bdc3d4fead0cb8 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 17:48:37 +0800 Subject: [PATCH 06/13] =?UTF-8?q?:pencil:=20NapCat.Onebot=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_status/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liteyuki/plugins/liteyuki_status/api.py b/liteyuki/plugins/liteyuki_status/api.py index a5894ac7..060e652e 100644 --- a/liteyuki/plugins/liteyuki_status/api.py +++ b/liteyuki/plugins/liteyuki_status/api.py @@ -170,7 +170,7 @@ async def get_bots_data(self_id: str = "0") -> dict: statistics = status.get("stat", {}) app_name = version_info.get("app_name", "UnknownImplementation") - if app_name in ["Lagrange.OneBot", "LLOneBot", "Shamrock"]: + if app_name in ["Lagrange.OneBot", "LLOneBot", "Shamrock", "NapCat.Onebot"]: icon = f"https://q.qlogo.cn/g?b=qq&nk={bot_id}&s=640" elif isinstance(bot, satori.Bot): app_name = "Satori" From 974b97b74423e660ff904eff7c7ab223d95b5f8d Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 17:51:42 +0800 Subject: [PATCH 07/13] =?UTF-8?q?:pencil:=20=E5=88=9D=E6=AC=A1=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=B6=E6=B7=BB=E5=8A=A0=20satori=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=85=8D=E7=BD=AE=20:pencil:=20=E5=B0=86?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=99=A8=E9=85=8D=E7=BD=AE=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=92=8C=E6=B3=A8=E5=86=8C=E7=A7=BB=E5=8A=A8=E5=88=B0?= =?UTF-8?q?=20utils.adapter=5Fmanager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/utils/adapter_manager/__init__.py | 14 ++++++++++ liteyuki/utils/adapter_manager/onebot.py | 12 ++++++++ liteyuki/utils/adapter_manager/satori.py | 28 +++++++++++++++++++ liteyuki/utils/base/config.py | 15 ++++++++++ liteyuki/utils/driver_manager/auto_set_env.py | 2 +- main.py | 23 +++++++++------ 6 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 liteyuki/utils/adapter_manager/__init__.py create mode 100644 liteyuki/utils/adapter_manager/onebot.py create mode 100644 liteyuki/utils/adapter_manager/satori.py diff --git a/liteyuki/utils/adapter_manager/__init__.py b/liteyuki/utils/adapter_manager/__init__.py new file mode 100644 index 00000000..daf48023 --- /dev/null +++ b/liteyuki/utils/adapter_manager/__init__.py @@ -0,0 +1,14 @@ +from . import ( + satori, + onebot +) + + +def init(config: dict): + onebot.init() + satori.init(config) + + +def register(): + onebot.register() + satori.register() diff --git a/liteyuki/utils/adapter_manager/onebot.py b/liteyuki/utils/adapter_manager/onebot.py new file mode 100644 index 00000000..23d2a59c --- /dev/null +++ b/liteyuki/utils/adapter_manager/onebot.py @@ -0,0 +1,12 @@ +import nonebot +from nonebot.adapters.onebot import v11, v12 + + +def init(): + pass + + +def register(): + driver = nonebot.get_driver() + driver.register_adapter(v11.Adapter) + driver.register_adapter(v12.Adapter) diff --git a/liteyuki/utils/adapter_manager/satori.py b/liteyuki/utils/adapter_manager/satori.py new file mode 100644 index 00000000..86d741e1 --- /dev/null +++ b/liteyuki/utils/adapter_manager/satori.py @@ -0,0 +1,28 @@ +import json +import os + +import nonebot +from nonebot.adapters import satori + + +def init(config: dict): + if config.get("satori", None) is None: + nonebot.logger.info("Satori config not found, skip Satori init.") + return None + satori_config = config.get("satori") + if not satori_config.get("enable", False): + nonebot.logger.info("Satori not enabled, skip Satori init.") + return None + if os.getenv("SATORI_CLIENTS", None) is not None: + nonebot.logger.info("Satori clients already set in environment variable, skip.") + os.environ["SATORI_CLIENTS"] = json.dumps(satori_config.get("hosts", []), ensure_ascii=False) + config['satori_clients'] = satori_config.get("hosts", []) + print(json.dumps(satori_config.get("hosts", []), ensure_ascii=False)) + return + + +def register(): + if os.getenv("SATORI_CLIENTS", None) is not None: + print(os.getenv("SATORI_CLIENTS", None)) + driver = nonebot.get_driver() + driver.register_adapter(satori.Adapter) diff --git a/liteyuki/utils/base/config.py b/liteyuki/utils/base/config.py index b7ad1e19..eaccbf4d 100644 --- a/liteyuki/utils/base/config.py +++ b/liteyuki/utils/base/config.py @@ -1,4 +1,5 @@ import os +from typing import List import nonebot import yaml @@ -11,12 +12,26 @@ from ..message.tools import random_hex_string config = {} # 全局配置,确保加载后读取 +class SatoriNodeConfig(BaseModel): + host: str = "" + port: str = "5500" + path: str = "" + token: str = "" + + +class SatoriConfig(BaseModel): + comment: str = "These features are still in development. Do not enable in production environment." + enable: bool = False + hosts: List[SatoriNodeConfig] = [SatoriNodeConfig()] + + class BasicConfig(BaseModel): host: str = "127.0.0.1" port: int = 20216 superusers: list[str] = [] command_start: list[str] = ["/", ""] nickname: list[str] = [f"LiteyukiBot-{random_hex_string(6)}"] + satori: SatoriConfig = SatoriConfig() def load_from_yaml(file: str) -> dict: diff --git a/liteyuki/utils/driver_manager/auto_set_env.py b/liteyuki/utils/driver_manager/auto_set_env.py index 2568d80f..88466d24 100644 --- a/liteyuki/utils/driver_manager/auto_set_env.py +++ b/liteyuki/utils/driver_manager/auto_set_env.py @@ -11,7 +11,7 @@ def auto_set_env(config: dict): if os.getenv("DRIVER", None) is not None: nonebot.logger.info("Driver already set in environment variable, skip auto configure.") return - if config.get("enable_satori", False): + if config.get("satori", {'enable': False}).get("enable", False): os.environ["DRIVER"] = get_driver_string(ASGI_DRIVER, HTTPX_DRIVER, WEBSOCKETS_DRIVER) nonebot.logger.info("Enable Satori, set driver to ASGI+HTTPX+WEBSOCKETS") else: diff --git a/main.py b/main.py index c7248751..c795d25b 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ import nonebot from nonebot.adapters.onebot import v11, v12 from nonebot.adapters import satori -from liteyuki.utils import init, driver_manager +from liteyuki.utils import init, driver_manager, adapter_manager from liteyuki.utils.base.config import load_from_yaml from liteyuki.utils.base.data_manager import StoredConfig, common_db from liteyuki.utils.base.ly_api import liteyuki_api @@ -12,16 +12,21 @@ if __name__ == "__mp_main__": static_config = load_from_yaml("config.yml") store_config.update(static_config) driver_manager.init(config=store_config) + adapter_manager.init(store_config) nonebot.init(**store_config) - if not store_config.get("enable_satori", False): - adapters = [v11.Adapter, v12.Adapter] - else: - adapters = [v11.Adapter, v12.Adapter, satori.Adapter] - driver = nonebot.get_driver() - # print(driver.__dict__) - for adapter in adapters: - driver.register_adapter(adapter) + adapter_manager.register() + + # print(nonebot.get_adapters()['Satori'].__dict__) + + # if not store_config.get("enable_satori", False): + # adapters = [v11.Adapter, v12.Adapter] + # else: + # adapters = [v11.Adapter, v12.Adapter, satori.Adapter] + # driver = nonebot.get_driver() + # # print(driver.__dict__) + # for adapter in adapters: + # driver.register_adapter(adapter) try: nonebot.load_plugin("liteyuki.liteyuki_main") From 246e43317f3c540acb57c81b0aa20a68b7194828 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 17:53:38 +0800 Subject: [PATCH 08/13] =?UTF-8?q?:pencil:=20=E6=B7=BB=E5=8A=A0=20onebot=5F?= =?UTF-8?q?v12=5Fevent=5Fmonitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteyuki_statistics/stat_monitors.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/liteyuki/plugins/liteyuki_statistics/stat_monitors.py b/liteyuki/plugins/liteyuki_statistics/stat_monitors.py index 27d82256..5db82dff 100644 --- a/liteyuki/plugins/liteyuki_statistics/stat_monitors.py +++ b/liteyuki/plugins/liteyuki_statistics/stat_monitors.py @@ -4,7 +4,7 @@ from nonebot import require from nonebot.message import event_postprocessor from liteyuki.utils.base.data import Database, LiteModel -from liteyuki.utils.base.ly_typing import v11, satori +from liteyuki.utils.base.ly_typing import v11, v12, satori from liteyuki.utils.base.ly_typing import T_Bot, T_MessageEvent @@ -47,6 +47,29 @@ async def onebot_v11_event_monitor(bot: v11.Bot, event: v11.MessageEvent): msg_db.save(mem) +@event_postprocessor +async def onebot_v12_event_monitor(bot: v12.Bot, event: v12.MessageEvent): + if event.message_type == "group": + event: v12.GroupMessageEvent + group_id = str(event.group_id) + else: + group_id = "" + mem = MessageEventModel( + time=int(time.time()), + bot_id=bot.self_id, + adapter="onebot.v12", + group_id=group_id, + user_id=str(event.user_id), + + message_id=str(event.message_id), + + message=event.message, + message_text=event.raw_message, + message_type=event.message_type, + ) + msg_db.save(mem) + + @event_postprocessor async def satori_event_monitor(bot: satori.Bot, event: satori.MessageEvent): if event.guild is not None: From 4c65a308d67e112a7b00e192916c29224289ee22 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 18:00:07 +0800 Subject: [PATCH 09/13] =?UTF-8?q?:bug:=20=E5=BD=93=E6=B2=A1=E6=9C=89=20.en?= =?UTF-8?q?v=20=E6=96=87=E4=BB=B6=E6=97=B6=E6=84=8F=E5=A4=96=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=94=99=E8=AF=AF=E7=9A=84=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/utils/driver_manager/auto_set_env.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liteyuki/utils/driver_manager/auto_set_env.py b/liteyuki/utils/driver_manager/auto_set_env.py index 88466d24..94e5b3be 100644 --- a/liteyuki/utils/driver_manager/auto_set_env.py +++ b/liteyuki/utils/driver_manager/auto_set_env.py @@ -7,8 +7,9 @@ from .defines import * def auto_set_env(config: dict): - dotenv.load_dotenv() + dotenv.load_dotenv(".env") if os.getenv("DRIVER", None) is not None: + print(os.getenv("DRIVER")) nonebot.logger.info("Driver already set in environment variable, skip auto configure.") return if config.get("satori", {'enable': False}).get("enable", False): From 10c383d66ae55f7d1e2d60c87ac2dce1d067aa50 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Fri, 17 May 2024 18:16:57 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=20print?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/utils/adapter_manager/satori.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/liteyuki/utils/adapter_manager/satori.py b/liteyuki/utils/adapter_manager/satori.py index 86d741e1..7778296d 100644 --- a/liteyuki/utils/adapter_manager/satori.py +++ b/liteyuki/utils/adapter_manager/satori.py @@ -17,12 +17,10 @@ def init(config: dict): nonebot.logger.info("Satori clients already set in environment variable, skip.") os.environ["SATORI_CLIENTS"] = json.dumps(satori_config.get("hosts", []), ensure_ascii=False) config['satori_clients'] = satori_config.get("hosts", []) - print(json.dumps(satori_config.get("hosts", []), ensure_ascii=False)) return def register(): if os.getenv("SATORI_CLIENTS", None) is not None: - print(os.getenv("SATORI_CLIENTS", None)) driver = nonebot.get_driver() driver.register_adapter(satori.Adapter) From 8667706377e8271e2ac9e96b86a164629e87ade4 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Mon, 20 May 2024 08:20:20 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20alc=20=E5=8F=91?= =?UTF-8?q?=E9=80=81=E4=BE=8B=E5=A6=82=20=E5=A4=A9=E6=B0=94=E6=AD=A6?= =?UTF-8?q?=E6=B1=89=20=E7=9A=84=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_weather/qweather.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/liteyuki/plugins/liteyuki_weather/qweather.py b/liteyuki/plugins/liteyuki_weather/qweather.py index 77490635..6f13f6d3 100644 --- a/liteyuki/plugins/liteyuki_weather/qweather.py +++ b/liteyuki/plugins/liteyuki_weather/qweather.py @@ -14,30 +14,30 @@ from liteyuki.utils.message.html_tool import template2image from liteyuki.utils import event as event_utils require("nonebot_plugin_alconna") -from nonebot_plugin_alconna import on_alconna, Alconna, Args, MultiVar, Arparma +from nonebot_plugin_alconna import on_alconna, Alconna, Args, MultiVar, Arparma, UniMessage - -@on_alconna( +wrx_alc = on_alconna( aliases={"天气"}, command=Alconna( "weather", Args["keywords", MultiVar(str), []], ), -).handle() +) + + +@wrx_alc.handle() async def _(result: Arparma, event: T_MessageEvent, matcher: Matcher): """await alconna.send("weather", city)""" kws = result.main_args.get("keywords") image = await get_weather_now_card(matcher, event, kws) - if isinstance(event, satori.event.Event): - await matcher.finish(satori.MessageSegment.image(raw=image, mime="image/png")) - else: - await matcher.finish(MessageSegment.image(image)) + await wrx_alc.finish(UniMessage.image(raw=image)) @on_endswith(("天气", "weather")).handle() async def _(event: T_MessageEvent, matcher: Matcher): """await alconna.send("weather", city)""" - kws = event.message.extract_plain_text() + # kws = event.message.extract_plain_text() + kws = event.get_plaintext() image = await get_weather_now_card(matcher, event, [kws.replace("天气", "").replace("weather", "")], False) await matcher.finish(MessageSegment.image(image)) From c5f8fbe86db0fd9488aa46c90e9c4f641d946d56 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Mon, 20 May 2024 08:22:06 +0800 Subject: [PATCH 12/13] =?UTF-8?q?:bug:=20=E5=9C=A8=E4=BD=BF=E7=94=A8=20sat?= =?UTF-8?q?ori=20=E9=80=82=E9=85=8D=E5=99=A8=E6=97=B6=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E4=BE=8B=E5=A6=82=20=E6=AD=A6=E6=B1=89?= =?UTF-8?q?=E5=A4=A9=E6=B0=94=20=E7=9A=84=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_weather/qweather.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/liteyuki/plugins/liteyuki_weather/qweather.py b/liteyuki/plugins/liteyuki_weather/qweather.py index 6f13f6d3..08e6df6c 100644 --- a/liteyuki/plugins/liteyuki_weather/qweather.py +++ b/liteyuki/plugins/liteyuki_weather/qweather.py @@ -39,7 +39,10 @@ async def _(event: T_MessageEvent, matcher: Matcher): # kws = event.message.extract_plain_text() kws = event.get_plaintext() image = await get_weather_now_card(matcher, event, [kws.replace("天气", "").replace("weather", "")], False) - await matcher.finish(MessageSegment.image(image)) + if isinstance(event, satori.event.Event): + await matcher.finish(satori.MessageSegment.image(raw=image, mime="image/png")) + else: + await matcher.finish(MessageSegment.image(image)) async def get_weather_now_card(matcher: Matcher, event: T_MessageEvent, keyword: list[str], tip: bool = True): From e13464cb7c369d3c45374a11e13854894c70e632 Mon Sep 17 00:00:00 2001 From: Expliyh Date: Mon, 20 May 2024 08:51:21 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E6=8B=BC=E5=86=99=E9=94=99=E4=BA=86(?= =?UTF-8?q?=E5=B0=B4=E5=B0=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/plugins/liteyuki_weather/qweather.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liteyuki/plugins/liteyuki_weather/qweather.py b/liteyuki/plugins/liteyuki_weather/qweather.py index 08e6df6c..9b158b9e 100644 --- a/liteyuki/plugins/liteyuki_weather/qweather.py +++ b/liteyuki/plugins/liteyuki_weather/qweather.py @@ -16,7 +16,7 @@ from liteyuki.utils import event as event_utils require("nonebot_plugin_alconna") from nonebot_plugin_alconna import on_alconna, Alconna, Args, MultiVar, Arparma, UniMessage -wrx_alc = on_alconna( +wx_alc = on_alconna( aliases={"天气"}, command=Alconna( "weather", @@ -25,12 +25,12 @@ wrx_alc = on_alconna( ) -@wrx_alc.handle() +@wx_alc.handle() async def _(result: Arparma, event: T_MessageEvent, matcher: Matcher): """await alconna.send("weather", city)""" kws = result.main_args.get("keywords") image = await get_weather_now_card(matcher, event, kws) - await wrx_alc.finish(UniMessage.image(raw=image)) + await wx_alc.finish(UniMessage.image(raw=image)) @on_endswith(("天气", "weather")).handle()