koishi-plugin-maple-dice-v2 0.0.3 → 0.0.4
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 +104 -39
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -354,25 +354,33 @@ ${response}`;
|
|
|
354
354
|
新增内容:
|
|
355
355
|
${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")}`;
|
|
356
356
|
});
|
|
357
|
-
ctx.command("查看自定义回复 [
|
|
358
|
-
let mode =
|
|
357
|
+
ctx.command("查看自定义回复 [level] [page]", "查看自定义回复").alias("查看回复").option("me", "-m 查看由本人添加的所有自定义回复").option("group", "-g 查看当前群组内添加的所有自定义回复(私聊时,仅调用本人私聊添加的所有自定义回复)").option("all", "-a 查看所有自定义回复").example("查看自定义回复 -g 查看当前群组内的自定义回复(默认)").example("查看自定义回复 -m 2 查看本人添加的自定义回复,第2页").example("查看自定义回复 大成功 3 查看大成功等级的自定义回复,第3页").action(async ({ session, options }, level, page) => {
|
|
358
|
+
let mode = config.replyMode;
|
|
359
359
|
if (options?.all) {
|
|
360
|
-
mode = "
|
|
361
|
-
} else if (options?.
|
|
360
|
+
mode = "global";
|
|
361
|
+
} else if (options?.me) {
|
|
362
362
|
mode = "personal";
|
|
363
363
|
} else if (options?.group) {
|
|
364
364
|
mode = "group";
|
|
365
365
|
}
|
|
366
|
+
let actualLevel = level;
|
|
367
|
+
let actualPage = 1;
|
|
368
|
+
if (level && !isNaN(parseInt(level)) && level.match(/^\d+$/)) {
|
|
369
|
+
actualPage = parseInt(level);
|
|
370
|
+
actualLevel = void 0;
|
|
371
|
+
} else if (page && !isNaN(parseInt(page)) && page.match(/^\d+$/)) {
|
|
372
|
+
actualPage = parseInt(page);
|
|
373
|
+
}
|
|
366
374
|
const isPrivate = !session?.guildId;
|
|
367
375
|
const userId = session?.userId;
|
|
368
376
|
const groupId = isPrivate ? "私聊" : session?.guildId;
|
|
369
377
|
const query = {};
|
|
370
|
-
if (
|
|
378
|
+
if (actualLevel) {
|
|
371
379
|
const validLevels = ["大成功", "极难成功", "困难成功", "成功", "失败", "大失败"];
|
|
372
|
-
if (!validLevels.includes(
|
|
380
|
+
if (!validLevels.includes(actualLevel)) {
|
|
373
381
|
return `无效的成功等级。可用等级:${validLevels.join("、")}`;
|
|
374
382
|
}
|
|
375
|
-
query.level =
|
|
383
|
+
query.level = actualLevel;
|
|
376
384
|
}
|
|
377
385
|
switch (mode) {
|
|
378
386
|
case "personal":
|
|
@@ -387,18 +395,18 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
|
|
|
387
395
|
}
|
|
388
396
|
query.group = groupId;
|
|
389
397
|
break;
|
|
390
|
-
case "
|
|
398
|
+
case "global":
|
|
391
399
|
break;
|
|
392
400
|
}
|
|
393
401
|
const responses = await ctx.database.get("maple-dice-responses", query);
|
|
394
402
|
if (responses.length === 0) {
|
|
395
|
-
const
|
|
396
|
-
"
|
|
403
|
+
const modeText2 = {
|
|
404
|
+
"global": "所有",
|
|
397
405
|
"group": `当前${isPrivate ? "私聊" : "群组"}`,
|
|
398
406
|
"personal": "本人"
|
|
399
407
|
}[mode];
|
|
400
|
-
const
|
|
401
|
-
return `${
|
|
408
|
+
const levelText2 = actualLevel ? `【${actualLevel}】` : "";
|
|
409
|
+
return `${modeText2}${levelText2}暂无自定义回复,请使用"添加自定义回复"指令添加`;
|
|
402
410
|
}
|
|
403
411
|
const grouped = {};
|
|
404
412
|
for (const response of responses) {
|
|
@@ -410,44 +418,101 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
|
|
|
410
418
|
for (const levelName in grouped) {
|
|
411
419
|
grouped[levelName].sort((a, b) => a.id - b.id);
|
|
412
420
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const isOwner = userId && r.author === userId;
|
|
424
|
-
return `${index + 1}. [ID:${r.id}] ${r.content} ${isOwner ? "(可修改)" : ""}`;
|
|
425
|
-
}).join("\n");
|
|
426
|
-
return output;
|
|
421
|
+
const pageSize = 10;
|
|
422
|
+
const currentPage = actualPage;
|
|
423
|
+
let allResponsesFlat = [];
|
|
424
|
+
if (actualLevel) {
|
|
425
|
+
const levelResponses = grouped[actualLevel] || [];
|
|
426
|
+
allResponsesFlat = levelResponses.map((r, index) => ({
|
|
427
|
+
level: actualLevel,
|
|
428
|
+
response: r,
|
|
429
|
+
indexInLevel: index + 1
|
|
430
|
+
}));
|
|
427
431
|
} else {
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
432
|
+
const levelNames = ["大成功", "极难成功", "困难成功", "成功", "失败", "大失败"];
|
|
433
|
+
for (const levelName of levelNames) {
|
|
434
|
+
const levelResponses = grouped[levelName] || [];
|
|
435
|
+
levelResponses.forEach((r, index) => {
|
|
436
|
+
allResponsesFlat.push({
|
|
437
|
+
level: levelName,
|
|
438
|
+
response: r,
|
|
439
|
+
indexInLevel: index + 1
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
const totalResponses = allResponsesFlat.length;
|
|
445
|
+
const totalPages = Math.ceil(totalResponses / pageSize);
|
|
446
|
+
if (currentPage < 1 || currentPage > totalPages) {
|
|
447
|
+
return `页码无效,请使用1-${totalPages}之间的页码`;
|
|
448
|
+
}
|
|
449
|
+
const startIndex = (currentPage - 1) * pageSize;
|
|
450
|
+
const endIndex = Math.min(startIndex + pageSize, totalResponses);
|
|
451
|
+
const currentPageResponses = allResponsesFlat.slice(startIndex, endIndex);
|
|
452
|
+
const modeText = {
|
|
453
|
+
"global": "所有",
|
|
454
|
+
"group": `当前${isPrivate ? "私聊" : "群组"}`,
|
|
455
|
+
"personal": "本人"
|
|
456
|
+
}[mode];
|
|
457
|
+
const levelText = actualLevel ? `【${actualLevel}】` : "";
|
|
458
|
+
const paginationText = totalPages > 1 ? `(第${currentPage}/${totalPages}页)` : "";
|
|
459
|
+
const currentPageCount = currentPageResponses.length;
|
|
460
|
+
let output = `${modeText}${levelText}自定义回复${paginationText}(共${totalResponses}条,本页${currentPageCount}条):
|
|
434
461
|
|
|
435
462
|
`;
|
|
463
|
+
const groupedCurrentPage = {};
|
|
464
|
+
for (const item of currentPageResponses) {
|
|
465
|
+
if (!groupedCurrentPage[item.level]) {
|
|
466
|
+
groupedCurrentPage[item.level] = [];
|
|
467
|
+
}
|
|
468
|
+
groupedCurrentPage[item.level].push(item);
|
|
469
|
+
}
|
|
470
|
+
if (actualLevel) {
|
|
471
|
+
const items = groupedCurrentPage[actualLevel] || [];
|
|
472
|
+
if (items.length === 0) {
|
|
473
|
+
return `第${currentPage}页没有【${actualLevel}】的自定义回复`;
|
|
474
|
+
}
|
|
475
|
+
output += `【${actualLevel}】(本页${items.length}条):
|
|
476
|
+
`;
|
|
477
|
+
output += items.map((item, index) => {
|
|
478
|
+
const isOwner = userId && item.response.author === userId;
|
|
479
|
+
return `${item.indexInLevel}. [ID:${item.response.id}] ${item.response.content} ${isOwner ? "(可修改)" : ""}`;
|
|
480
|
+
}).join("\n");
|
|
481
|
+
} else {
|
|
436
482
|
const levelNames = ["大成功", "极难成功", "困难成功", "成功", "失败", "大失败"];
|
|
483
|
+
let hasContent = false;
|
|
437
484
|
for (const levelName of levelNames) {
|
|
438
|
-
const
|
|
439
|
-
if (
|
|
440
|
-
|
|
485
|
+
const items = groupedCurrentPage[levelName] || [];
|
|
486
|
+
if (items.length > 0) {
|
|
487
|
+
hasContent = true;
|
|
488
|
+
output += `【${levelName}】(本页${items.length}条):
|
|
441
489
|
`;
|
|
442
|
-
output +=
|
|
443
|
-
const isOwner = userId &&
|
|
444
|
-
return `${
|
|
490
|
+
output += items.map((item, index) => {
|
|
491
|
+
const isOwner = userId && item.response.author === userId;
|
|
492
|
+
return `${item.indexInLevel}. [ID:${item.response.id}] ${item.response.content} ${isOwner ? "(可修改)" : ""}`;
|
|
445
493
|
}).join("\n");
|
|
446
494
|
output += "\n\n";
|
|
447
495
|
}
|
|
448
496
|
}
|
|
449
|
-
|
|
497
|
+
if (!hasContent) {
|
|
498
|
+
return `第${currentPage}页没有自定义回复`;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (totalPages > 1) {
|
|
502
|
+
output += `
|
|
503
|
+
──────────────
|
|
504
|
+
`;
|
|
505
|
+
const optionsPrefix = options?.me ? " -m" : options?.group ? " -g" : options?.all ? " -a" : "";
|
|
506
|
+
const levelPrefix = actualLevel ? ` ${actualLevel}` : "";
|
|
507
|
+
if (currentPage > 1) {
|
|
508
|
+
output += `输入"查看自定义回复${levelPrefix}${optionsPrefix} ${currentPage - 1}"查看上一页
|
|
509
|
+
`;
|
|
510
|
+
}
|
|
511
|
+
if (currentPage < totalPages) {
|
|
512
|
+
output += `输入"查看自定义回复${levelPrefix}${optionsPrefix} ${currentPage + 1}"查看下一页`;
|
|
513
|
+
}
|
|
450
514
|
}
|
|
515
|
+
return output.trim();
|
|
451
516
|
});
|
|
452
517
|
ctx.command("删除自定义回复 <id:number>", '删除自定义回复(ID可从"查看自定义回复 -m"中查看)').alias("删除回复").example("删除自定义回复 1 删除ID为1的回复").action(async ({ session }, id) => {
|
|
453
518
|
if (!session?.userId) {
|