koishi-plugin-best-cave 2.3.8 → 2.3.9
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 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +37 -8
- package/package.json +1 -1
package/lib/Utils.d.ts
CHANGED
|
@@ -50,9 +50,11 @@ export declare function updateCooldownTimestamp(session: Session, config: Config
|
|
|
50
50
|
* @param sourceElements 原始的 Koishi 消息元素数组。
|
|
51
51
|
* @param newId 这条回声洞的新 ID。
|
|
52
52
|
* @param session 触发操作的会话。
|
|
53
|
+
* @param config 插件配置。
|
|
54
|
+
* @param logger 日志实例。
|
|
53
55
|
* @returns 包含数据库元素和待保存媒体列表的对象。
|
|
54
56
|
*/
|
|
55
|
-
export declare function processMessageElements(sourceElements: h[], newId: number, session: Session): Promise<{
|
|
57
|
+
export declare function processMessageElements(sourceElements: h[], newId: number, session: Session, config: Config, logger: Logger): Promise<{
|
|
56
58
|
finalElementsForDb: StoredElement[];
|
|
57
59
|
mediaToSave: {
|
|
58
60
|
sourceUrl: string;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -406,7 +406,7 @@ function updateCooldownTimestamp(session, config, lastUsed) {
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
__name(updateCooldownTimestamp, "updateCooldownTimestamp");
|
|
409
|
-
async function processMessageElements(sourceElements, newId, session) {
|
|
409
|
+
async function processMessageElements(sourceElements, newId, session, config, logger2) {
|
|
410
410
|
const mediaToSave = [];
|
|
411
411
|
let mediaIndex = 0;
|
|
412
412
|
async function transform(elements) {
|
|
@@ -415,28 +415,36 @@ async function processMessageElements(sourceElements, newId, session) {
|
|
|
415
415
|
const defaultExtMap = { "image": ".jpg", "video": ".mp4", "audio": ".mp3", "file": ".dat" };
|
|
416
416
|
for (const el of elements) {
|
|
417
417
|
const type = typeMap[el.type];
|
|
418
|
+
if (config.debug) logger2.info(`正在处理元素 <${el.type}>, 映射类型: ${type || "无"}`);
|
|
418
419
|
if (!type) {
|
|
419
420
|
if (el.children) result.push(...await transform(el.children));
|
|
420
421
|
continue;
|
|
421
422
|
}
|
|
422
423
|
if (type === "text" && el.attrs.content?.trim()) {
|
|
423
|
-
|
|
424
|
+
const content = el.attrs.content.trim();
|
|
425
|
+
if (config.debug) logger2.info(`发现 [text] 元素,内容: "${content}"`);
|
|
426
|
+
result.push({ type: "text", content });
|
|
424
427
|
} else if (type === "at" && el.attrs.id) {
|
|
428
|
+
if (config.debug) logger2.info(`发现 [at] 元素,ID: "${el.attrs.id}"`);
|
|
425
429
|
result.push({ type: "at", content: el.attrs.id });
|
|
426
430
|
} else if (type === "forward" && el.children?.length) {
|
|
431
|
+
if (config.debug) logger2.info(`发现 [forward] 元素,开始递归解析子元素...`);
|
|
427
432
|
const transformedChildren = await transform(el.children);
|
|
428
433
|
result.push({ type: "forward", content: JSON.stringify(transformedChildren) });
|
|
429
434
|
} else if (["image", "video", "audio", "file"].includes(type) && el.attrs.src) {
|
|
430
435
|
let fileIdentifier = el.attrs.src;
|
|
436
|
+
if (config.debug) logger2.info(`发现 [${type}] 元素,src: "${fileIdentifier}"`);
|
|
431
437
|
if (fileIdentifier.startsWith("http")) {
|
|
432
438
|
const ext = path2.extname(el.attrs.file || "") || defaultExtMap[type];
|
|
433
439
|
const currentMediaIndex = ++mediaIndex;
|
|
434
440
|
const fileName = `${newId}_${currentMediaIndex}_${session.channelId || "private"}_${session.userId}${ext}`;
|
|
441
|
+
if (config.debug) logger2.info(`[${type}] 是远程文件,文件名: "${fileName}"`);
|
|
435
442
|
mediaToSave.push({ sourceUrl: fileIdentifier, fileName });
|
|
436
443
|
fileIdentifier = fileName;
|
|
437
444
|
}
|
|
438
445
|
result.push({ type, file: fileIdentifier });
|
|
439
446
|
} else if (el.children) {
|
|
447
|
+
if (config.debug) logger2.info(`元素 <${el.type}> 无直接内容,递归其子元素...`);
|
|
440
448
|
result.push(...await transform(el.children));
|
|
441
449
|
}
|
|
442
450
|
}
|
|
@@ -997,7 +1005,10 @@ var Config = import_koishi3.Schema.intersect([
|
|
|
997
1005
|
region: import_koishi3.Schema.string().default("auto").description("区域 (Region)"),
|
|
998
1006
|
accessKeyId: import_koishi3.Schema.string().description("Access Key ID").role("secret"),
|
|
999
1007
|
secretAccessKey: import_koishi3.Schema.string().description("Secret Access Key").role("secret")
|
|
1000
|
-
}).description("存储配置")
|
|
1008
|
+
}).description("存储配置"),
|
|
1009
|
+
import_koishi3.Schema.object({
|
|
1010
|
+
debug: import_koishi3.Schema.boolean().default(false).description("启用调试模式,将在控制台输出详细的操作日志。")
|
|
1011
|
+
}).description("开发配置")
|
|
1001
1012
|
]);
|
|
1002
1013
|
function apply(ctx, config) {
|
|
1003
1014
|
ctx.model.extend("cave", {
|
|
@@ -1040,18 +1051,36 @@ function apply(ctx, config) {
|
|
|
1040
1051
|
});
|
|
1041
1052
|
cave.subcommand(".add [content:text]", "添加回声洞").usage("添加一条回声洞。可直接发送内容,也可回复或引用消息。").action(async ({ session }, content) => {
|
|
1042
1053
|
try {
|
|
1043
|
-
let sourceElements
|
|
1044
|
-
|
|
1054
|
+
let sourceElements;
|
|
1055
|
+
let sourceOrigin = "";
|
|
1056
|
+
if (session.quote?.elements) {
|
|
1057
|
+
sourceElements = session.quote.elements;
|
|
1058
|
+
sourceOrigin = "引用(quote)";
|
|
1059
|
+
} else if (content?.trim()) {
|
|
1045
1060
|
sourceElements = import_koishi3.h.parse(content);
|
|
1046
|
-
|
|
1047
|
-
|
|
1061
|
+
sourceOrigin = `指令参数(content)`;
|
|
1062
|
+
} else {
|
|
1048
1063
|
await session.send("请在一分钟内发送你要添加的内容");
|
|
1049
1064
|
const reply = await session.prompt(6e4);
|
|
1050
1065
|
if (!reply) return "等待操作超时";
|
|
1051
1066
|
sourceElements = import_koishi3.h.parse(reply);
|
|
1067
|
+
sourceOrigin = `用户回复(prompt)`;
|
|
1068
|
+
}
|
|
1069
|
+
if (config.debug) {
|
|
1070
|
+
logger.info(`内容来源: ${sourceOrigin}`);
|
|
1071
|
+
logger.info(`获取到的消息内容 (sourceElements):
|
|
1072
|
+
${JSON.stringify(sourceElements, null, 2)}`);
|
|
1073
|
+
logger.info(`完整的会话对象 (session):
|
|
1074
|
+
${JSON.stringify(session, null, 2)}`);
|
|
1052
1075
|
}
|
|
1053
1076
|
const newId = await getNextCaveId(ctx, getScopeQuery(session, config, false), reusableIds);
|
|
1054
|
-
const { finalElementsForDb, mediaToSave } = await processMessageElements(sourceElements, newId, session);
|
|
1077
|
+
const { finalElementsForDb, mediaToSave } = await processMessageElements(sourceElements, newId, session, config, logger);
|
|
1078
|
+
if (config.debug) {
|
|
1079
|
+
logger.info(`提取后数据库元素(finalElementsForDb):
|
|
1080
|
+
${JSON.stringify(finalElementsForDb, null, 2)}`);
|
|
1081
|
+
logger.info(`提取后待存媒体(mediaToSave):
|
|
1082
|
+
${JSON.stringify(mediaToSave, null, 2)}`);
|
|
1083
|
+
}
|
|
1055
1084
|
if (finalElementsForDb.length === 0) return "无可添加内容";
|
|
1056
1085
|
const textHashesToStore = [];
|
|
1057
1086
|
if (hashManager) {
|