@azimiao/koishi-plugin-cafe-bot-exp 0.0.13 → 0.0.16

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 CHANGED
@@ -38,7 +38,7 @@ __export(src_exports, {
38
38
  module.exports = __toCommonJS(src_exports);
39
39
 
40
40
  // package.json
41
- var version = "0.0.13";
41
+ var version = "0.0.16";
42
42
 
43
43
  // src/draw/index.ts
44
44
  var draw_exports = {};
@@ -661,21 +661,44 @@ async function answerHandler(ctx, config, argv, answer) {
661
661
  await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵(导力网络异常波动)`);
662
662
  return;
663
663
  }
664
+ const userQuiz = await ctx.database.get("cafeQuiz", { userId: argv.session.userId });
665
+ let userQuizA = null;
666
+ if (userQuiz.length === 0) {
667
+ userQuizA = await ctx.database.create("cafeQuiz", {
668
+ userId: argv.session.userId,
669
+ right: 0,
670
+ wrong: 0
671
+ });
672
+ } else {
673
+ userQuizA = userQuiz[0];
674
+ }
664
675
  var qItem = quizDataSet[lastQuestion.question];
665
676
  logger2?.info(`${argv.session.userId} try answer quiz(id:${lastQuestion.question}): right answer:${lastQuestion.answer}, input answer:${selectNumber}`);
666
677
  if (qItem && lastQuestion.answer == selectNumber) {
667
678
  await argv.session?.send(`${At(argv)}回答正确😊${qItem.explain.length > 0 ? "," + qItem.explain : ""}`);
679
+ await ctx.database.set("cafeQuiz", userQuizA.id, {
680
+ right: userQuizA.right + 1
681
+ });
668
682
  return;
669
683
  } else {
670
684
  await argv.session?.send(`${At(argv)}回答错误😟${qItem.explain2.length > 0 ? "," + qItem.explain2 : ""}`);
685
+ await ctx.database.set("cafeQuiz", userQuizA.id, {
686
+ wrong: userQuizA.wrong + 1
687
+ });
671
688
  return;
672
689
  }
673
690
  }
674
691
  __name(answerHandler, "answerHandler");
675
692
  async function apply3(ctx, config) {
676
693
  logger2 = ctx.logger(name3);
694
+ ctx.model.extend("cafeQuiz", {
695
+ id: "unsigned",
696
+ userId: "string",
697
+ right: "integer",
698
+ wrong: "integer"
699
+ }, { primary: "id", autoInc: true });
677
700
  await downloadQuitDataIfNotExist(ctx, config, config.forceUpdateWhenLoad);
678
- ctx.command("轨迹答题/出题").action(async (argv, _) => {
701
+ ctx.command("轨迹答题/出题", "随机抽一道题目").action(async (argv, _) => {
679
702
  await downloadQuitDataIfNotExist(ctx, config, false);
680
703
  var lastQuestion = await ctx.cache.get("question", argv.session.userId);
681
704
  if (lastQuestion) {
@@ -683,6 +706,7 @@ async function apply3(ctx, config) {
683
706
  return;
684
707
  }
685
708
  var dailyNameKey = DailySeededName(argv.session.userId);
709
+ argv.session.user;
686
710
  if (quizDataIds == null || quizDataIds.length <= 0) {
687
711
  await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵(导力网络异常波动)`);
688
712
  return;
@@ -720,7 +744,7 @@ D. ${qOptions[3].s}`;
720
744
  return;
721
745
  });
722
746
  ctx.command("轨迹答题").usage("通过趣味答题看看你是不是合格的桂皮吧~");
723
- ctx.command("轨迹答题/回答 <answer:text>", `使用"回答+空格+选项"回答问题哦,如"回答 A"`).action(async (argv, answer) => {
747
+ ctx.command("轨迹答题/回答 <answer:text>", `使用"回答+空格+选项"回答问题,另外你也可以直接@我说出选项(ABCD)哦`).action(async (argv, answer) => {
724
748
  await answerHandler(ctx, config, argv, answer);
725
749
  return;
726
750
  });
@@ -740,9 +764,19 @@ D. ${qOptions[3].s}`;
740
764
  await answerHandler(ctx, config, argv, "D");
741
765
  return;
742
766
  });
743
- ctx.command("轨迹答题/答题分数", "查看答题总分数").action(async (argv, _) => {
744
- await argv.session?.send(`${At(argv)}正在开发中哦~`);
745
- return;
767
+ ctx.command("轨迹答题/答题分", "查看答题总分数").action(async (argv, _) => {
768
+ const userQuiz = await ctx.database.get("cafeQuiz", { userId: argv.session.userId });
769
+ if (userQuiz.length === 0) {
770
+ await argv.session?.send(`${At(argv)}你还没有答过题哦,快来答题吧~`);
771
+ return;
772
+ } else {
773
+ let userQuizA = userQuiz[0];
774
+ let total = userQuizA.right + userQuizA.wrong;
775
+ await argv.session?.send(`${At(argv)}答题总数: ${total}
776
+ 正确回答: ${userQuizA.right}
777
+ 正确率: ${Math.round(userQuizA.right * 1 / total * 100)}`);
778
+ return;
779
+ }
746
780
  });
747
781
  }
748
782
  __name(apply3, "apply");
@@ -757,7 +791,7 @@ var Config4 = import_koishi7.Schema.intersect([
757
791
 
758
792
  // src/index.ts
759
793
  var name4 = "cafe-bot-exp";
760
- var inject3 = ["http", "cache", "logger"];
794
+ var inject3 = ["http", "cache", "logger", "database"];
761
795
  async function apply4(ctx, config) {
762
796
  ctx.plugin(draw_exports, config);
763
797
  ctx.plugin(quiz_exports, config);
@@ -18,5 +18,16 @@ declare module '@koishijs/cache' {
18
18
  todayCache: number;
19
19
  }
20
20
  }
21
+ declare module 'koishi' {
22
+ interface Tables {
23
+ 'cafeQuiz': CafeQuiz;
24
+ }
25
+ }
26
+ export interface CafeQuiz {
27
+ id: number;
28
+ userId: string;
29
+ right: number;
30
+ wrong: number;
31
+ }
21
32
  export declare function apply(ctx: Context, config: Config): Promise<void>;
22
33
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@azimiao/koishi-plugin-cafe-bot-exp",
3
3
  "description": "cafe bot experiment",
4
- "version": "0.0.13",
4
+ "version": "0.0.16",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "repository": {