@azimiao/koishi-plugin-cafe-bot-exp 0.0.10 → 0.0.11

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.
@@ -0,0 +1,4 @@
1
+ declare const CafeTimeTools: {
2
+ getRemainingSecondsToBeijingMidnight: () => number;
3
+ };
4
+ export default CafeTimeTools;
package/lib/index.js CHANGED
@@ -89,12 +89,12 @@ var PseudoRandom = class {
89
89
  "seed": this.seed
90
90
  });
91
91
  }
92
- next = /* @__PURE__ */ __name(() => {
92
+ next = () => {
93
93
  return this.randFunc();
94
- }, "next");
95
- nextInt = /* @__PURE__ */ __name((min, max) => {
94
+ };
95
+ nextInt = (min, max) => {
96
96
  return Math.floor(this.next() * (max - min + 1)) + min;
97
- }, "nextInt");
97
+ };
98
98
  };
99
99
  var PseudoRandom_default = PseudoRandom;
100
100
 
@@ -572,6 +572,23 @@ var CafeBotQuizConfig = import_koishi5.Schema.object({
572
572
  redisAuth: import_koishi5.Schema.string().description("redis服务器密码")
573
573
  }).description("答题配置");
574
574
 
575
+ // src/common/CafeTimeTools.ts
576
+ var CafeTimeTools = {
577
+ getRemainingSecondsToBeijingMidnight: function() {
578
+ const now = /* @__PURE__ */ new Date();
579
+ const utcNow = now.getTime();
580
+ const target = new Date(now);
581
+ target.setUTCHours(16, 0, 0, 0);
582
+ if (utcNow >= target.getTime()) {
583
+ target.setUTCDate(target.getUTCDate() + 1);
584
+ }
585
+ const diff = target.getTime() - utcNow;
586
+ const seconds = Math.ceil(diff / 1e3);
587
+ return seconds;
588
+ }
589
+ };
590
+ var CafeTimeTools_default = CafeTimeTools;
591
+
575
592
  // src/quiz/index.ts
576
593
  var name3 = "cafe-bot-exp.quiz";
577
594
  var inject2 = ["http", "cache"];
@@ -614,6 +631,36 @@ async function downloadQuitDataIfNotExist(ctx, config, forceUpdate) {
614
631
  return;
615
632
  }
616
633
  __name(downloadQuitDataIfNotExist, "downloadQuitDataIfNotExist");
634
+ async function answerHandler(ctx, config, argv, answer) {
635
+ await downloadQuitDataIfNotExist(ctx, config, false);
636
+ var lastQuestion = await ctx.cache.get("question", argv.session.userId);
637
+ if (!lastQuestion) {
638
+ await argv.session?.send("你还未开始答题或已超时哦~");
639
+ return;
640
+ }
641
+ let selectNumber = -1;
642
+ if (answer in validOptions) {
643
+ selectNumber = validOptions[answer];
644
+ } else {
645
+ await argv.session?.send(`${At(argv)}选项无效,请重新输入~`);
646
+ return;
647
+ }
648
+ await ctx.cache.delete("question", argv.session.userId);
649
+ if (quizDataIds == null || quizDataIds.length <= 0) {
650
+ await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵`);
651
+ return;
652
+ }
653
+ var qItem = quizDataSet[lastQuestion.question];
654
+ console.log(`${argv.session.userId} try answer quiz(id:${lastQuestion.question}), input answer:${selectNumber}`);
655
+ if (qItem && lastQuestion.answer == selectNumber) {
656
+ await argv.session?.send(`${At(argv)}回答正确😊${qItem.explain.length > 0 ? "," + qItem.explain : ""}`);
657
+ return;
658
+ } else {
659
+ await argv.session?.send(`${At(argv)}回答错误😟${qItem.explain2.length > 0 ? "," + qItem.explain2 : ""}`);
660
+ return;
661
+ }
662
+ }
663
+ __name(answerHandler, "answerHandler");
617
664
  async function apply3(ctx, config) {
618
665
  await downloadQuitDataIfNotExist(ctx, config, config.forceUpdateWhenLoad);
619
666
  ctx.command("轨迹答题/出题").action(async (argv, _) => {
@@ -623,14 +670,27 @@ async function apply3(ctx, config) {
623
670
  await argv.session?.send("上一题还没有回答哦~");
624
671
  return;
625
672
  }
673
+ var dailyNameKey = DailySeededName(argv.session.userId);
626
674
  if (quizDataIds == null || quizDataIds.length <= 0) {
627
- await argv.session?.send(`${At(argv)}题目数据获取失败~`);
675
+ await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵`);
628
676
  return;
629
677
  }
678
+ var todayCount = await ctx.cache.get("todayCache", dailyNameKey);
679
+ if (!todayCount) {
680
+ todayCount = 0;
681
+ }
682
+ if (todayCount >= config.maxQuizPerDay) {
683
+ await argv.session?.send(`${At(argv)}今日答题已到上限哦~明天再来看看吧❤`);
684
+ return;
685
+ }
686
+ todayCount++;
687
+ var cacheTimeoutTime = CafeTimeTools_default.getRemainingSecondsToBeijingMidnight();
688
+ await ctx.cache.set("todayCache", dailyNameKey, todayCount, cacheTimeoutTime * 1e3);
630
689
  var randomId = import_koishi6.Random.pick(quizDataIds);
