koishi-plugin-maple-dice-v2 0.0.2 → 0.0.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.
Files changed (2) hide show
  1. package/lib/index.js +99 -18
  2. 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 掷1个100面骰(默认)").example("r d6 掷1个6面骰").example("r 3d6 掷3个6面骰").example("r 2d20+5 掷2个20面骰并加5").example("r 3d10-2 掷3个10面骰并减2").example("r 2d6*3 掷2个6面骰并乘以3").example("r 4d10/2 掷4个10面骰并除以2").action(async ({ session }, expression) => {
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}&奇迹般的大成功!骰值:{result}").action(async ({ session }, level, text) => {
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,11 +350,11 @@ ${response}`;
350
350
  });
351
351
  addedResponses.push(result);
352
352
  }
353
- return `成功为【${level}】添加了 ${replies.length} 条自定义回复(群组: ${groupId})
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("查看自定义回复 [options]", "查看自定义回复").alias("查看回复").option("mode", "-m 查看由本人添加的所有自定义回复").option("group", "-g 查看当前群组内添加的所有自定义回复(私聊时,仅调用本人私聊添加的所有自定义回复)").option("all", "-a 查看所有自定义回复").example("查看自定义回复 -g 查看当前群组内的自定义回复(默认)").example("查看自定义回复 -m 查看由本人添加的自定义回复").example("查看自定义回复 -a 查看所有自定义回复").action(async ({ session, options }, level) => {
357
+ ctx.command("查看自定义回复 [options]", "查看自定义回复").alias("查看回复").option("mode", "-m 查看由本人添加的所有自定义回复").option("group", "-g 查看当前群组内添加的所有自定义回复(私聊时,仅调用本人私聊添加的所有自定义回复)").option("all", "-a 查看所有自定义回复").example("查看自定义回复 -g 查看当前群组内的自定义回复(默认)").example("查看自定义回复 -m 查看由本人添加的自定义回复").action(async ({ session, options }, level) => {
358
358
  let mode = "group";
359
359
  if (options?.all) {
360
360
  mode = "all";
@@ -397,8 +397,8 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
397
397
  "group": `当前${isPrivate ? "私聊" : "群组"}`,
398
398
  "personal": "本人"
399
399
  }[mode];
400
- const levelText = level ? `【${level}】` : "";
401
- return `${modeText}${levelText}暂无自定义回复,请使用【添加自定义回复】指令添加`;
400
+ const levelText = level ? `"${level}"` : "";
401
+ return `${modeText}${levelText}暂无自定义回复,请使用"添加自定义回复"指令添加`;
402
402
  }
403
403
  const grouped = {};
404
404
  for (const response of responses) {
@@ -417,7 +417,7 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
417
417
  "group": `当前${isPrivate ? "私聊" : "群组"}`,
418
418
  "personal": "本人"
419
419
  }[mode];
420
- let output = `${modeText}【${level}】(${levelResponses.length}条):
420
+ let output = `${modeText}"${level}"(${levelResponses.length}条):
421
421
  `;
422
422
  output += levelResponses.map((r, index) => {
423
423
  const isOwner = userId && r.author === userId;
@@ -437,7 +437,7 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
437
437
  for (const levelName of levelNames) {
438
438
  const levelResponses = grouped[levelName] || [];
439
439
  if (levelResponses.length > 0) {
440
- output += `【${levelName}】(${levelResponses.length}条):
440
+ output += `"${levelName}"(${levelResponses.length}条):
441
441
  `;
442
442
  output += levelResponses.map((r, index) => {
443
443
  const isOwner = userId && r.author === userId;
@@ -449,7 +449,7 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
449
449
  return output.trim();
450
450
  }
451
451
  });
452
- ctx.command("删除自定义回复 <id:number>", "删除自定义回复").alias("删除回复").example("删除自定义回复 1 删除ID为1的回复").action(async ({ session }, id) => {
452
+ ctx.command("删除自定义回复 <id:number>", '删除自定义回复(ID可从"查看自定义回复 -m"中查看)').alias("删除回复").example("删除自定义回复 1 删除ID为1的回复").action(async ({ session }, id) => {
453
453
  if (!session?.userId) {
454
454
  return "无法获取用户信息,请确保在正确的环境下使用此指令";
455
455
  }
@@ -460,15 +460,15 @@ ${addedResponses.map((r, i) => `${i + 1}. [ID:${r.id}] ${r.content}`).join("\n")
460
460
  const response = existing[0];
461
461
  if (response.author !== session.userId) {
462
462
  return `无法删除此回复,您只能删除自己添加的回复。
463
- 输入【查看自定义回复 -m】查看由自己添加的回复`;
463
+ 输入"查看自定义回复 -m"查看由自己添加的回复`;
464
464
  }
465
465
  const contentToDelete = response.content;
466
466
  const level = response.level;
467
467
  await ctx.database.remove("maple-dice-responses", { id });
468
- return `已删除【${level}】的回复(ID: ${id}):
468
+ return `已删除"${level}"的回复(ID: ${id}):
469
469
  ${contentToDelete}`;
470
470
  });
471
- ctx.command("修改自定义回复 <id:number> <text:string>", "修改自定义回复").alias("修改回复").example("修改自定义回复 1 新的回复内容").action(async ({ session }, id, text) => {
471
+ ctx.command("修改自定义回复 <id:number> <text:string>", '修改自定义回复(ID可从"查看自定义回复 -m"中查看)').alias("修改回复").example("修改自定义回复 1 新的回复内容").action(async ({ session }, id, text) => {
472
472
  if (!session?.userId) {
473
473
  return "无法获取用户信息,请确保在正确的环境下使用此指令";
474
474
  }
@@ -479,7 +479,7 @@ ${contentToDelete}`;
479
479
  const response = existing[0];
480
480
  if (response.author !== session.userId) {
481
481
  return `无法修改此回复,您只能修改自己添加的回复。
482
- 输入【查看自定义回复 -m】查看由自己添加的回复`;
482
+ 输入"查看自定义回复 -m"查看由自己添加的回复`;
483
483
  }
484
484
  if (!text.trim()) {
485
485
  return "新回复内容不能为空";
@@ -491,13 +491,94 @@ ${contentToDelete}`;
491
491
  created: /* @__PURE__ */ new Date()
492
492
  // 更新修改时间
493
493
  });
494
- return `已修改【${level}】的回复(ID: ${id}):
494
+ return `已修改"${level}"的回复(ID: ${id}):
495
495
  原内容: ${oldContent}
496
496
  新内容: ${text.trim()}`;
497
497
  });
498
- ctx.command("清空自定义回复", "清空所有自定义回复").alias("清空回复").action(async () => {
499
- const count = await ctx.database.remove("maple-dice-responses", {});
500
- return `已清空所有 ${count} 条自定义回复`;
498
+ 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 }) => {
499
+ const userId = session?.userId;
500
+ const groupId = session?.guildId || "私聊";
501
+ const authorOptions = [];
502
+ if (options?.all) authorOptions.push("-a");
503
+ if (options?.me) authorOptions.push("-m");
504
+ if (options?.user) authorOptions.push("-u");
505
+ if (authorOptions.length > 1) {
506
+ return `选项冲突:${authorOptions.join("、")}不能同时使用,请在[-a、-m、-u]中选择一个`;
507
+ }
508
+ const groupOptions = [];
509
+ if (options?.thisGroup) groupOptions.push("-tg");
510
+ if (options?.group) groupOptions.push("-g");
511
+ if (options?.thisGroup && options?.group) {
512
+ return "选项冲突:-tg和-g不能同时使用,请在[-a、-tg、-g]中选择一个";
513
+ }
514
+ let authorQuery = "all";
515
+ let authorValue = void 0;
516
+ if (options?.all) {
517
+ authorQuery = "all";
518
+ } else if (options?.me) {
519
+ if (!userId) {
520
+ return "无法获取用户信息,请确保在正确的环境下使用此指令";
521
+ }
522
+ authorQuery = "me";
523
+ authorValue = userId;
524
+ } else if (options?.user) {
525
+ authorQuery = "user";
526
+ authorValue = options.user;
527
+ }
528
+ let groupQuery = "all";
529
+ let groupValue = void 0;
530
+ if (options?.all) {
531
+ groupQuery = "all";
532
+ } else if (options?.thisGroup) {
533
+ groupQuery = "thisGroup";
534
+ groupValue = groupId;
535
+ } else if (options?.group) {
536
+ groupQuery = "group";
537
+ groupValue = options.group;
538
+ }
539
+ let query = {};
540
+ let description = "";
541
+ switch (authorQuery) {
542
+ case "all":
543
+ description += "所有用户";
544
+ break;
545
+ case "me":
546
+ query.author = authorValue;
547
+ description += "自己";
548
+ break;
549
+ case "user":
550
+ query.author = authorValue;
551
+ description += `用户 ${authorValue}`;
552
+ break;
553
+ }
554
+ switch (groupQuery) {
555
+ case "all":
556
+ description += "的所有群组";
557
+ break;
558
+ case "thisGroup":
559
+ if (authorQuery === "all") {
560
+ description = `${groupId === "私聊" ? "私聊" : "当前群组"}`;
561
+ } else {
562
+ description += `在${groupId === "私聊" ? "私聊" : "当前群组"}内`;
563
+ }
564
+ query.group = groupValue;
565
+ break;
566
+ case "group":
567
+ if (authorQuery === "all") {
568
+ description = `群组 ${groupValue}`;
569
+ } else {
570
+ description += `在群组 ${groupValue} 内`;
571
+ }
572
+ query.group = groupValue;
573
+ break;
574
+ }
575
+ const responses = await ctx.database.get("maple-dice-responses", query);
576
+ const count = responses.length;
577
+ if (count === 0) {
578
+ return `没有找到符合条件的自定义回复`;
579
+ }
580
+ await ctx.database.remove("maple-dice-responses", query);
581
+ return `已清空 ${count} 条${description}的自定义回复`;
501
582
  });
502
583
  ctx.on("ready", () => {
503
584
  console.log("maple-dice-v2 插件已加载完成");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-maple-dice-v2",
3
3
  "description": "-",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [