fix: 修复图片发送失败时的错误处理及路径配置

This commit is contained in:
sliverp
2026-01-30 18:33:54 +08:00
parent 6c6c5bd7fd
commit 0ace68d2a4
3 changed files with 23 additions and 4 deletions

9
moltbot.plugin.json Normal file
View File

@@ -0,0 +1,9 @@
{
"id": "qqbot",
"channels": ["qqbot"],
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}

9
openclaw.plugin.json Normal file
View File

@@ -0,0 +1,9 @@
{
"id": "qqbot",
"channels": ["qqbot"],
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}

View File

@@ -47,7 +47,8 @@ const QUICK_DISCONNECT_THRESHOLD = 5000; // 5秒内断开视为快速断开
// 图床服务器配置(可通过环境变量覆盖) // 图床服务器配置(可通过环境变量覆盖)
const IMAGE_SERVER_PORT = parseInt(process.env.QQBOT_IMAGE_SERVER_PORT || "18765", 10); const IMAGE_SERVER_PORT = parseInt(process.env.QQBOT_IMAGE_SERVER_PORT || "18765", 10);
const IMAGE_SERVER_DIR = process.env.QQBOT_IMAGE_SERVER_DIR || "./qqbot-images"; // 使用绝对路径,确保文件保存和读取使用同一目录
const IMAGE_SERVER_DIR = process.env.QQBOT_IMAGE_SERVER_DIR || path.join(process.env.HOME || "/home/ubuntu", "clawd", "qqbot-images");
export interface GatewayContext { export interface GatewayContext {
account: ResolvedQQBotAccount; account: ResolvedQQBotAccount;
@@ -550,9 +551,9 @@ export async function startGateway(ctx: GatewayContext): Promise<void> {
log?.info(`[qqbot:${account.accountId}] Sent image: ${imageUrl.slice(0, 50)}...`); log?.info(`[qqbot:${account.accountId}] Sent image: ${imageUrl.slice(0, 50)}...`);
} catch (imgErr) { } catch (imgErr) {
log?.error(`[qqbot:${account.accountId}] Failed to send image: ${imgErr}`); log?.error(`[qqbot:${account.accountId}] Failed to send image: ${imgErr}`);
// 图片发送失败时,把 URL 加回文本(已处理过点号的版本) // 图片发送失败时,显示错误信息而不是 URL
const safeUrl = imageUrl.replace(/([a-zA-Z0-9])\.([a-zA-Z0-9])/g, "$1_$2"); const errMsg = String(imgErr).slice(0, 200);
textWithoutImages = `[图片: ${safeUrl}]\n${textWithoutImages}`; textWithoutImages = `[图片发送失败: ${errMsg}]\n${textWithoutImages}`;
} }
} }