koishi-plugin-best-cave 1.5.2 → 1.5.3
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/index.js +23 -11
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -346,14 +346,20 @@ var IdManager = class {
|
|
|
346
346
|
throw new Error("IdManager not initialized");
|
|
347
347
|
}
|
|
348
348
|
let nextId;
|
|
349
|
-
if (this.deletedIds.size
|
|
350
|
-
|
|
349
|
+
if (this.deletedIds.size > 0) {
|
|
350
|
+
const minDeletedId = Math.min(...Array.from(this.deletedIds));
|
|
351
|
+
if (!isNaN(minDeletedId) && minDeletedId > 0) {
|
|
352
|
+
nextId = minDeletedId;
|
|
353
|
+
this.deletedIds.delete(nextId);
|
|
354
|
+
} else {
|
|
355
|
+
nextId = this.maxId + 1;
|
|
356
|
+
}
|
|
351
357
|
} else {
|
|
352
|
-
nextId =
|
|
353
|
-
this.deletedIds.delete(nextId);
|
|
358
|
+
nextId = this.maxId + 1;
|
|
354
359
|
}
|
|
355
|
-
while (this.usedIds.has(nextId)) {
|
|
356
|
-
nextId =
|
|
360
|
+
while (isNaN(nextId) || nextId <= 0 || this.usedIds.has(nextId)) {
|
|
361
|
+
nextId = this.maxId + 1;
|
|
362
|
+
this.maxId++;
|
|
357
363
|
}
|
|
358
364
|
this.usedIds.add(nextId);
|
|
359
365
|
this.saveStatus().catch(
|
|
@@ -1342,13 +1348,16 @@ async function apply(ctx, config) {
|
|
|
1342
1348
|
async function processAdd(ctx2, config2, caveFilePath, resourceDir, pendingFilePath, session, content) {
|
|
1343
1349
|
let caveId;
|
|
1344
1350
|
try {
|
|
1351
|
+
caveId = await idManager.getNextId();
|
|
1352
|
+
if (isNaN(caveId) || caveId <= 0) {
|
|
1353
|
+
throw new Error("Invalid ID generated");
|
|
1354
|
+
}
|
|
1345
1355
|
const inputContent = content.length > 0 ? content.join("\n") : await (async () => {
|
|
1346
1356
|
await sendMessage(session, "commands.cave.add.noContent", [], true, 6e4);
|
|
1347
1357
|
const reply = await session.prompt({ timeout: 6e4 });
|
|
1348
1358
|
if (!reply) sendMessage(session, "commands.cave.add.operationTimeout", [], true);
|
|
1349
1359
|
return reply;
|
|
1350
1360
|
})();
|
|
1351
|
-
caveId = await idManager.getNextId();
|
|
1352
1361
|
if (inputContent.includes("/app/.config/QQ/")) {
|
|
1353
1362
|
return sendMessage(session, "commands.cave.add.localFileNotAllowed", [], true);
|
|
1354
1363
|
}
|
|
@@ -1384,6 +1393,7 @@ async function apply(ctx, config) {
|
|
|
1384
1393
|
]);
|
|
1385
1394
|
const newCave = {
|
|
1386
1395
|
cave_id: caveId,
|
|
1396
|
+
// 确保使用有效的数字ID
|
|
1387
1397
|
elements: [
|
|
1388
1398
|
...textParts,
|
|
1389
1399
|
...imageElements.map((el, idx) => ({
|
|
@@ -1392,9 +1402,11 @@ async function apply(ctx, config) {
|
|
|
1392
1402
|
// 保持原始文本和图片的相对位置
|
|
1393
1403
|
index: el.index
|
|
1394
1404
|
}))
|
|
1395
|
-
].sort((a, b) => a.index -
|
|
1396
|
-
contributor_number: session.userId,
|
|
1397
|
-
|
|
1405
|
+
].sort((a, b) => a.index - b.index),
|
|
1406
|
+
contributor_number: session.userId || "100000",
|
|
1407
|
+
// 添加默认值
|
|
1408
|
+
contributor_name: session.username || "User"
|
|
1409
|
+
// 添加默认值
|
|
1398
1410
|
};
|
|
1399
1411
|
if (videoUrls.length > 0 && savedVideos.length > 0) {
|
|
1400
1412
|
newCave.elements.push({
|
|
@@ -1460,7 +1472,7 @@ async function apply(ctx, config) {
|
|
|
1460
1472
|
await idManager.addStat(session.userId, caveId);
|
|
1461
1473
|
return sendMessage(session, "commands.cave.add.addSuccess", [caveId], false);
|
|
1462
1474
|
} catch (error) {
|
|
1463
|
-
if (
|
|
1475
|
+
if (typeof caveId === "number" && !isNaN(caveId) && caveId > 0) {
|
|
1464
1476
|
await idManager.markDeleted(caveId);
|
|
1465
1477
|
}
|
|
1466
1478
|
if (error.message === "duplicate_found") {
|