From a1172c9a8227072700e44c28f358e93dd282618a Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 11 Mar 2025 23:27:10 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=9B=9E=E5=A4=8D=E6=B6=88=E6=81=AF=20#783?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/message/components.py | 18 ++++++++- astrbot/core/platform/astr_message_event.py | 8 ++++ .../aiocqhttp/aiocqhttp_platform_adapter.py | 38 ++++++++++++++++++- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/astrbot/core/message/components.py b/astrbot/core/message/components.py index 44caa2075..389f0088a 100644 --- a/astrbot/core/message/components.py +++ b/astrbot/core/message/components.py @@ -311,10 +311,24 @@ class Image(BaseMessageComponent): class Reply(BaseMessageComponent): type: ComponentType = "Reply" id: T.Union[str, int] - text: T.Optional[str] = "" - qq: T.Optional[int] = 0 + """所引用的消息 ID""" + chain: T.Optional[T.List["BaseMessageComponent"]] = [] + """引用的消息段列表""" + sender_id: T.Optional[int] | T.Optional[str] = 0 + """引用的消息发送者 ID""" + sender_nickname: T.Optional[str] = "" + """引用的消息发送者昵称""" time: T.Optional[int] = 0 + """引用的消息发送时间""" + message_str: T.Optional[str] = "" + """解析后的纯文本消息字符串""" + + text: T.Optional[str] = "" + """deprecated""" + qq: T.Optional[int] = 0 + """deprecated""" seq: T.Optional[int] = 0 + """deprecated""" def __init__(self, **_): super().__init__(**_) diff --git a/astrbot/core/platform/astr_message_event.py b/astrbot/core/platform/astr_message_event.py index 72e4414b6..9ae3c99f7 100644 --- a/astrbot/core/platform/astr_message_event.py +++ b/astrbot/core/platform/astr_message_event.py @@ -14,6 +14,7 @@ from astrbot.core.message.components import ( At, AtAll, Forward, + Reply ) from astrbot.core.utils.metrics import Metric from astrbot.core.provider.entites import ProviderRequest @@ -101,8 +102,15 @@ class AstrMessageEvent(abc.ABC): elif isinstance(i, Forward): # 转发消息 outline += "[转发消息]" + elif isinstance(i, Reply): + # 引用回复 + if i.message_str: + outline += f"[引用消息({i.sender_nickname}: {i.message_str})]" + else: + outline += "[引用消息]" else: outline += f"[{i.type}]" + outline += " " return outline def get_message_outline(self) -> str: diff --git a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py index 0a2e8d430..e81e7153f 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -160,8 +160,14 @@ class AiocqhttpAdapter(Platform): return abm - async def _convert_handle_message_event(self, event: Event) -> AstrBotMessage: - """OneBot V11 消息类事件""" + async def _convert_handle_message_event( + self, event: Event, get_reply=True + ) -> AstrBotMessage: + """OneBot V11 消息类事件 + + @param event: 事件对象 + @param get_reply: 是否获取回复消息。这个参数是为了防止多个回复嵌套。 + """ abm = AstrBotMessage() abm.self_id = str(event.self_id) abm.sender = MessageMember( @@ -240,6 +246,34 @@ class AiocqhttpAdapter(Platform): except BaseException as e: logger.error(f"获取文件失败: {e},此消息段将被忽略。") + elif t == "reply": + if not get_reply: + a = ComponentTypes[t](**m["data"]) # noqa: F405 + abm.message.append(a) + else: + try: + reply_event_data = await self.bot.call_action( + action="get_msg", + message_id=int(m["data"]["id"]), + ) + abm_reply = await self._convert_handle_message_event( + Event.from_payload(reply_event_data), get_reply=False + ) + + reply_seg = Reply( + id=abm_reply.message_id, + chain=abm_reply.message, + sender_id=abm_reply.sender.user_id, + sender_nickname=abm_reply.sender.nickname, + time=abm_reply.timestamp, + message_str=abm_reply.message_str, + text=abm_reply.message_str, # for compatibility + qq=abm_reply.sender.user_id, # for compatibility + ) + + abm.message.append(reply_seg) + except BaseException as e: + logger.error(f"获取消息失败: {e},此消息段将被忽略。") else: a = ComponentTypes[t](**m["data"]) # noqa: F405 abm.message.append(a) From f9ec97e0260098857518e89ab5ea9c15740ba3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Wed, 12 Mar 2025 08:39:54 +0900 Subject: [PATCH 02/17] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/message/components.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/astrbot/core/message/components.py b/astrbot/core/message/components.py index 389f0088a..4c62cc30f 100644 --- a/astrbot/core/message/components.py +++ b/astrbot/core/message/components.py @@ -367,16 +367,20 @@ class Node(BaseMessageComponent): id: T.Optional[int] = 0 # 忽略 name: T.Optional[str] = "" # qq昵称 uin: T.Optional[int] = 0 # qq号 - content: T.Optional[T.Union[str, list]] = "" # 子消息段列表 + content: T.Optional[T.Union[str, list, dict]] = "" # 子消息段列表 seq: T.Optional[T.Union[str, list]] = "" # 忽略 time: T.Optional[int] = 0 - def __init__(self, content: T.Union[str, list], **_): + def __init__(self, content: T.Union[str, list, dict, "Node"], **_): if isinstance(content, list): _content = "" for chain in content: _content += chain.toString() content = _content + elif isinstance(content, Node): + content = content.toDict() + else: + content = content super().__init__(content=content, **_) def toString(self): From 9d0ad35403075bf5b766eaa923f810c718420ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Wed, 12 Mar 2025 11:14:54 +0900 Subject: [PATCH 03/17] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=EF=BC=8C=E9=87=8C=E5=B1=82=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E5=A4=9A=E6=9D=A1=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/message/components.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/astrbot/core/message/components.py b/astrbot/core/message/components.py index 4c62cc30f..19fdb89e2 100644 --- a/astrbot/core/message/components.py +++ b/astrbot/core/message/components.py @@ -371,16 +371,14 @@ class Node(BaseMessageComponent): seq: T.Optional[T.Union[str, list]] = "" # 忽略 time: T.Optional[int] = 0 - def __init__(self, content: T.Union[str, list, dict, "Node"], **_): + def __init__(self, content: T.Union[str, list, dict, "Node", T.List["Node"]], **_): if isinstance(content, list): - _content = "" - for chain in content: - _content += chain.toString() - content = _content + if all(isinstance(item, str) for item in content): + content = "".join(content) + elif all(isinstance(item, Node) for item in content): + content = [node.toDict() for node in content] elif isinstance(content, Node): content = content.toDict() - else: - content = content super().__init__(content=content, **_) def toString(self): From 122fccc041c7fc5a5deea3375191d925928e2b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=B0=B8=E8=B5=AB?= <1259085392@qq.com> Date: Wed, 12 Mar 2025 11:59:53 +0900 Subject: [PATCH 04/17] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=9D=9E=E5=B5=8C=E5=A5=97=E7=9A=84=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E6=B6=88=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/message/components.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/astrbot/core/message/components.py b/astrbot/core/message/components.py index 19fdb89e2..7f73e5d91 100644 --- a/astrbot/core/message/components.py +++ b/astrbot/core/message/components.py @@ -373,10 +373,14 @@ class Node(BaseMessageComponent): def __init__(self, content: T.Union[str, list, dict, "Node", T.List["Node"]], **_): if isinstance(content, list): - if all(isinstance(item, str) for item in content): - content = "".join(content) - elif all(isinstance(item, Node) for item in content): - content = [node.toDict() for node in content] + _content = None + if all(isinstance(item, Node) for item in content): + _content = [node.toDict() for node in content] + else: + _content = "" + for chain in content: + _content += chain.toString() + content = _content elif isinstance(content, Node): content = content.toDict() super().__init__(content=content, **_) From 16488506e8507fd4ab3e6a3b2f17c15a4950d4f6 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 12 Mar 2025 14:14:45 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5=E4=B8=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E4=B8=8A=E4=BC=A0=E5=88=B0=20Telegram=20?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E7=9A=84=E9=97=AE=E9=A2=98=20#601?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/sources/telegram/tg_event.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/astrbot/core/platform/sources/telegram/tg_event.py b/astrbot/core/platform/sources/telegram/tg_event.py index de0f9a58e..7708732b4 100644 --- a/astrbot/core/platform/sources/telegram/tg_event.py +++ b/astrbot/core/platform/sources/telegram/tg_event.py @@ -2,6 +2,7 @@ from astrbot.api.event import AstrMessageEvent, MessageChain from astrbot.api.platform import AstrBotMessage, PlatformMetadata, MessageType from astrbot.api.message_components import Plain, Image, Reply, At, File, Record from telegram.ext import ExtBot +from astrbot.core.utils.io import download_file class TelegramPlatformEvent(AstrMessageEvent): @@ -58,6 +59,11 @@ class TelegramPlatformEvent(AstrMessageEvent): else: await client.send_photo(photo=image_path, **payload) elif isinstance(i, File): + if i.file.startswith("https://"): + path = "data/temp/" + i.name + await download_file(i.file, path) + i.file = path + await client.send_document(document=i.file, filename=i.name, **payload) elif isinstance(i, Record): await client.send_voice(voice=i.file, **payload) From 681940d4665d190fffbb980ddcfdd0b55c8fb7cb Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 12 Mar 2025 23:37:24 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=87=8D=E8=BD=BD=E6=8F=92=E4=BB=B6=E6=97=B6=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=8F=AF=E8=83=BD=E5=A4=9A=E6=AC=A1=E5=AE=B6?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/func_tool_manager.py | 11 +++++++---- astrbot/core/star/register/star_handler.py | 2 -- astrbot/core/star/star_manager.py | 4 +--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/astrbot/core/provider/func_tool_manager.py b/astrbot/core/provider/func_tool_manager.py index 0022d2773..42b88cae2 100644 --- a/astrbot/core/provider/func_tool_manager.py +++ b/astrbot/core/provider/func_tool_manager.py @@ -2,7 +2,7 @@ import json import textwrap from typing import Dict, List, Awaitable from dataclasses import dataclass - +from astrbot import logger @dataclass class FuncTool: @@ -46,14 +46,16 @@ class FuncCall: desc: str, handler: Awaitable, ) -> None: - """ - 为函数调用(function-calling / tools-use)添加工具。 + """添加函数调用工具 @param name: 函数名 @param func_args: 函数参数列表,格式为 [{"type": "string", "name": "arg_name", "description": "arg_description"}, ...] @param desc: 函数描述 @param func_obj: 处理函数 """ + # check if the tool has been added before + self.remove_func(name) + params = { "type": "object", # hard-coded here "properties": {}, @@ -70,13 +72,14 @@ class FuncCall: handler=handler, ) self.func_list.append(_func) + logger.info(f"添加了函数调用工具({len(self.func_list)}): {name} - {desc}") def remove_func(self, name: str) -> None: """ 删除一个函数调用工具。 """ for i, f in enumerate(self.func_list): - if f["name"] == name: + if f.name == name: self.func_list.pop(i) break diff --git a/astrbot/core/star/register/star_handler.py b/astrbot/core/star/register/star_handler.py index 4e2f9d176..86620cae6 100644 --- a/astrbot/core/star/register/star_handler.py +++ b/astrbot/core/star/register/star_handler.py @@ -360,8 +360,6 @@ def register_llm_tool(name: str = None): ) md = get_handler_or_create(awaitable, EventType.OnCallingFuncToolEvent) llm_tools.add_func(llm_tool_name, args, docstring.description, md.handler) - - logger.debug(f"LLM 函数工具 {llm_tool_name} 已注册") return awaitable return decorator diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 4a7938605..9fa27798b 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -485,7 +485,7 @@ class PluginManager: for handler in star_handlers_registry.get_handlers_by_module_name( plugin_module_path ): - logger.debug(f"unbind handler {handler.handler_name} from {plugin_name}") + logger.info(f"移除了插件 {plugin_name} 的处理函数 {handler.handler_name} ({len(star_handlers_registry)})") star_handlers_registry.remove(handler) keys_to_delete = [ k @@ -493,8 +493,6 @@ class PluginManager: if k.startswith(plugin_module_path) ] for k in keys_to_delete: - v = star_handlers_registry.star_handlers_map[k] - logger.debug(f"unbind handler {v.handler_name} from {plugin_name} (map)") try: del star_handlers_registry.star_handlers_map[k] except KeyError: From 8136ad8287f0af5009658cead0a1f577024de5c1 Mon Sep 17 00:00:00 2001 From: shuiping233 <1944680304@qq.com> Date: Wed, 12 Mar 2025 18:09:25 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=8A=A5=E9=94=99=E4=BF=A1=E6=81=AF=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=8F=91=E9=80=81=E8=87=B3qq=E5=AE=98=E6=96=B9?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E5=B9=B3=E5=8F=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/waking_check/stage.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/astrbot/core/pipeline/waking_check/stage.py b/astrbot/core/pipeline/waking_check/stage.py index 6bb5f814d..9b2b20155 100644 --- a/astrbot/core/pipeline/waking_check/stage.py +++ b/astrbot/core/pipeline/waking_check/stage.py @@ -106,6 +106,7 @@ class WakingCheckStage(Stage): f"插件 {star_map[handler.handler_module_path].name}: {e}" ) ) + await event._post_send() event.stop_event() passed = False break @@ -117,6 +118,7 @@ class WakingCheckStage(Stage): f"ID {event.get_sender_id()} 权限不足。通过 /sid 获取 ID 并请管理员添加。" ) ) + await event._post_send() event.stop_event() return From 0034474219b609f1d401f15993a07c2f0acfc5ae Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 13:01:44 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=F0=9F=90=9B=20fix:=20sent=20message=20to?= =?UTF-8?q?=20wrong=20topic=20in=20topic=20group=20#801?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/platform/sources/telegram/tg_adapter.py | 6 +++++- astrbot/core/platform/sources/telegram/tg_event.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index dfb882328..b7d7a6e7e 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -113,7 +113,11 @@ class TelegramPlatformAdapter(Platform): message.type = MessageType.FRIEND_MESSAGE else: message.type = MessageType.GROUP_MESSAGE - message.group_id = update.effective_chat.id + message.group_id = str(update.effective_chat.id) + if update.message.message_thread_id: + # Topic Group + message.group_id += "#" + str(update.message.message_thread_id) + message.message_id = str(update.message.message_id) message.session_id = str(update.effective_chat.id) message.sender = MessageMember( diff --git a/astrbot/core/platform/sources/telegram/tg_event.py b/astrbot/core/platform/sources/telegram/tg_event.py index 7708732b4..a8a04e2e1 100644 --- a/astrbot/core/platform/sources/telegram/tg_event.py +++ b/astrbot/core/platform/sources/telegram/tg_event.py @@ -32,12 +32,18 @@ class TelegramPlatformEvent(AstrMessageEvent): at_user_id = i.name at_flag = False + message_thread_id = None + if "#" in user_name: + # it's a supergroup chat with message_thread_id + user_name, message_thread_id = user_name.split("#") for i in message.chain: payload = { "chat_id": user_name, } if has_reply: payload["reply_to_message_id"] = reply_message_id + if message_thread_id: + payload["reply_to_message_id"] = message_thread_id if isinstance(i, Plain): if at_user_id and not at_flag: From 0c396181f78dff33800e33b923cbfb27aabd0ff1 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 15:37:53 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=F0=9F=8F=97=20refactor:=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E6=A0=B7=E5=BC=8F=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/shared/AstrBotConfig.vue | 227 +++++++++--------- .../src/components/shared/ListConfigItem.vue | 166 ++++++------- dashboard/src/views/ConfigPage.vue | 110 +++++---- 3 files changed, 253 insertions(+), 250 deletions(-) diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index 6ace849ef..38d3f3c27 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -1,130 +1,135 @@ - - \ No newline at end of file + removeItem(index) { + this.items.splice(index, 1); + }, + }, +}; + + + \ No newline at end of file diff --git a/dashboard/src/views/ConfigPage.vue b/dashboard/src/views/ConfigPage.vue index 48b866c0f..d7f0f4ecb 100644 --- a/dashboard/src/views/ConfigPage.vue +++ b/dashboard/src/views/ConfigPage.vue @@ -30,73 +30,79 @@ import config from '@/config'; - + {{ metadata[key]['name'] }} - - - -