631
690
  var qItem = quizDataSet[randomId];
632
691
  var qOptions = import_koishi6.Random.shuffle(qItem.options);
633
692
  var answerIndex = -1;
693
+ console.log(`${argv.session.userId} get a new quiz(id:${randomId})`);
634
694
  for (var i = 0; i < qOptions.length; i++) {
635
695
  if (qOptions[i].oid === qItem.a) {
636
696
  answerIndex = i;
@@ -639,40 +699,32 @@ async function apply3(ctx, config) {
639
699
  }
640
700
  await ctx.cache.set("question", argv.session.userId, { question: randomId, answer: answerIndex }, config.answerTimeout * 1e3);
641
701
  var messageQuestion = `${qItem.question.img.length > 0 ? `<img src="${qItem.question.img}"/>` : ``}${At(argv)}${qItem.question.s}
642
- A.${qOptions[0].s}
643
- B.${qOptions[1].s}
644
- C.${qOptions[2].s}
645
- D.${qOptions[3].s}`;
702
+ A. ${qOptions[0].s}
703
+ B. ${qOptions[1].s}
704
+ C. ${qOptions[2].s}
705
+ D. ${qOptions[3].s}`;
646
706
  await argv.session?.send(messageQuestion);
647
707
  return;
648
708
  });
649
709
  ctx.command("轨迹答题/回答 <answer:text>", `回复"回答+空格+选项"回答问题哦,如"回答 A"`).action(async (argv, answer) => {
650
- await downloadQuitDataIfNotExist(ctx, config, false);
651
- var lastQuestion = await ctx.cache.get("question", argv.session.userId);
652
- if (!lastQuestion) {
653
- await argv.session?.send("你还未开始答题或已超时哦~");
654
- return;
655
- }
656
- let selectNumber = -1;
657
- if (answer in validOptions) {
658
- selectNumber = validOptions[answer];
659
- } else {
660
- await argv.session?.send(`${At(argv)}选项无效,请重新输入~`);
661
- return;
662
- }
663
- await ctx.cache.delete("question", argv.session.userId);
664
- if (quizDataIds == null || quizDataIds.length <= 0) {
665
- await argv.session?.send(`${At(argv)}题目数据获取失败,请重新开始答题~`);
666
- return;
667
- }
668
- var qItem = quizDataSet[lastQuestion.question];
669
- if (qItem && lastQuestion.answer == selectNumber) {
670
- await argv.session?.send(`${At(argv)}回答正确😊${qItem.explain.length > 0 ? "," + qItem.explain : ""}`);
671
- return;
672
- } else {
673
- await argv.session?.send(`${At(argv)}回答错误😟${qItem.explain2.length > 0 ? "," + qItem.explain2 : ""}`);
674
- return;
675
- }
710
+ await answerHandler(ctx, config, argv, answer);
711
+ return;
712
+ });
713
+ ctx.command("轨迹答题/A", "选择 A 选项").action(async (argv, _) => {
714
+ await answerHandler(ctx, config, argv, "A");
715
+ return;
716
+ });
717
+ ctx.command("轨迹答题/B", "选择 B 选项").action(async (argv, _) => {
718
+ await answerHandler(ctx, config, argv, "B");
719
+ return;
720
+ });
721
+ ctx.command("轨迹答题/C", "选择 C 选项").action(async (argv, _) => {
722
+ await answerHandler(ctx, config, argv, "C");
723
+ return;
724
+ });
725
+ ctx.command("轨迹答题/D", "选择 D 选项").action(async (argv, _) => {
726
+ await answerHandler(ctx, config, argv, "D");
727
+ return;
676
728
  });
677
729
  ctx.command("轨迹答题/答题分数").action(async (argv, _) => {
678
730
  await argv.session?.send(`${At(argv)}正在开发中哦~`);
@@ -15,6 +15,7 @@ interface QuestionCache {
15
15
  declare module '@koishijs/cache' {
16
16
  interface Tables {
17
17
  question: QuestionCache;
18
+ todayCache: number;
18
19
  }
19
20
  }
20
21
  export declare function apply(ctx: Context, config: Config): Promise<void>;
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.10",
4
+ "version": "0.0.11",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- export declare function DailySeededName(uid: any): string;
@@ -1,2 +0,0 @@
1
- export declare function DailySeededName(uid: any): string;
2
- export declare function DailySeededRandom(uid: any): () => number;
@@ -1,11 +0,0 @@
1
- /**
2
- * PseudoRandom 伪随机数类
3
- */
4
- declare class PseudoRandom {
5
- private seed;
6
- private randFunc;
7
- constructor(seedStr: string);
8
- next: () => number;
9
- nextInt: (min: number, max: number) => number;
10
- }
11
- export default PseudoRandom;
@@ -1,2 +0,0 @@
1
- declare function HtmlCreator(cardList: any): string;
2
- export default HtmlCreator;
File without changes