From 5aeca9662b30a246ed637062bd4acff10a042c1a Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Sun, 11 May 2025 22:57:50 +0800 Subject: [PATCH 01/11] =?UTF-8?q?feat:=20=E5=AF=B9aiocqhttp=E4=B8=AD,=20At?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=96=B0=E5=A2=9E=E5=A4=84=E7=90=86:=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8At=E5=AD=97=E6=AE=B5=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E4=B9=9F=E4=BC=9A=E8=A2=AB=E8=A7=A3=E6=9E=90=E4=B8=BA=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E4=BF=A1=E6=81=AF(=E4=BD=86=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=93=BE=E5=B9=B6=E6=B2=A1=E6=9C=89=E4=BF=AE=E6=94=B9,=20?= =?UTF-8?q?=E5=8F=AA=E6=98=AF=E5=9C=A8=E7=94=A8=E4=BA=8Ellm=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=9A=84=E6=96=87=E6=9C=AC=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86At=E4=BF=A1=E6=81=AF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiocqhttp/aiocqhttp_platform_adapter.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 97754f2c..4786b996 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -287,6 +287,31 @@ class AiocqhttpAdapter(Platform): logger.error(f"获取引用消息失败: {e}。") a = ComponentTypes[t](**m["data"]) # noqa: F405 abm.message.append(a) + elif t == "at": + for m in m_group: + try: + at_info = await self.bot.call_action( + action="get_stranger_info", + user_id=int(m["data"]["qq"]), + ) + if at_info: + nickname = at_info.get("nick", "") + abm.message.append( + At( + qq=m["data"]["qq"], + name=nickname, + ) + ) + # 兼容文本消息 + message_str += f"@{nickname} " + else: + abm.message.append( + At(qq=m["data"]["qq"], name="") + ) # noqa: F405 + except ActionFailed as e: + logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。") + except BaseException as e: + logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。") else: for m in m_group: a = ComponentTypes[t](**m["data"]) # noqa: F405 From 4bef5e8313444dbcb0a84cf6fad69fb3e791ff66 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Mon, 12 May 2025 00:21:48 +0800 Subject: [PATCH 02/11] =?UTF-8?q?fix:=20=E9=81=BF=E5=85=8Dmessage=5Fstr?= =?UTF-8?q?=E8=A2=AB=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sources/aiocqhttp/aiocqhttp_platform_adapter.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 4786b996..0896e6cc 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -165,9 +165,7 @@ class AiocqhttpAdapter(Platform): if "sub_type" in event: if event["sub_type"] == "poke" and "target_id" in event: - abm.message.append( - Poke(qq=str(event["target_id"]), type="poke") - ) # noqa: F405 + abm.message.append(Poke(qq=str(event["target_id"]), type="poke")) # noqa: F405 return abm @@ -218,7 +216,7 @@ class AiocqhttpAdapter(Platform): a = None if t == "text": # 合并相邻文本段 - message_str = "".join(m["data"]["text"] for m in m_group).strip() + message_str += "".join(m["data"]["text"] for m in m_group).strip() a = ComponentTypes[t](text=message_str) # noqa: F405 abm.message.append(a) @@ -305,9 +303,7 @@ class AiocqhttpAdapter(Platform): # 兼容文本消息 message_str += f"@{nickname} " else: - abm.message.append( - At(qq=m["data"]["qq"], name="") - ) # noqa: F405 + abm.message.append(At(qq=m["data"]["qq"], name="")) # noqa: F405 except ActionFailed as e: logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。") except BaseException as e: From e46cf20dd30f7b0e832e62151f1c31fe3c036c4e Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Mon, 12 May 2025 11:22:46 +0800 Subject: [PATCH 03/11] =?UTF-8?q?fix:=20=E4=B8=8D=E5=86=8D=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=94=A4=E9=86=92=E7=9A=84@=E5=88=B0message=5Fstr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiocqhttp/aiocqhttp_platform_adapter.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 4786b996..e6ed9205 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -288,6 +288,8 @@ class AiocqhttpAdapter(Platform): a = ComponentTypes[t](**m["data"]) # noqa: F405 abm.message.append(a) elif t == "at": + first_at_self_processed = False + for m in m_group: try: at_info = await self.bot.call_action( @@ -296,18 +298,23 @@ class AiocqhttpAdapter(Platform): ) if at_info: nickname = at_info.get("nick", "") + is_at_self = str(m["data"]["qq"]) in {abm.self_id, "all"} + abm.message.append( At( qq=m["data"]["qq"], name=nickname, ) ) - # 兼容文本消息 - message_str += f"@{nickname} " + + if is_at_self and not first_at_self_processed: + # 第一个@是机器人,不添加到message_str + first_at_self_processed = True + else: + # 非第一个@机器人或@其他用户,添加到message_str + message_str += f"@{nickname} " else: - abm.message.append( - At(qq=m["data"]["qq"], name="") - ) # noqa: F405 + abm.message.append(At(qq=str(m["data"]["qq"]), name="")) except ActionFailed as e: logger.error(f"获取 @ 用户信息失败: {e},此消息段将被忽略。") except BaseException as e: From 77c823c100c89518f295a8f412cec8a868c853d2 Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Mon, 12 May 2025 11:32:40 +0800 Subject: [PATCH 04/11] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=85=A8=E4=BD=93=E6=88=90=E5=91=98=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sources/aiocqhttp/aiocqhttp_platform_adapter.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index eb50ad67..cbf40eda 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -217,9 +217,9 @@ class AiocqhttpAdapter(Platform): for t, m_group in itertools.groupby(event.message, key=lambda x: x["type"]): a = None if t == "text": - # 合并相邻文本段 - message_str += "".join(m["data"]["text"] for m in m_group).strip() - a = ComponentTypes[t](text=message_str) # noqa: F405 + current_text = "".join(m["data"]["text"] for m in m_group).strip() + message_str += current_text + a = ComponentTypes[t](text=current_text) # noqa: F405 abm.message.append(a) elif t == "file": @@ -292,6 +292,11 @@ class AiocqhttpAdapter(Platform): for m in m_group: try: + if m["data"]["qq"] == "all": + abm.message.append(At(qq="all", name="全体成员")) + message_str += "@全体成员 " + continue + at_info = await self.bot.call_action( action="get_stranger_info", user_id=int(m["data"]["qq"]), From a730cee7fd64daead7e8d5fd59ab8d135bc34ce6 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Mon, 12 May 2025 14:48:31 +0800 Subject: [PATCH 05/11] =?UTF-8?q?fix:=20at=E5=85=A8=E4=BD=93=E4=B8=8D?= =?UTF-8?q?=E5=8A=A0=E5=85=A5message=5Fstr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index cbf40eda..9d882741 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -294,7 +294,6 @@ class AiocqhttpAdapter(Platform): try: if m["data"]["qq"] == "all": abm.message.append(At(qq="all", name="全体成员")) - message_str += "@全体成员 " continue at_info = await self.bot.call_action( From 3ad2c46f3fcb48136692b131b1bfa97a235d09b6 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Mon, 12 May 2025 15:04:23 +0800 Subject: [PATCH 06/11] =?UTF-8?q?perf:=20tg=E9=80=82=E9=85=8D=E5=99=A8?= =?UTF-8?q?=E5=90=8C=E6=AD=A5aiocqhttp=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/sources/telegram/tg_adapter.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index a2ce8873..b13b60d7 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -282,10 +282,12 @@ class TelegramPlatformAdapter(Platform): entity.offset + 1 : entity.offset + entity.length ] message.message.append(Comp.At(qq=name, name=name)) - plain_text = ( - plain_text[: entity.offset] - + plain_text[entity.offset + entity.length :] - ) + # 如果mention是当前bot则移除;否则保留 + if name.lower() == context.bot.username.lower(): + plain_text = ( + plain_text[: entity.offset] + + plain_text[entity.offset + entity.length :] + ) if plain_text: message.message.append(Comp.Plain(plain_text)) From 6d8a3b9897e714d02c7ac48ef3349d60c0621f19 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Tue, 13 May 2025 10:10:58 +0800 Subject: [PATCH 07/11] =?UTF-8?q?fix:=20=E5=9B=9E=E9=80=80=E8=87=B3os.exec?= =?UTF-8?q?l=E4=BB=A5=E5=85=BC=E5=AE=B9docker=EF=BC=8C=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E5=8F=8C=E5=BC=95=E5=8F=B7=E5=A4=84=E7=90=86=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/updator.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/astrbot/core/updator.py b/astrbot/core/updator.py index 9a5dcc02..09c4dba9 100644 --- a/astrbot/core/updator.py +++ b/astrbot/core/updator.py @@ -2,7 +2,6 @@ import os import psutil import sys import time -import subprocess from .zip_updator import ReleaseInfo, RepoZipUpdator from astrbot.core import logger from astrbot.core.config.default import VERSION @@ -43,9 +42,9 @@ class AstrBotUpdator(RepoZipUpdator): pass def _reboot(self, delay: int = 3): - """ - 重启当前程序,使用 subprocess.Popen 启动新进程并退出旧进程 + """重启当前程序 在指定的延迟后,终止所有子进程并重新启动程序 + 这里只能使用 os.execl 来重启程序 """ time.sleep(delay) self.terminate_child_processes() @@ -53,18 +52,16 @@ class AstrBotUpdator(RepoZipUpdator): try: if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli - cmd = [py, "-m", "astrbot.cli.__main__"] + sys.argv[1:] + args = [ + f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:] + ] + os.execl(py, f'"{py}"', "-m", "astrbot.cli.__main__", *args) else: - cmd = [py] + sys.argv - - subprocess.Popen(cmd, start_new_session=True) - + os.execl(py, f'"{py}"', *sys.argv) except Exception as e: - logger.error(f"重启失败({py} {cmd},错误:{e}),请尝试手动重启。") + logger.error(f"重启失败({py}, {e}),请尝试手动重启。") raise e - os._exit(0) - async def check_update(self, url: str, current_version: str) -> ReleaseInfo: """检查更新""" return await super().check_update(self.ASTRBOT_RELEASE_API, VERSION) From c5aae98558d04bbeaddef6545f26b362eaddc13a Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Tue, 13 May 2025 16:03:04 +0800 Subject: [PATCH 08/11] fix: update reboot logic to handle executable paths correctly --- astrbot/core/updator.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/astrbot/core/updator.py b/astrbot/core/updator.py index 09c4dba9..d7ee77bf 100644 --- a/astrbot/core/updator.py +++ b/astrbot/core/updator.py @@ -44,20 +44,26 @@ class AstrBotUpdator(RepoZipUpdator): def _reboot(self, delay: int = 3): """重启当前程序 在指定的延迟后,终止所有子进程并重新启动程序 - 这里只能使用 os.execl 来重启程序 + 这里只能使用 os.exec* 来重启程序 """ time.sleep(delay) self.terminate_child_processes() - py = sys.executable + if os.name == "nt": + py = f'"{sys.executable}"' + else: + py = sys.executable try: if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli - args = [ - f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:] - ] - os.execl(py, f'"{py}"', "-m", "astrbot.cli.__main__", *args) + if os.name == "nt": + args = [ + f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:] + ] + else: + args = sys.argv[1:] + os.execl(sys.executable, py, "-m", "astrbot.cli.__main__", *args) else: - os.execl(py, f'"{py}"', *sys.argv) + os.execl(sys.executable, py, *sys.argv) except Exception as e: logger.error(f"重启失败({py}, {e}),请尝试手动重启。") raise e From 864b6bc56d5daad3ed19851e7f6b26698054921b Mon Sep 17 00:00:00 2001 From: anka <1350989414@qq.com> Date: Thu, 15 May 2025 20:00:46 +0800 Subject: [PATCH 09/11] =?UTF-8?q?fix:=20=F0=9F=A4=A0=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E5=90=8E=E6=9C=89@=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91=E6=8C=87=E4=BB=A4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 9d882741..890ff0f8 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -316,7 +316,7 @@ class AiocqhttpAdapter(Platform): first_at_self_processed = True else: # 非第一个@机器人或@其他用户,添加到message_str - message_str += f"@{nickname} " + message_str += f" @{nickname} " else: abm.message.append(At(qq=str(m["data"]["qq"]), name="")) except ActionFailed as e: From 507c3e362938c9bd97854deee7470e9b218d2b43 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 16 May 2025 10:14:16 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E2=9C=A8=20feat:=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=E6=94=AF=E6=8C=81=E4=BB=A3=E7=A0=81=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/shared/AstrBotConfig.vue | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index 0117fd2f..fff89f60 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -1,3 +1,27 @@ + +