koishi-plugin-maple-dice-v2 0.0.2 → 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 +198 -52
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -243,7 +243,7 @@ function apply(ctx, config) {
|
|
|
243
243
|
primary: "id",
|
|
244
244
|
autoInc: true
|
|
245
245
|
});
|
|
246
|
-
ctx.command("r [expression:string]", "基础掷骰(默认为1d100)").alias("roll").alias("掷骰").example("r
|
|
246
|
+
ctx.command("r [expression:string]", "基础掷骰(默认为1d100)").alias("roll").alias("掷骰").example("r 3d6 掷3个6面骰").example("r 2d20+5 掷2个20面骰并加5").action(async ({ session }, expression) => {
|
|
247
247
|
try {
|
|
248
248
|
const result = DiceRoller.parseDice(expression);
|
|
249
249
|
let output = `r ${result.expression} = `;
|
|
@@ -265,7 +265,7 @@ function apply(ctx, config) {
|
|
|
265
265
|
return `错误: ${error.message}`;
|
|
266
266
|
}
|
|
267
267
|
});
|
|
268
|
-
ctx.command("ra [skill:number]", "技能检定").alias("检定").action(async ({ session }, skill) => {
|
|
268
|
+
ctx.command("ra [skill:number]", "技能检定").alias("检定").example("ra 使用默认技能值进行检定").example("ra 80 使用80点技能值进行检定").action(async ({ session }, skill) => {
|
|
269
269
|
const skillValue = skill || config.defaultSkill;
|
|
270
270
|
if (skillValue < 1 || skillValue > 100) {
|
|
271
271
|
return "技能值必须在1-100之间";
|
|
@@ -326,7 +326,7 @@ ${response}`;
|
|
|
326
326
|
return `错误: ${error.message}`;
|
|
327
327
|
}
|
|
328
328
|
});
|
|
329
|
-
ctx.command("添加自定义回复 <level:string> <text:string>", "添加自定义回复(用&分隔多条回复)").alias("添加回复").example("添加自定义回复 大成功 太棒了!大成功!骰值:{result}
|
|
329
|
+
ctx.command("添加自定义回复 <level:string> <text:string>", "添加自定义回复(用&分隔多条回复)").alias("添加回复").example("添加自定义回复 大成功 太棒了!大成功!骰值:{result}").example("添加自定义回复 成功 成功!骰值:{result}&干得漂亮!骰值:{result}").action(async ({ session }, level, text) => {
|
|
330
330
|
const validLevels = ["大成功", "极难成功", "困难成功", "成功", "失败", "大失败"];
|
|
331
331
|
if (!validLevels.includes(level)) {
|
|
332
332
|
return `无效的成功等级。可用等级:${validLevels.join("、")}`;
|
|
@@ -350,29 +350,37 @@ ${response}`;
|
|
|
350
350
|
});
|
|
351
351
|
addedResponses.push(result);
|
|
352
352
|
}
|
|
353
|
-
return
|
|
353
|
+
return `成功为"${level}"添加了 ${replies.length} 条自定义回复(群组: ${groupId})
|
|
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,46 +418,103 @@ ${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
|
-
ctx.command("删除自定义回复 <id:number>", "
|
|
517
|
+
ctx.command("删除自定义回复 <id:number>", '删除自定义回复(ID可从"查看自定义回复 -m"中查看)').alias("删除回复").example("删除自定义回复 1 删除ID为1的回复").action(async ({ session }, id) => {
|
|
453
518
|
if (!session?.userId) {
|
|
454
519
|
return "无法获取用户信息,请确保在正确的环境下使用此指令";
|
|
455
520
|
}
|
|
@@ -460,15 +525,15 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
|
|
|
460
525
|
const response = existing[0];
|
|
461
526
|
if (response.author !== session.userId) {
|
|
462
527
|
return `无法删除此回复,您只能删除自己添加的回复。
|
|
463
|
-
|
|
528
|
+
输入"查看自定义回复 -m"查看由自己添加的回复`;
|
|
464
529
|
}
|
|
465
530
|
const contentToDelete = response.content;
|
|
466
531
|
const level = response.level;
|
|
467
532
|
await ctx.database.remove("maple-dice-responses", { id });
|
|
468
|
-
return
|
|
533
|
+
return `已删除"${level}"的回复(ID: ${id}):
|
|
469
534
|
${contentToDelete}`;
|
|
470
535
|
});
|
|
471
|
-
ctx.command("修改自定义回复 <id:number> <text:string>", "
|
|
536
|
+
ctx.command("修改自定义回复 <id:number> <text:string>", '修改自定义回复(ID可从"查看自定义回复 -m"中查看)').alias("修改回复").example("修改自定义回复 1 新的回复内容").action(async ({ session }, id, text) => {
|
|
472
537
|
if (!session?.userId) {
|
|
473
538
|
return "无法获取用户信息,请确保在正确的环境下使用此指令";
|
|
474
539
|
}
|
|
@@ -479,7 +544,7 @@ ${contentToDelete}`;
|
|
|
479
544
|
const response = existing[0];
|
|
480
545
|
if (response.author !== session.userId) {
|
|
481
546
|
return `无法修改此回复,您只能修改自己添加的回复。
|
|
482
|
-
|
|
547
|
+
输入"查看自定义回复 -m"查看由自己添加的回复`;
|
|
483
548
|
}
|
|
484
549
|
if (!text.trim()) {
|
|
485
550
|
return "新回复内容不能为空";
|
|
@@ -491,13 +556,94 @@ ${contentToDelete}`;
|
|
|
491
556
|
created: /* @__PURE__ */ new Date()
|
|
492
557
|
// 更新修改时间
|
|
493
558
|
});
|
|
494
|
-
return
|
|
559
|
+
return `已修改"${level}"的回复(ID: ${id}):
|
|
495
560
|
原内容: ${oldContent}
|
|
496
561
|
新内容: ${text.trim()}`;
|
|
497
562
|
});
|
|
498
|
-
ctx.command("清空自定义回复", "
|
|
499
|
-
const
|
|
500
|
-
|
|
563
|
+
ctx.command("清空自定义回复 [options]", "清空自定义回复").alias("清空回复").option("all", "-a 清空所有自定义回复(默认)").option("me", "-m 清空自己添加的自定义回复").option("user", "-u <userId:string> 清空指定用户添加的所有自定义回复").option("thisGroup", "-tg 清空当前群聊的自定义回复").option("group", "-g <groupId:string> 清空指定群内的所有自定义回复").action(async ({ session, options }) => {
|
|
564
|
+
const userId = session?.userId;
|
|
565
|
+
const groupId = session?.guildId || "私聊";
|
|
566
|
+
const authorOptions = [];
|
|
567
|
+
if (options?.all) authorOptions.push("-a");
|
|
568
|
+
if (options?.me) authorOptions.push("-m");
|
|
569
|
+
if (options?.user) authorOptions.push("-u");
|
|
570
|
+
if (authorOptions.length > 1) {
|
|
571
|
+
return `选项冲突:${authorOptions.join("、")}不能同时使用,请在[-a、-m、-u]中选择一个`;
|
|
572
|
+
}
|
|
573
|
+
const groupOptions = [];
|
|
574
|
+
if (options?.thisGroup) groupOptions.push("-tg");
|
|
575
|
+
if (options?.group) groupOptions.push("-g");
|
|
576
|
+
if (options?.thisGroup && options?.group) {
|
|
577
|
+
return "选项冲突:-tg和-g不能同时使用,请在[-a、-tg、-g]中选择一个";
|
|
578
|
+
}
|
|
579
|
+
let authorQuery = "all";
|
|
580
|
+
let authorValue = void 0;
|
|
581
|
+
if (options?.all) {
|
|
582
|
+
authorQuery = "all";
|
|
583
|
+
} else if (options?.me) {
|
|
584
|
+
if (!userId) {
|
|
585
|
+
return "无法获取用户信息,请确保在正确的环境下使用此指令";
|
|
586
|
+
}
|
|
587
|
+
authorQuery = "me";
|
|
588
|
+
authorValue = userId;
|
|
589
|
+
} else if (options?.user) {
|
|
590
|
+
authorQuery = "user";
|
|
591
|
+
authorValue = options.user;
|
|
592
|
+
}
|
|
593
|
+
let groupQuery = "all";
|
|
594
|
+
let groupValue = void 0;
|
|
595
|
+
if (options?.all) {
|
|
596
|
+
groupQuery = "all";
|
|
597
|
+
} else if (options?.thisGroup) {
|
|
598
|
+
groupQuery = "thisGroup";
|
|
599
|
+
groupValue = groupId;
|
|
600
|
+
} else if (options?.group) {
|
|
601
|
+
groupQuery = "group";
|
|
602
|
+
groupValue = options.group;
|
|
603
|
+
}
|
|
604
|
+
let query = {};
|
|
605
|
+
let description = "";
|
|
606
|
+
switch (authorQuery) {
|
|
607
|
+
case "all":
|
|
608
|
+
description += "所有用户";
|
|
609
|
+
break;
|
|
610
|
+
case "me":
|
|
611
|
+
query.author = authorValue;
|
|
612
|
+
description += "自己";
|
|
613
|
+
break;
|
|
614
|
+
case "user":
|
|
615
|
+
query.author = authorValue;
|
|
616
|
+
description += `用户 ${authorValue}`;
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
switch (groupQuery) {
|
|
620
|
+
case "all":
|
|
621
|
+
description += "的所有群组";
|
|
622
|
+
break;
|
|
623
|
+
case "thisGroup":
|
|
624
|
+
if (authorQuery === "all") {
|
|
625
|
+
description = `${groupId === "私聊" ? "私聊" : "当前群组"}`;
|
|
626
|
+
} else {
|
|
627
|
+
description += `在${groupId === "私聊" ? "私聊" : "当前群组"}内`;
|
|
628
|
+
}
|
|
629
|
+
query.group = groupValue;
|
|
630
|
+
break;
|
|
631
|
+
case "group":
|
|
632
|
+
if (authorQuery === "all") {
|
|
633
|
+
description = `群组 ${groupValue}`;
|
|
634
|
+
} else {
|
|
635
|
+
description += `在群组 ${groupValue} 内`;
|
|
636
|
+
}
|
|
637
|
+
query.group = groupValue;
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
const responses = await ctx.database.get("maple-dice-responses", query);
|
|
641
|
+
const count = responses.length;
|
|
642
|
+
if (count === 0) {
|
|
643
|
+
return `没有找到符合条件的自定义回复`;
|
|
644
|
+
}
|
|
645
|
+
await ctx.database.remove("maple-dice-responses", query);
|
|
646
|
+
return `已清空 ${count} 条${description}的自定义回复`;
|
|
501
647
|
});
|
|
502
648
|
ctx.on("ready", () => {
|
|
503
649
|
console.log("maple-dice-v2 插件已加载完成");
|