Skip to content

Commit 4c546f2

Browse files
authored
Merge branch 'master' into better-stream
2 parents 3753fce + 4c02857 commit 4c546f2

19 files changed

Lines changed: 603 additions & 339 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ _✨ 易上手的多平台 LLM 聊天机器人及开发框架 ✨_
1313
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Soulter/AstrBot?style=for-the-badge&color=76bad9)](https://github.com/Soulter/AstrBot/releases/latest)
1414
<img src="https://img.shields.io/badge/python-3.10+-blue.svg?style=for-the-badge&color=76bad9" alt="python">
1515
<a href="https://hub.docker.com/r/soulter/astrbot"><img alt="Docker pull" src="https://img.shields.io/docker/pulls/soulter/astrbot.svg?style=for-the-badge&color=76bad9"/></a>
16-
<a href="https://qm.qq.com/cgi-bin/qm/qr?k=wtbaNx7EioxeaqS9z7RQWVXPIxg2zYr7&jump_from=webapi&authKey=vlqnv/AV2DbJEvGIcxdlNSpfxVy+8vVqijgreRdnVKOaydpc+YSw4MctmEbr0k5"><img alt="Static Badge" src="https://img.shields.io/badge/QQ群-775869627-purple?style=for-the-badge&color=76bad9"></a>
16+
<a href="https://qm.qq.com/cgi-bin/qm/qr?k=wtbaNx7EioxeaqS9z7RQWVXPIxg2zYr7&jump_from=webapi&authKey=vlqnv/AV2DbJEvGIcxdlNSpfxVy+8vVqijgreRdnVKOaydpc+YSw4MctmEbr0k5"><img alt="QQ_community" src="https://img.shields.io/badge/QQ群-775869627-purple?style=for-the-badge&color=76bad9"></a>
17+
<a href="https://t.me/+hAsD2Ebl5as3NmY1"><img alt="Telegram_community" src="https://img.shields.io/badge/Telegram-AstrBot-purple?style=for-the-badge&color=76bad9"></a>
1718
[![wakatime](https://wakatime.com/badge/user/915e5316-99c6-4563-a483-ef186cf000c9/project/018e705a-a1a7-409a-a849-3013485e6c8e.svg?style=for-the-badge&color=76bad9)](https://wakatime.com/badge/user/915e5316-99c6-4563-a483-ef186cf000c9/project/018e705a-a1a7-409a-a849-3013485e6c8e)
18-
![Dynamic JSON Badge](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.soulter.top%2Fastrbot%2Fstats&query=v&label=7%E6%97%A5%E6%B4%BB%E8%B7%83%E9%87%8F&cacheSeconds=10800&style=for-the-badge&color=3b618e)
19-
![Dynamic JSON Badge](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.soulter.top%2Fastrbot%2Fplugin-num&query=%24.result&suffix=%E4%B8%AA&style=for-the-badge&label=%E6%8F%92%E4%BB%B6%E5%B8%82%E5%9C%BA&cacheSeconds=7200)
19+
![Dynamic JSON Badge](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.soulter.top%2Fastrbot%2Fstats&query=v&label=7%E6%97%A5%E6%B4%BB%E8%B7%83%E9%87%8F&cacheSeconds=3600&style=for-the-badge&color=3b618e)
20+
![Dynamic JSON Badge](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.soulter.top%2Fastrbot%2Fplugin-num&query=%24.result&suffix=%E4%B8%AA&style=for-the-badge&label=%E6%8F%92%E4%BB%B6%E5%B8%82%E5%9C%BA&cacheSeconds=3600)
2021

2122

2223
<a href="https://github.com/Soulter/AstrBot/blob/master/README_en.md">English</a> |

astrbot/core/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
sp = (
2424
SharedPreferences()
2525
) # 简单的偏好设置存储, 这里后续应该存储到数据库中, 一些部分可以存储到配置中
26-
pip_installer = PipInstaller(astrbot_config.get("pip_install_arg", ""))
26+
pip_installer = PipInstaller(
27+
astrbot_config.get("pip_install_arg", ""),
28+
astrbot_config.get("pypi_index_url", None),
29+
)
2730
web_chat_queue = asyncio.Queue(maxsize=32)
2831
web_chat_back_queue = asyncio.Queue(maxsize=32)
2932
WEBUI_SK = "Advanced_System_for_Text_Response_and_Bot_Operations_Tool"

astrbot/core/config/default.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"wake_prefix": ["/"],
9999
"log_level": "INFO",
100100
"pip_install_arg": "",
101-
"plugin_repo_mirror": "",
101+
"pypi_index_url": "https://mirrors.aliyun.com/pypi/simple/",
102102
"knowledge_db": {},
103103
"persona": [],
104104
"timezone": "",
@@ -529,6 +529,7 @@
529529
"model": "gemini-2.0-flash-exp",
530530
},
531531
"gm_resp_image_modal": False,
532+
"gm_native_coderunner": False,
532533
"gm_safety_settings": {
533534
"harassment": "BLOCK_MEDIUM_AND_ABOVE",
534535
"hate_speech": "BLOCK_MEDIUM_AND_ABOVE",
@@ -705,6 +706,12 @@
705706
"type": "bool",
706707
"hint": "启用后,将支持返回图片内容。需要模型支持,否则会报错。具体支持模型请查看 Google Gemini 官方网站。温馨提示,如果您需要生成图片,请关闭 `启用群员识别` 配置获得更好的效果。",
707708
},
709+
"gm_native_coderunner": {
710+
"description": "启用原生代码执行器",
711+
"type": "bool",
712+
"hint": "启用后所有函数工具将全部失效",
713+
"obvious_hint": True,
714+
},
708715
"gm_safety_settings": {
709716
"description": "安全过滤器",
710717
"type": "object",
@@ -1222,16 +1229,10 @@
12221229
"type": "string",
12231230
"hint": "安装插件依赖时,会使用 Python 的 pip 工具。这里可以填写额外的参数,如 `--break-system-package` 等。",
12241231
},
1225-
"plugin_repo_mirror": {
1226-
"description": "插件仓库镜像",
1232+
"pypi_index_url": {
1233+
"description": "PyPI 软件仓库地址",
12271234
"type": "string",
1228-
"hint": "已废弃,请使用管理面板->设置页的代理地址选择",
1229-
"obvious_hint": True,
1230-
"options": [
1231-
"default",
1232-
"https://ghp.ci/",
1233-
"https://github-mirror.us.kg/",
1234-
],
1235+
"hint": "安装 Python 依赖时请求的 PyPI 软件仓库地址。默认为 https://mirrors.aliyun.com/pypi/simple/",
12351236
},
12361237
},
12371238
},

astrbot/core/core_lifecycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def initialize(self):
106106
await self.pipeline_scheduler.initialize()
107107

108108
# 初始化更新器
109-
self.astrbot_updator = AstrBotUpdator(self.astrbot_config["plugin_repo_mirror"])
109+
self.astrbot_updator = AstrBotUpdator()
110110

111111
# 初始化事件总线
112112
self.event_bus = EventBus(self.event_queue, self.pipeline_scheduler)

astrbot/core/platform/astr_message_event.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import abc
22
import asyncio
33
import re
4+
import hashlib
5+
import uuid
46
from dataclasses import dataclass
57
from typing import List, Union, Optional, AsyncGenerator
68

@@ -402,8 +404,13 @@ async def send(self, message: MessageChain):
402404
Args:
403405
message (MessageChain): 消息链,具体使用方式请参考文档。
404406
"""
407+
# Leverage BLAKE2 hash function to generate a non-reversible hash of the sender ID for privacy.
408+
hash_obj = hashlib.blake2b(self.get_sender_id().encode("utf-8"), digest_size=16)
409+
sid = str(uuid.UUID(bytes=hash_obj.digest()))
405410
asyncio.create_task(
406-
Metric.upload(msg_event_tick=1, adapter_name=self.platform_meta.name)
411+
Metric.upload(
412+
msg_event_tick=1, adapter_name=self.platform_meta.name, sid=sid
413+
)
407414
)
408415
self._has_send_oper = True
409416

astrbot/core/platform/sources/aiocqhttp/aiocqhttp_message_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def _parse_onebot_json(message_chain: MessageChain):
3030
# convert to base64
3131
bs64 = await segment.convert_to_base64()
3232
d["data"] = {
33-
"file": bs64,
33+
"file": f"base64://{bs64}",
3434
}
3535
elif isinstance(segment, At):
3636
d["data"] = {

astrbot/core/platform/sources/telegram/tg_adapter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import re
23
import sys
34
import uuid
45

@@ -118,8 +119,6 @@ async def register_commands(self):
118119

119120
if commands:
120121
await self.client.set_my_commands(commands)
121-
for cmd in commands:
122-
logger.debug(f"已注册指令: /{cmd.command} - {cmd.description}")
123122

124123
except Exception as e:
125124
logger.error(f"向 Telegram 注册指令时发生错误: {e!s}")
@@ -167,6 +166,10 @@ def _extract_command_info(
167166
if not cmd_name or cmd_name in skip_commands:
168167
return None
169168

169+
if not re.match(r"^[a-z0-9_]+$", cmd_name) or len(cmd_name) > 32:
170+
logger.warning(f"跳过无法注册的命令: {cmd_name}")
171+
return None
172+
170173
# Build description.
171174
description = handler_metadata.desc or (
172175
f"指令组: {cmd_name} (包含多个子指令)" if is_group else f"指令: {cmd_name}"

astrbot/core/provider/entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async def assemble_context(self) -> Dict:
155155
if self.image_urls:
156156
user_content = {
157157
"role": "user",
158-
"content": [{"type": "text", "text": self.prompt}],
158+
"content": [{"type": "text", "text": self.prompt if self.prompt else "[图片]"}],
159159
}
160160
for image_url in self.image_urls:
161161
if image_url.startswith("http"):

0 commit comments

Comments
 (0)