{{metadata[key]['metadata'][key2]['description']}}

-
- - - - 😄 消息平台适配器和服务提供商的配置已经迁移至更方便的独立页面!推荐前往左栏配置哦~ - +
+ +
+ + + + {{ item[metadata[key]['metadata'][key2]?.tmpl_display_title] }} + + + {{ item.id }}({{ item.type }}) + + + + + + {{ index }} + + + + + + + + + 删除这项 + + + + + + + +
+ +
+ +
+ + +
+ + +
+ +
- - - {{ item[metadata[key]['metadata'][key2]?.tmpl_display_title] }} - - - {{ item.id }}({{ item.type }}) - - - - - - {{ index }} - - - - - - - - - 删除这项 - - - - - -
- - - - - -
-
- 不了解配置?请见 官方文档 + 不了解配置?请见 官方文档加群询问
From c5e944744b070584d429409876f827dcfeb679db Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 15:44:52 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=F0=9F=8F=97=20refactor:=20enhance=20Conf?= =?UTF-8?q?igPage=20layout=20and=20styling=20for=20better=20user=20experie?= =?UTF-8?q?nce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/views/ConfigPage.vue | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dashboard/src/views/ConfigPage.vue b/dashboard/src/views/ConfigPage.vue index d7f0f4ecb..55d6e8e33 100644 --- a/dashboard/src/views/ConfigPage.vue +++ b/dashboard/src/views/ConfigPage.vue @@ -42,9 +42,16 @@ import config from '@/config';
+ v-show="key2 !== 'platform' && key2 !== 'provider'" style="border: 1px solid #e0e0e0; padding: 8px; margin-bottom: 16px; border-radius: 10px"> + + {{ metadata[key]['metadata'][key2]['description'] }} ({{ key2 }}) + + object + + @@ -70,14 +77,14 @@ import config from '@/config'; - +
删除这项 - +
From 4fe1ebaa5b148535c3ba026c6ca17be971401ef3 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 15:59:20 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=F0=9F=8F=97=20refactor:=20improve=20styl?= =?UTF-8?q?ing=20and=20layout=20of=20AstrBotConfig=20component=20for=20enh?= =?UTF-8?q?anced=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/components/shared/AstrBotConfig.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index 38d3f3c27..f5aa2ade3 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -1,6 +1,6 @@ From bd3dab8aaedee0fef8180a7e0cd58bc49d8a2a98 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 16:36:35 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=9A=84=E6=8F=92=E4=BB=B6=E7=AE=80=E4=BB=8B?= =?UTF-8?q?=E5=A4=AA=E9=95=BF=20=E2=80=9C=E5=B8=AE=E5=8A=A9=E2=80=9D?= =?UTF-8?q?=E2=80=9C=E6=93=8D=E4=BD=9C=E2=80=9D=E5=9B=BE=E6=A0=87=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20#790?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 2 +- dashboard/src/components/shared/ExtensionCard.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 4e8db43f3..ba87ba528 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -342,7 +342,7 @@ CONFIG_METADATA_2 = { "type": "list", "items": {"type": "string"}, "obvious_hint": True, - "hint": "AstrBot 只处理所填写的 ID 发来的消息事件。为空时不启用白名单过滤。可以使用 /sid 指令获取在某个平台上的会话 ID。也可在 AstrBot 日志内获取会话 ID,当一条消息没通过白名单时,会输出 INFO 级别的日志。会话 ID 类似 aiocqhttp:GroupMessage:547540978。管理员可使用 /wl 添加白名单", + "hint": "只处理所填写的 ID 发来的消息事件。为空时不启用白名单过滤。可以使用 /sid 指令获取在某个平台上的会话 ID。会话 ID 类似 aiocqhttp:GroupMessage:547540978。管理员可使用 /wl 添加白名单", }, "id_whitelist_log": { "description": "打印白名单日志", diff --git a/dashboard/src/components/shared/ExtensionCard.vue b/dashboard/src/components/shared/ExtensionCard.vue index 5f9066e60..6b30460d4 100644 --- a/dashboard/src/components/shared/ExtensionCard.vue +++ b/dashboard/src/components/shared/ExtensionCard.vue @@ -99,7 +99,7 @@ const viewHandlers = () => {
-
+
{{ extension.desc }}
From a24eb9d9b0e20b599f1aafa52b845892baa13317 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 16:40:59 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=F0=9F=8F=97=20refactor:=20clean=20up=20A?= =?UTF-8?q?strBotConfig=20component=20markup=20for=20improved=20readabilit?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/shared/AstrBotConfig.vue | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/dashboard/src/components/shared/AstrBotConfig.vue b/dashboard/src/components/shared/AstrBotConfig.vue index f5aa2ade3..cc39f7ff0 100644 --- a/dashboard/src/components/shared/AstrBotConfig.vue +++ b/dashboard/src/components/shared/AstrBotConfig.vue @@ -14,7 +14,7 @@ -
@@ -51,8 +51,7 @@ v-if="metadata[metadataKey].items[key]?.options && !metadata[metadataKey].items[key]?.invisible" v-model="iterable[key]" variant="outlined" :items="metadata[metadataKey].items[key]?.options" dense - :disabled="metadata[metadataKey].items[key]?.readonly" density="compact" - flat hide-details + :disabled="metadata[metadataKey].items[key]?.readonly" density="compact" flat hide-details single-line> + v-model="iterable[key]" variant="outlined" dense flat hide-details single-line> @@ -80,8 +76,8 @@
- - +
@@ -128,7 +124,7 @@ - +
From efa287ed35c5a12424f6f4d52285adcf6156c1ce Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 17:40:28 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=94=AF=E6=8C=81=20?= =?UTF-8?q?LLM=20=E5=AF=B9=E5=BC=95=E7=94=A8=E6=B6=88=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E6=84=9F=E7=9F=A5=20#783?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/telegram/tg_adapter.py | 48 +++++++++++++++---- packages/astrbot/main.py | 20 ++++++-- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index b7d7a6e7e..3dde1802b 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -17,6 +17,7 @@ from astrbot.api.message_components import ( File as AstrBotFile, Video, At, + Reply, ) from astrbot.core.platform.astr_message_event import MessageSesion from astrbot.api.platform import register_platform_adapter @@ -68,7 +69,7 @@ class TelegramPlatformAdapter(Platform): ) message_handler = TelegramMessageHandler( filters=filters.ALL, # receive all messages - callback=self.convert_message, + callback=self.message_handler, ) self.application.add_handler(message_handler) self.client = self.application.bot @@ -104,33 +105,64 @@ class TelegramPlatformAdapter(Platform): chat_id=update.effective_chat.id, text=self.config["start_message"] ) + async def message_handler(self, update: Update, context: ContextTypes.DEFAULT_TYPE): + logger.debug(f"Telegram message: {update.message}") + abm = await self.convert_message(update, context) + await self.handle_msg(abm) + async def convert_message( - self, update: Update, context: ContextTypes.DEFAULT_TYPE + self, update: Update, context: ContextTypes.DEFAULT_TYPE, get_reply=True ) -> AstrBotMessage: + """转换 Telegram 的消息对象为 AstrBotMessage 对象。 + + @param update: Telegram 的 Update 对象。 + @param context: Telegram 的 Context 对象。 + @param get_reply: 是否获取回复消息。这个参数是为了防止多个回复嵌套。 + """ message = AstrBotMessage() # 获得是群聊还是私聊 - if update.effective_chat.type == ChatType.PRIVATE: + if update.message.chat.type == ChatType.PRIVATE: message.type = MessageType.FRIEND_MESSAGE else: message.type = MessageType.GROUP_MESSAGE - message.group_id = str(update.effective_chat.id) + message.group_id = str(update.message.chat.id) if update.message.message_thread_id: # Topic Group message.group_id += "#" + str(update.message.message_thread_id) message.message_id = str(update.message.message_id) - message.session_id = str(update.effective_chat.id) + message.session_id = str(update.message.chat.id) message.sender = MessageMember( - str(update.effective_user.id), update.effective_user.username + str(update.message.from_user.id), update.message.from_user.username ) message.self_id = str(context.bot.username) message.raw_message = update message.message_str = "" message.message = [] - logger.debug(f"Telegram message: {update.message}") + if update.message.reply_to_message: + # 获取回复消息 + reply_update = Update( + update_id=1, + message=update.message.reply_to_message, + ) + reply_abm = await self.convert_message(reply_update, context, False) + + message.message.append( + Reply( + id=reply_abm.message_id, + chain=reply_abm.message, + sender_id=reply_abm.sender.user_id, + sender_nickname=reply_abm.sender.nickname, + time=reply_abm.timestamp, + message_str=reply_abm.message_str, + text=reply_abm.message_str, + qq=reply_abm.sender.user_id, + ) + ) if update.message.text: + # 处理文本消息 plain_text = update.message.text if update.message.entities: @@ -178,7 +210,7 @@ class TelegramPlatformAdapter(Platform): Video(file=file.file_path, path=file.file_path), ] - await self.handle_msg(message) + return message async def handle_msg(self, message: AstrBotMessage): message_event = TelegramPlatformEvent( diff --git a/packages/astrbot/main.py b/packages/astrbot/main.py index c8ed2564d..463f24950 100644 --- a/packages/astrbot/main.py +++ b/packages/astrbot/main.py @@ -17,7 +17,7 @@ from astrbot.core.star.filter.permission import PermissionTypeFilter from astrbot.core.config.default import VERSION from .long_term_memory import LongTermMemory from astrbot.core import logger -from astrbot.api.message_components import Plain, Image +from astrbot.api.message_components import Plain, Image, Reply from typing import Union @@ -1088,12 +1088,17 @@ UID: {user_id} 此 ID 可用于设置管理员。 @filter.on_llm_request() async def decorate_llm_req(self, event: AstrMessageEvent, req: ProviderRequest): - """在请求 LLM 前注入人格信息、Identifier、时间等 System Prompt""" - logger.debug(req.conversation) - + """在请求 LLM 前注入人格信息、Identifier、时间、回复内容等 System Prompt""" if self.prompt_prefix: req.prompt = self.prompt_prefix + req.prompt + # 解析引用内容 + quote = None + for comp in event.message_obj.message: + if isinstance(comp, Reply): + quote = comp + break + if self.identifier: user_id = event.message_obj.sender.user_id user_nickname = event.message_obj.sender.nickname @@ -1129,6 +1134,13 @@ UID: {user_id} 此 ID 可用于设置管理员。 if begin_dialogs := persona["_begin_dialogs_processed"]: req.contexts[:0] = begin_dialogs + if quote and quote.message_str: + if quote.sender_nickname: + sender_info = f"(Sent by {quote.sender_nickname})" + else: + sender_info = "" + req.system_prompt += f"\nUser is quoting the message{sender_info}: {quote.message_str}, please consider the context." + if self.ltm: try: await self.ltm.on_req_llm(event, req) From 60e58b4f5f359030f81db08f52dadfe035c7d8af Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 09:52:03 +0000 Subject: [PATCH 15/17] :balloon: auto fixes by pre-commit hooks --- astrbot/core/platform/astr_message_event.py | 2 +- astrbot/core/provider/func_tool_manager.py | 1 + astrbot/core/star/star_manager.py | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/astrbot/core/platform/astr_message_event.py b/astrbot/core/platform/astr_message_event.py index 9ae3c99f7..fceb63ce7 100644 --- a/astrbot/core/platform/astr_message_event.py +++ b/astrbot/core/platform/astr_message_event.py @@ -14,7 +14,7 @@ from astrbot.core.message.components import ( At, AtAll, Forward, - Reply + Reply, ) from astrbot.core.utils.metrics import Metric from astrbot.core.provider.entites import ProviderRequest diff --git a/astrbot/core/provider/func_tool_manager.py b/astrbot/core/provider/func_tool_manager.py index 42b88cae2..cdb1b3d6d 100644 --- a/astrbot/core/provider/func_tool_manager.py +++ b/astrbot/core/provider/func_tool_manager.py @@ -4,6 +4,7 @@ from typing import Dict, List, Awaitable from dataclasses import dataclass from astrbot import logger + @dataclass class FuncTool: """ diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 9fa27798b..347bc13ef 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -485,7 +485,9 @@ class PluginManager: for handler in star_handlers_registry.get_handlers_by_module_name( plugin_module_path ): - logger.info(f"移除了插件 {plugin_name} 的处理函数 {handler.handler_name} ({len(star_handlers_registry)})") + logger.info( + f"移除了插件 {plugin_name} 的处理函数 {handler.handler_name} ({len(star_handlers_registry)})" + ) star_handlers_registry.remove(handler) keys_to_delete = [ k From b52a44a7dd068a95a96a7e2b0eb548bd38b12c1e Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 20:44:08 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=F0=9F=8E=A8=20stype:=20format=20codes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/star/register/star_handler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astrbot/core/star/register/star_handler.py b/astrbot/core/star/register/star_handler.py index 86620cae6..77d7fb482 100644 --- a/astrbot/core/star/register/star_handler.py +++ b/astrbot/core/star/register/star_handler.py @@ -15,7 +15,6 @@ from ..filter.regex import RegexFilter from typing import Awaitable from astrbot.core.provider.func_tool_manager import SUPPORTED_TYPES from astrbot.core.provider.register import llm_tools -from astrbot.core import logger def get_handler_full_name(awaitable: Awaitable) -> str: From 0870b87c961863d8527ba2e5fae6ddd9bb3d959f Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 13 Mar 2025 20:59:52 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E6=B6=88=E6=81=AF=E5=A4=B1=E8=B4=A5=E6=97=B6?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=B0=86=E5=BC=95=E7=94=A8=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=AE=B5=E5=8A=A0=E5=85=A5=E6=B6=88=E6=81=AF=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py | 4 +++- 1 file changed, 3 insertions(+), 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 e81e7153f..0d11e3c0b 100644 --- a/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py +++ b/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py @@ -273,7 +273,9 @@ class AiocqhttpAdapter(Platform): abm.message.append(reply_seg) except BaseException as e: - logger.error(f"获取消息失败: {e},此消息段将被忽略。") + logger.error(f"获取引用消息失败: {e}。") + a = ComponentTypes[t](**m["data"]) # noqa: F405 + abm.message.append(a) else: a = ComponentTypes[t](**m["data"]) # noqa: F405 abm.message.append(a)