mioku-plugin-media 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/error-handler.ts +1 -33
package/package.json
CHANGED
package/utils/error-handler.ts
CHANGED
|
@@ -22,39 +22,7 @@ export async function handleMediaError(options: {
|
|
|
22
22
|
platform: string;
|
|
23
23
|
config: MediaConfig;
|
|
24
24
|
}): Promise<void> {
|
|
25
|
-
const { ctx,
|
|
25
|
+
const { ctx, error, platform } = options;
|
|
26
26
|
const errorMessage = normalizeErrorMessage(error);
|
|
27
27
|
ctx.logger.error(`[media] ${platform} 解析失败: ${errorMessage}`);
|
|
28
|
-
|
|
29
|
-
// 尝试获取 bot 发送错误信息给用户
|
|
30
|
-
const selfId = event?.self_id != null ? Number(event.self_id) : undefined;
|
|
31
|
-
const bot =
|
|
32
|
-
selfId != null && typeof ctx?.pickBot === "function"
|
|
33
|
-
? ctx.pickBot(selfId)
|
|
34
|
-
: undefined;
|
|
35
|
-
|
|
36
|
-
if (!bot) return;
|
|
37
|
-
|
|
38
|
-
const nickname = String(
|
|
39
|
-
ctx?.bot?.nickname ||
|
|
40
|
-
event?.sender?.card ||
|
|
41
|
-
event?.sender?.nickname ||
|
|
42
|
-
"媒体解析",
|
|
43
|
-
);
|
|
44
|
-
const userId = String(selfId || event?.self_id || 0);
|
|
45
|
-
|
|
46
|
-
// 构建错误提示消息
|
|
47
|
-
const errorText = `【${platform}】解析失败\n${errorMessage}`;
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
if (event?.message_type === "group" && event?.group_id != null) {
|
|
51
|
-
await bot.sendGroupMsg(event.group_id, [ctx.segment.text(errorText)]);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (event?.user_id != null) {
|
|
55
|
-
await bot.sendPrivateMsg(event.user_id, [ctx.segment.text(errorText)]);
|
|
56
|
-
}
|
|
57
|
-
} catch {
|
|
58
|
-
// ignore send errors
|
|
59
|
-
}
|
|
60
28
|
}
|