koishi-plugin-best-cave 2.3.15 → 2.3.16
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/lib/Utils.d.ts +3 -2
- package/lib/index.js +51 -13
- package/package.json +1 -1
package/lib/Utils.d.ts
CHANGED
|
@@ -9,9 +9,10 @@ import { PendManager } from './PendManager';
|
|
|
9
9
|
* @param config 插件配置。
|
|
10
10
|
* @param fileManager 文件管理器实例。
|
|
11
11
|
* @param logger 日志记录器实例。
|
|
12
|
-
* @
|
|
12
|
+
* @param platform 目标平台名称 (e.g., 'onebot')。
|
|
13
|
+
* @returns 包含多条消息的数组,每条消息是一个 (string | h)[] 数组。
|
|
13
14
|
*/
|
|
14
|
-
export declare function buildCaveMessage(cave: CaveObject, config: Config, fileManager: FileManager, logger: Logger): Promise<(string | h)[]>;
|
|
15
|
+
export declare function buildCaveMessage(cave: CaveObject, config: Config, fileManager: FileManager, logger: Logger, platform?: string): Promise<(string | h)[][]>;
|
|
15
16
|
/**
|
|
16
17
|
* @description 清理数据库中标记为 'delete' 状态的回声洞及其关联文件和哈希。
|
|
17
18
|
* @param ctx Koishi 上下文。
|
package/lib/index.js
CHANGED
|
@@ -292,7 +292,7 @@ var import_koishi2 = require("koishi");
|
|
|
292
292
|
var import_koishi = require("koishi");
|
|
293
293
|
var path2 = __toESM(require("path"));
|
|
294
294
|
var mimeTypeMap = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".mp4": "video/mp4", ".mp3": "audio/mpeg", ".webp": "image/webp" };
|
|
295
|
-
async function buildCaveMessage(cave, config, fileManager, logger2) {
|
|
295
|
+
async function buildCaveMessage(cave, config, fileManager, logger2, platform) {
|
|
296
296
|
async function transformToH(elements) {
|
|
297
297
|
return Promise.all(elements.map(async (el) => {
|
|
298
298
|
if (el.type === "text") return import_koishi.h.text(el.content);
|
|
@@ -337,11 +337,31 @@ async function buildCaveMessage(cave, config, fileManager, logger2) {
|
|
|
337
337
|
const caveHElements = await transformToH(cave.elements);
|
|
338
338
|
const replacements = { id: cave.id.toString(), name: cave.userName };
|
|
339
339
|
const [header, footer] = config.caveFormat.split("|", 2).map((part) => part.replace(/\{id\}|\{name\}/g, (match) => replacements[match.slice(1, -1)]).trim());
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (
|
|
344
|
-
|
|
340
|
+
const problematicTypes = ["video", "audio", "file", "forward"];
|
|
341
|
+
const placeholderMap = { video: "[视频]", audio: "[音频]", file: "[文件]", forward: "[合并转发]" };
|
|
342
|
+
const containsProblematic = platform === "onebot" && caveHElements.some((el) => problematicTypes.includes(el.type));
|
|
343
|
+
if (!containsProblematic) {
|
|
344
|
+
const finalMessage = [];
|
|
345
|
+
if (header) finalMessage.push(header + "\n");
|
|
346
|
+
finalMessage.push(...caveHElements);
|
|
347
|
+
if (footer) finalMessage.push("\n" + footer);
|
|
348
|
+
return [finalMessage.length > 0 ? finalMessage : []];
|
|
349
|
+
}
|
|
350
|
+
const initialMessageContent = [];
|
|
351
|
+
const followUpMessages = [];
|
|
352
|
+
for (const el of caveHElements) {
|
|
353
|
+
if (problematicTypes.includes(el.type)) {
|
|
354
|
+
initialMessageContent.push(import_koishi.h.text(placeholderMap[el.type]));
|
|
355
|
+
followUpMessages.push([el]);
|
|
356
|
+
} else {
|
|
357
|
+
initialMessageContent.push(el);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const finalInitialMessage = [];
|
|
361
|
+
if (header) finalInitialMessage.push(header + "\n");
|
|
362
|
+
finalInitialMessage.push(...initialMessageContent);
|
|
363
|
+
if (footer) finalInitialMessage.push("\n" + footer);
|
|
364
|
+
return [finalInitialMessage, ...followUpMessages].filter((msg) => msg.length > 0);
|
|
345
365
|
}
|
|
346
366
|
__name(buildCaveMessage, "buildCaveMessage");
|
|
347
367
|
async function cleanupPendingDeletions(ctx, fileManager, logger2, reusableIds) {
|
|
@@ -564,7 +584,12 @@ var PendManager = class {
|
|
|
564
584
|
const [targetCave] = await this.ctx.database.get("cave", { id });
|
|
565
585
|
if (!targetCave) return `回声洞(${id})不存在`;
|
|
566
586
|
if (targetCave.status !== "pending") return `回声洞(${id})无需审核`;
|
|
567
|
-
|
|
587
|
+
await session.send("待审核");
|
|
588
|
+
const caveMessages = await buildCaveMessage(targetCave, this.config, this.fileManager, this.logger, session.platform);
|
|
589
|
+
for (const message of caveMessages) {
|
|
590
|
+
if (message.length > 0) await session.send(import_koishi2.h.normalize(message));
|
|
591
|
+
}
|
|
592
|
+
return;
|
|
568
593
|
}
|
|
569
594
|
const pendingCaves = await this.ctx.database.get("cave", { status: "pending" }, { fields: ["id"] });
|
|
570
595
|
if (!pendingCaves.length) return "当前没有需要审核的回声洞";
|
|
@@ -608,8 +633,12 @@ ${pendingCaves.map((c) => c.id).join("|")}`;
|
|
|
608
633
|
return;
|
|
609
634
|
}
|
|
610
635
|
try {
|
|
611
|
-
const
|
|
612
|
-
await
|
|
636
|
+
const [platform] = this.config.adminChannel.split(":", 1);
|
|
637
|
+
const caveMessages = await buildCaveMessage(cave, this.config, this.fileManager, this.logger, platform);
|
|
638
|
+
await this.ctx.broadcast([this.config.adminChannel], "待审核");
|
|
639
|
+
for (const message of caveMessages) {
|
|
640
|
+
if (message.length > 0) await this.ctx.broadcast([this.config.adminChannel], import_koishi2.h.normalize(message));
|
|
641
|
+
}
|
|
613
642
|
} catch (error) {
|
|
614
643
|
this.logger.error(`发送回声洞(${cave.id})审核消息失败:`, error);
|
|
615
644
|
}
|
|
@@ -1067,7 +1096,10 @@ function apply(ctx, config) {
|
|
|
1067
1096
|
const randomId = candidates[Math.floor(Math.random() * candidates.length)].id;
|
|
1068
1097
|
const [randomCave] = await ctx.database.get("cave", { ...query, id: randomId });
|
|
1069
1098
|
updateCooldownTimestamp(session, config, lastUsed);
|
|
1070
|
-
|
|
1099
|
+
const messages = await buildCaveMessage(randomCave, config, fileManager, logger, session.platform);
|
|
1100
|
+
for (const message of messages) {
|
|
1101
|
+
if (message.length > 0) await session.send(import_koishi3.h.normalize(message));
|
|
1102
|
+
}
|
|
1071
1103
|
} catch (error) {
|
|
1072
1104
|
logger.error("随机获取回声洞失败:", error);
|
|
1073
1105
|
return "随机获取回声洞失败";
|
|
@@ -1152,7 +1184,10 @@ ${JSON.stringify(finalElementsForDb, null, 2)}`);
|
|
|
1152
1184
|
const [targetCave] = await ctx.database.get("cave", { ...getScopeQuery(session, config), id });
|
|
1153
1185
|
if (!targetCave) return `回声洞(${id})不存在`;
|
|
1154
1186
|
updateCooldownTimestamp(session, config, lastUsed);
|
|
1155
|
-
|
|
1187
|
+
const messages = await buildCaveMessage(targetCave, config, fileManager, logger, session.platform);
|
|
1188
|
+
for (const message of messages) {
|
|
1189
|
+
if (message.length > 0) await session.send(import_koishi3.h.normalize(message));
|
|
1190
|
+
}
|
|
1156
1191
|
} catch (error) {
|
|
1157
1192
|
logger.error(`查看回声洞(${id})失败:`, error);
|
|
1158
1193
|
return "查看失败,请稍后再试";
|
|
@@ -1167,9 +1202,12 @@ ${JSON.stringify(finalElementsForDb, null, 2)}`);
|
|
|
1167
1202
|
const isAdmin = session.channelId === config.adminChannel?.split(":")[1];
|
|
1168
1203
|
if (!isAuthor && !isAdmin) return "你没有权限删除这条回声洞";
|
|
1169
1204
|
await ctx.database.upsert("cave", [{ id, status: "delete" }]);
|
|
1170
|
-
const
|
|
1205
|
+
const caveMessages = await buildCaveMessage(targetCave, config, fileManager, logger, session.platform);
|
|
1171
1206
|
cleanupPendingDeletions(ctx, fileManager, logger, reusableIds);
|
|
1172
|
-
|
|
1207
|
+
await session.send("已删除");
|
|
1208
|
+
for (const message of caveMessages) {
|
|
1209
|
+
if (message.length > 0) await session.send(import_koishi3.h.normalize(message));
|
|
1210
|
+
}
|
|
1173
1211
|
} catch (error) {
|
|
1174
1212
|
logger.error(`标记回声洞(${id})失败:`, error);
|
|
1175
1213
|
return "删除失败,请稍后再试";
|