From 40bd372cc1c3ec87ec196c674da0b9ffb7390e7e Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 8 Feb 2025 18:02:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E9=87=8D=E5=90=AFgewe=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E6=9C=BA=E5=99=A8=E4=BA=BA=E4=BC=9A=E7=96=AF?= =?UTF-8?q?=E7=8B=82=E5=8F=91=E6=B6=88=E6=81=AF=20#421?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/sources/gewechat/client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index e96145bbf..dd0b26a6c 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -3,6 +3,8 @@ import asyncio import aiohttp import quart import base64 +import datetime +import tzdata from astrbot.api.platform import AstrBotMessage, MessageMember, MessageType from astrbot.api.message_components import Plain, Image, At, Record @@ -67,6 +69,17 @@ class SimpleGewechatClient(): logger.critical("收到 gewechat 下线通知。") return + if 'Data' in data and 'CreateTime' in data['Data']: + # 得到系统 UTF+8 的 ts + tz_offset = datetime.timedelta(hours=8) + tz = datetime.timezone(tz_offset) + ts = datetime.datetime.now(tz).timestamp() + create_time = data['Data']['CreateTime'] + if create_time < ts - 30: + logger.warning(f"消息时间戳过旧: {create_time},当前时间戳: {ts}") + return + + abm = AstrBotMessage() d = data['Data'] @@ -143,7 +156,7 @@ class SimpleGewechatClient(): abm.message.append(Record(file=file_path, url=file_path)) case _: - logger.error(f"未实现的消息类型: {d['MsgType']}") + logger.info(f"未实现的消息类型: {d['MsgType']}") return logger.info(f"abm: {abm}") From 8c132a51f507939c01bba887a51477ae350d9b08 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 8 Feb 2025 18:51:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=90=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E8=AE=BE=E7=BD=AEpermission=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E5=85=B6=E4=B8=80=E5=AE=9A=E4=BC=9A?= =?UTF-8?q?=E8=A2=AB=E6=89=A7=E8=A1=8C=20#427?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/waking_check/stage.py | 4 ++++ astrbot/core/platform/sources/gewechat/client.py | 1 - astrbot/core/star/register/star_handler.py | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/astrbot/core/pipeline/waking_check/stage.py b/astrbot/core/pipeline/waking_check/stage.py index 206baf11e..eeede1667 100644 --- a/astrbot/core/pipeline/waking_check/stage.py +++ b/astrbot/core/pipeline/waking_check/stage.py @@ -86,6 +86,10 @@ class WakingCheckStage(Stage): if len(handler.event_filters) == 0: # 不可能有这种情况, 也不允许有这种情况 continue + + if 'sub_command' in handler.extras_configs: + # 如果是子指令 + continue for filter in handler.event_filters: try: diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index dd0b26a6c..2489fc056 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -4,7 +4,6 @@ import aiohttp import quart import base64 import datetime -import tzdata from astrbot.api.platform import AstrBotMessage, MessageMember, MessageType from astrbot.api.message_components import Plain, Image, At, Record diff --git a/astrbot/core/star/register/star_handler.py b/astrbot/core/star/register/star_handler.py index 2a5e40a63..9226b04a7 100644 --- a/astrbot/core/star/register/star_handler.py +++ b/astrbot/core/star/register/star_handler.py @@ -68,12 +68,14 @@ def register_command(command_name: str = None, *args, **kwargs): add_to_event_filters = True def decorator(awaitable): + if not add_to_event_filters: + kwargs['sub_command'] = True # 打一个标记,表示这是一个子指令,再 wakingstage 阶段这个 handler 将会直接被跳过(其父指令会接管) handler_md = get_handler_or_create(awaitable, EventType.AdapterMessageEvent, **kwargs) new_command.init_handler_md(handler_md) if add_to_event_filters: # 裸指令 handler_md.event_filters.append(new_command) - + return awaitable return decorator