diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index 93ed6feb..b12478d5 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -133,7 +133,11 @@ class TelegramPlatformAdapter(Platform): message.message_str = "" message.message = [] - if update.message.reply_to_message: + if update.message.reply_to_message and not ( + update.message.is_topic_message + and update.message.message_thread_id + == update.message.reply_to_message.message_id + ): # 获取回复消息 reply_update = Update( update_id=1, @@ -199,6 +203,15 @@ class TelegramPlatformAdapter(Platform): ] message.message.append(Comp.At(qq=name, name=name)) + elif update.message.sticker: + # 将sticker当作图片处理 + file = await update.message.sticker.get_file() + message.message.append(Comp.Image(file=file.file_path, url=file.file_path)) + if update.message.sticker.emoji: + sticker_text = f"Sticker: {update.message.sticker.emoji}" + message.message_str = sticker_text + message.message.append(Comp.Plain(sticker_text)) + elif update.message.document: file = await update.message.document.get_file() message.message = [ diff --git a/astrbot/core/utils/io.py b/astrbot/core/utils/io.py index 318a6183..7393cb42 100644 --- a/astrbot/core/utils/io.py +++ b/astrbot/core/utils/io.py @@ -8,6 +8,9 @@ import base64 import zipfile import uuid import psutil + +import certifi + from typing import Union from PIL import Image @@ -81,7 +84,13 @@ async def download_image_by_url( 下载图片, 返回 path """ try: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context( + cafile=certifi.where() + ) # 使用 certifi 提供的 CA 证书 + connector = aiohttp.TCPConnector(ssl=ssl_context) # 使用 certifi 的根证书 + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: if post: async with session.post(url, json=post_data) as resp: if not path: @@ -118,7 +127,13 @@ async def download_file(url: str, path: str, show_progress: bool = False): 从指定 url 下载文件到指定路径 path """ try: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context( + cafile=certifi.where() + ) # 使用 certifi 提供的 CA 证书 + connector = aiohttp.TCPConnector(ssl=ssl_context) + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.get(url, timeout=1800) as resp: if resp.status != 200: raise Exception(f"下载文件失败: {resp.status}") diff --git a/astrbot/core/utils/t2i/local_strategy.py b/astrbot/core/utils/t2i/local_strategy.py index 23abba6e..aea3f481 100644 --- a/astrbot/core/utils/t2i/local_strategy.py +++ b/astrbot/core/utils/t2i/local_strategy.py @@ -1,5 +1,7 @@ import re import aiohttp +import ssl +import certifi from io import BytesIO from . import RenderStrategy @@ -91,7 +93,9 @@ class LocalRenderStrategy(RenderStrategy): try: image_url = re.findall(IMAGE_REGEX, line)[0] print(image_url) - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context(cafile=certifi.where()) + connector = aiohttp.TCPConnector(ssl=ssl_context) + async with aiohttp.ClientSession(trust_env=True, connector=connector) as session: async with session.get(image_url) as resp: image_res = Image.open(BytesIO(await resp.read())) images[i] = image_res diff --git a/astrbot/core/utils/t2i/network_strategy.py b/astrbot/core/utils/t2i/network_strategy.py index b9b9abff..f8f54b0d 100644 --- a/astrbot/core/utils/t2i/network_strategy.py +++ b/astrbot/core/utils/t2i/network_strategy.py @@ -1,5 +1,7 @@ import aiohttp import os +import ssl +import certifi from . import RenderStrategy from astrbot.core.config import VERSION @@ -46,7 +48,11 @@ class NetworkRenderStrategy(RenderStrategy): }, } if return_url: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context(cafile=certifi.where()) + connector = aiohttp.TCPConnector(ssl=ssl_context) + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.post( f"{self.BASE_RENDER_URL}/generate", json=post_data ) as resp: diff --git a/astrbot/core/zip_updator.py b/astrbot/core/zip_updator.py index 29533ea8..4622b47c 100644 --- a/astrbot/core/zip_updator.py +++ b/astrbot/core/zip_updator.py @@ -2,6 +2,10 @@ import aiohttp import os import zipfile import shutil + +import ssl +import certifi + from astrbot.core.utils.io import on_error, download_file from astrbot.core import logger @@ -33,10 +37,26 @@ class RepoZipUpdator: 返回一个列表,每个元素是一个字典,包含版本号、发布时间、更新内容、commit hash等信息。 """ try: - async with aiohttp.ClientSession(trust_env=True) as session: + ssl_context = ssl.create_default_context( + cafile=certifi.where() + ) # 新增:创建基于 certifi 的 SSL 上下文 + connector = aiohttp.TCPConnector( + ssl=ssl_context + ) # 新增:使用 TCPConnector 指定 SSL 上下文 + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.get(url) as response: + # 检查 HTTP 状态码 + if response.status != 200: + text = await response.text() + logger.error( + f"请求 {url} 失败,状态码: {response.status}, 内容: {text}" + ) + raise Exception(f"请求失败,状态码: {response.status}") result = await response.json() if not result: + logger.error("返回空的结果") return [] # if latest: # ret = self.github_api_release_parser([result[0]]) @@ -53,7 +73,8 @@ class RepoZipUpdator: "zipball_url": release["zipball_url"], } ) - except BaseException: + except Exception as e: + logger.error(f"解析版本信息时发生异常: {e}") raise Exception("解析版本信息失败") return ret diff --git a/astrbot/dashboard/routes/plugin.py b/astrbot/dashboard/routes/plugin.py index 6e90d73e..32dc9917 100644 --- a/astrbot/dashboard/routes/plugin.py +++ b/astrbot/dashboard/routes/plugin.py @@ -1,5 +1,9 @@ import traceback import aiohttp + +import ssl +import certifi + from .route import Route, Response, RouteContext from astrbot.core import logger from quart import request @@ -65,9 +69,14 @@ class PluginRoute(Route): else: urls = ["https://api.soulter.top/astrbot/plugins"] + # 新增:创建 SSL 上下文,使用 certifi 提供的根证书 + ssl_context = ssl.create_default_context(cafile=certifi.where()) + connector = aiohttp.TCPConnector(ssl=ssl_context) for url in urls: try: - async with aiohttp.ClientSession(trust_env=True) as session: + async with aiohttp.ClientSession( + trust_env=True, connector=connector + ) as session: async with session.get(url) as response: if response.status == 200: result = await response.json() diff --git a/astrbot/dashboard/routes/stat.py b/astrbot/dashboard/routes/stat.py index 04b2d21e..e73c0945 100644 --- a/astrbot/dashboard/routes/stat.py +++ b/astrbot/dashboard/routes/stat.py @@ -65,14 +65,9 @@ class StatRoute(Route): stat_dict = stat.__dict__ - # 获取CPU使用率 - 修复CPU始终为0的问题 - process = psutil.Process() - # 获取系统CPU使用率而不是进程CPU使用率 cpu_percent = psutil.cpu_percent(interval=0.5) - - # 获取线程数 thread_count = threading.active_count() - + # 获取插件信息 plugins = self.core_lifecycle.star_context.get_all_stars() plugin_info = [] @@ -80,7 +75,7 @@ class StatRoute(Route): info = { "name": getattr(plugin, "name", plugin.__class__.__name__), "version": getattr(plugin, "version", "1.0.0"), - "is_enabled": True + "is_enabled": True, } plugin_info.append(info) diff --git a/dashboard/src/views/PlatformPage.vue b/dashboard/src/views/PlatformPage.vue index 38fa08e6..1af95130 100644 --- a/dashboard/src/views/PlatformPage.vue +++ b/dashboard/src/views/PlatformPage.vue @@ -96,7 +96,7 @@ - + {{ updatingMode ? 'mdi-pencil' : 'mdi-plus' }} @@ -105,12 +105,12 @@ - + - + mdi-refresh 刷新 diff --git a/requirements.txt b/requirements.txt index 313dba0c..95983a2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,4 +25,5 @@ dashscope python-telegram-bot wechatpy dingtalk-stream -mcp \ No newline at end of file +mcp +certifi \ No newline at end of file