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

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
 
@@ -396,6 +396,7 @@ async function getCards(seed, ctx, config) {
396
396
  __name(getCards, "getCards");
397
397
  async function apply(ctx, config) {
398
398
  await downloadCardDataIfNotExist(ctx, config, config.forceUpdateDataWhenLoad);
399
+ ctx.command("轨迹抽卡", `抽取你的每日轨迹人物卡吧~`);
399
400
  ctx.command("轨迹抽卡/给我抽", "进行每日抽卡").action(async (argv, _) => {
400
401
  let seed = DailySeededName(argv.session.userId);
401
402
  console.log(`getcard for ${seed}`);
@@ -572,6 +573,23 @@ var CafeBotQuizConfig = import_koishi5.Schema.object({
572
573
  redisAuth: import_koishi5.Schema.string().description("redis服务器密码")
573
574
  }).description("答题配置");
574
575
 
576
+ // src/common/CafeTimeTools.ts
577
+ var CafeTimeTools = {
578
+ getRemainingSecondsToBeijingMidnight: function() {
579
+ const now = /* @__PURE__ */ new Date();
580
+ const utcNow = now.getTime();
581
+ const target = new Date(now);
582
+ target.setUTCHours(16, 0, 0, 0);
583
+ if (utcNow >= target.getTime()) {
584
+ target.setUTCDate(target.getUTCDate() + 1);
585
+ }
586
+ const diff = target.getTime() - utcNow;
587
+ const seconds = Math.ceil(diff / 1e3);
588
+ return seconds;
589
+ }
590
+ };
591
+ var CafeTimeTools_default = CafeTimeTools;
592
+
575
593
  // src/quiz/index.ts
576
594
  var name3 = "cafe-bot-exp.quiz";
577
595
  var inject2 = ["http", "cache"];
@@ -614,6 +632,36 @@ async function downloadQuitDataIfNotExist(ctx, config, forceUpdate) {
614
632
  return;
615
633
  }
616
634
  __name(downloadQuitDataIfNotExist, "downloadQuitDataIfNotExist");
635
+ async function answerHandler(ctx, config, argv, answer) {
636
+ await downloadQuitDataIfNotExist(ctx, config, false);
637
+ var lastQuestion = await ctx.cache.get("question", argv.session.userId);
638
+ if (!lastQuestion) {
639
+ await argv.session?.send("你还未开始答题或已超时哦~");
640
+ return;
641
+ }
642
+ let selectNumber = -1;
643
+ if (answer in validOptions) {
644
+ selectNumber = validOptions[answer];
645
+ } else {
646
+ await argv.session?.send(`${At(argv)}选项无效,请重新输入~`);
647
+ return;
648
+ }
649
+ await ctx.cache.delete("question", argv.session.userId);
650
+ if (quizDataIds == null || quizDataIds.length <= 0) {
651
+ await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵`);
652
+ return;
653
+ }
654
+ var qItem = quizDataSet[lastQuestion.question];
655
+ console.log(`${argv.session.userId} try answer quiz(id:${lastQuestion.question}), input answer:${selectNumber}`);
656
+ if (qItem && lastQuestion.answer == selectNumber) {
657
+ await argv.session?.send(`${At(argv)}回答正确😊${qItem.explain.length > 0 ? "," + qItem.explain : ""}`);
658
+ return;
659
+ } else {
660
+ await argv.session?.send(`${At(argv)}回答错误😟${qItem.explain2.length > 0 ? "," + qItem.explain2 : ""}`);
661
+ return;
662
+ }
663
+ }
664
+ __name(answerHandler, "answerHandler");
617
665
  async function apply3(ctx, config) {
618
666
  await downloadQuitDataIfNotExist(ctx, config, config.forceUpdateWhenLoad);
619
667
  ctx.command("轨迹答题/出题").action(async (argv, _) => {
@@ -623,14 +671,27 @@ async function apply3(ctx, config) {
623
671
  await argv.session?.send("上一题还没有回答哦~");
624
672
  return;
625
673
  }
674
+ var dailyNameKey = DailySeededName(argv.session.userId);
626
675
  if (quizDataIds == null || quizDataIds.length <= 0) {
627
- await argv.session?.send(`${At(argv)}题目数据获取失败~`);
676
+ await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵`);
628
677
  return;
629
678
  }
679
+ var todayCount = await ctx.cache.get("todayCache", dailyNameKey);
680
+ if (!todayCount) {
681
+ todayCount = 0;
682
+ }
683
+ if (todayCount >= config.maxQuizPerDay) {
684
+ await argv.session?.send(`${At(argv)}今日答题已到上限哦~明天再来看看吧❤`);
685
+ return;
686
+ }
687
+ todayCount++;
688
+ var cacheTimeoutTime = CafeTimeTools_default.getRemainingSecondsToBeijingMidnight();
689
+ await ctx.cache.set("todayCache", dailyNameKey, todayCount, cacheTimeoutTime * 1e3);
630
690
  var randomId = import_koishi6.Random.pick(quizDataIds);
631
691
  var qItem = quizDataSet[randomId];
632
692
  var qOptions = import_koishi6.Random.shuffle(qItem.options);
633
693
  var answerIndex = -1;
694
+ console.log(`${argv.session.userId} get a new quiz(id:${randomId})`);
634
695
  for (var i = 0; i < qOptions.length; i++) {
635
696
  if (qOptions[i].oid === qItem.a) {
636
697
  answerIndex = i;
@@ -639,40 +700,33 @@ async function apply3(ctx, config) {
639
700
  }
640
701
  await ctx.cache.set("question", argv.session.userId, { question: randomId, answer: answerIndex }, config.answerTimeout * 1e3);
641
702
  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}`;
703
+ A. ${qOptions[0].s}
704
+ B. ${qOptions[1].s}
705
+ C. ${qOptions[2].s}
706
+ D. ${qOptions[3].s}`;
646
707
  await argv.session?.send(messageQuestion);
647
708
  return;
648
709
  });
649
- 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
+ ctx.command("轨迹答题").usage("通过趣味答题看看你是不是合格的桂皮吧~");
711
+ ctx.command("轨迹答题/回答 <answer:text>", `使用"回答+空格+选项"回答问题哦,如"回答 A"`).action(async (argv, answer) => {
712
+ await answerHandler(ctx, config, argv, answer);
713
+ return;
714
+ });
715
+ ctx.command("轨迹答题/A", "选择 A 选项", { hidden: true }).action(async (argv, _) => {
716
+ await answerHandler(ctx, config, argv, "A");
717
+ return;
718
+ });
719
+ ctx.command("轨迹答题/B", "选择 B 选项", { hidden: true }).action(async (argv, _) => {
720
+ await answerHandler(ctx, config, argv, "B");
721
+ return;
722
+ });
723
+ ctx.command("轨迹答题/C", "选择 C 选项", { hidden: true }).action(async (argv, _) => {
724
+ await answerHandler(ctx, config, argv, "C");
725
+ return;
726
+ });
727
+ ctx.command("轨迹答题/D", "选择 D 选项", { hidden: true }).action(async (argv, _) => {
728
+ await answerHandler(ctx, config, argv, "D");
729
+ return;
676
730
  });
677
731
  ctx.command("轨迹答题/答题分数").action(async (argv, _) => {
678
732
  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.12",
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