koishi-plugin-smmcat-eazyfeedback 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.
Files changed (2) hide show
  1. package/lib/index.js +75 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -329,6 +329,55 @@ function apply(ctx, config) {
329
329
  await ctx.database.create("smm_eazy_feedback_log", temp);
330
330
  await Chat.send(session, `<@${userId}> 反馈成功!`);
331
331
  },
332
+ /** 发起统计报告 */
333
+ async statisticalReport(mid, fn) {
334
+ const data = await ctx.database.get("smm_eazy_feedback_log", { mid });
335
+ if (!data.length) {
336
+ fn && await fn({ err: "该 问卷调查/反馈 暂无任何回复..." });
337
+ return null;
338
+ }
339
+ const [title] = await ctx.database.get("smmcat_eazy_feedback_title", { mid });
340
+ if (!title) {
341
+ fn && await fn({ err: "未找到 mid 下的 问卷调查/反馈 模板信息..." });
342
+ return null;
343
+ }
344
+ const total = {};
345
+ const defaultRepaly = title.replyList;
346
+ for (const item of data) {
347
+ const message = item.message?.trim() || "";
348
+ if (message && defaultRepaly.includes(message)) {
349
+ if (total[message] == void 0) {
350
+ total[message] = 0;
351
+ }
352
+ total[message]++;
353
+ } else {
354
+ if (total["其他回复"] == void 0) {
355
+ total["其他回复"] = 0;
356
+ }
357
+ total["其他回复"]++;
358
+ }
359
+ }
360
+ return { title: title.title, mid: title.mid, total };
361
+ },
362
+ /** 格式化统计报告 */
363
+ formatMsgReport(detail) {
364
+ const { total: data, mid, title } = detail;
365
+ const option = Object.keys(data);
366
+ const total = Object.values(data).reduce((a, b) => a + b, 0);
367
+ return `
368
+ **问卷反馈统计 ${mid} 的结果**
369
+
370
+ \`\`\` 问卷内容
371
+ ${utils.cleanMdSimple(title)}
372
+ \`\`\`
373
+
374
+ **反馈的信息(一共 ${total} 条记录)**
375
+
376
+ ${option.map((item) => {
377
+ return `【${item}】:${(data[item] / total * 100).toFixed(2)}%`;
378
+ }).join("\n")}
379
+ `;
380
+ },
332
381
  /** 对比差异 */
333
382
  async difference() {
334
383
  if (!config.title?.trim()) return;
@@ -429,6 +478,11 @@ ${data.title}
429
478
  }
430
479
  };
431
480
  const utils = {
481
+ /** 清除md特殊符号 */
482
+ cleanMdSimple(str) {
483
+ if (!str) return "";
484
+ return str.replace(/<br\s*\/?>/gi, "").replace(/[*_`#>\-]/g, "").trim();
485
+ },
432
486
  /** 获取图片缩小后的尺寸 */
433
487
  async getImageReduceSize(url, size = config.picAutoWidth) {
434
488
  const useImg = await ctx.canvas.loadImage(url);
@@ -469,11 +523,12 @@ ${data.title}
469
523
  `, "|mid|问题|参与人数|操作|\n|:-:|:--|:-:|:-:|"];
470
524
  for (const item of data) {
471
525
  const feedbackData = await ctx.database.get("smm_eazy_feedback_log", { mid: item.mid });
472
- msg.push(`|${item.mid}|${item.title.length > 10 ? item.title.slice(0, 10) + "..." : item.title + ""}|${feedbackData.length}|<qqbot-cmd-input text="/查询回复 ${item.mid}" show="查询回复" reference="false"/>`);
526
+ msg.push(`|${item.mid}|${item.title.length > 10 ? utils.cleanMdSimple(item.title.slice(0, 10)) + "..." : utils.cleanMdSimple(item.title) + ""}|${feedbackData.length}|<qqbot-cmd-input text="/查询回复 ${item.mid}" show="查询回复" reference="false"/><qqbot-cmd-input text="/问卷统计 ${item.mid}" show="统计" reference="false"/>`);
473
527
  }
474
528
  msg.push(
475
529
  `
476
- 操作选项:<qqbot-cmd-input text="上一页" show="【上一页】" reference="false"/> <qqbot-cmd-input text="下一页" show="【下一页】" reference="false"/> <qqbot-cmd-input text="退出" show="【退出】" reference="false"/>`
530
+ 操作选项 (60s 有效):
531
+ <qqbot-cmd-input text="上一页" show="【上一页】" reference="false"/> <qqbot-cmd-input text="下一页" show="【下一页】" reference="false"/> <qqbot-cmd-input text="退出" show="【退出】" reference="false"/>`
477
532
  );
478
533
  Chat.send(session, msg.join("\n"));
479
534
  let type = await session.prompt(6e4);
@@ -498,12 +553,25 @@ ${data.title}
498
553
  }
499
554
  continue;
500
555
  }
501
- if (type.includes("查询回复")) {
556
+ if (type.includes("查询回复") || type.includes("问卷统计")) {
502
557
  session.execute(type.replace("/", ""));
503
558
  break;
504
559
  }
560
+ break;
505
561
  }
506
562
  });
563
+ ctx.command("问卷反馈/当前问卷").action(async ({ session }) => {
564
+ await eazyFeedback.sendMdFormatMsg(session, config.mid);
565
+ });
566
+ ctx.command("问卷反馈/问卷统计 <mid:posint>").action(async ({ session }, mid) => {
567
+ if (!config.masterList.includes(session.userId)) return `权限不足!`;
568
+ const data = await eazyFeedback.statisticalReport(mid, async (e) => {
569
+ await Chat.send(session, e.err);
570
+ });
571
+ if (!data) return;
572
+ const msg = eazyFeedback.formatMsgReport(data);
573
+ await Chat.send(session, `<@${session.userId}> ` + msg);
574
+ });
507
575
  ctx.command("问卷反馈/查询回复 <mid:posint>").action(async ({ session }, mid) => {
508
576
  if (!config.masterList.includes(session.userId)) return `权限不足!`;
509
577
  const _data = (await ctx.database.get("smm_eazy_feedback_log", { mid })).reverse();
@@ -519,7 +587,7 @@ ${data.title}
519
587
  `,
520
588
  `
521
589
  \`\`\` 问卷标题
522
- ${data[0].title}
590
+ ${utils.cleanMdSimple(data[0].title)}
523
591
  \`\`\`
524
592
 
525
593
  回复内容
@@ -533,7 +601,8 @@ ${data[0].title}
533
601
  }
534
602
  msg.push(
535
603
  `
536
- 操作选项:<qqbot-cmd-input text="上一页" show="【上一页】" reference="false"/> <qqbot-cmd-input text="下一页" show="【下一页】" reference="false"/> <qqbot-cmd-input text="退出" show="【退出】" reference="false"/>`
604
+ 操作选项 (60s 有效):
605
+ <qqbot-cmd-input text="上一页" show="【上一页】" reference="false"/> <qqbot-cmd-input text="下一页" show="【下一页】" reference="false"/> <qqbot-cmd-input text="退出" show="【退出】" reference="false"/>`
537
606
  );
538
607
  Chat.send(session, msg.join("\n"));
539
608
  let type = await session.prompt(6e4);
@@ -558,6 +627,7 @@ ${data[0].title}
558
627
  }
559
628
  continue;
560
629
  }
630
+ break;
561
631
  }
562
632
  });
563
633
  ctx.on("ready", () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-eazyfeedback",
3
3
  "description": "更容易让用户反馈的反馈功能",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [