@azimiao/koishi-plugin-cafe-bot-exp 0.0.27-beta1 → 0.0.27-beta3

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
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(src_exports);
40
40
  var import_url = require("url");
41
41
 
42
42
  // package.json
43
- var version = "0.0.27-beta1";
43
+ var version = "0.0.27-beta3";
44
44
 
45
45
  // src/index.ts
46
46
  var import_censor = require("@koishijs/censor");
@@ -520,7 +520,10 @@ var CafeBotQuizConfig = import_koishi3.Schema.object({
520
520
  maxQuizPerDay: import_koishi3.Schema.number().description("每日单人最大答题数").default(5),
521
521
  redisServer: import_koishi3.Schema.string().description("redis服务器地址"),
522
522
  // TODO: 计划: 分数存储使用 sqlite, 临时数据(如当前题目)用内存就行了?
523
- redisAuth: import_koishi3.Schema.string().description("redis服务器密码")
523
+ redisAuth: import_koishi3.Schema.string().description("redis服务器密码"),
524
+ qqQuizMDTextID: import_koishi3.Schema.string().description("QQ markdown 纯本文模板ID"),
525
+ qqQuizMDImgID: import_koishi3.Schema.string().description("QQ markdown 题目带图模板ID"),
526
+ qqQuizButtonID: import_koishi3.Schema.string().description("QQ按钮ID")
524
527
  }).description("答题配置");
525
528
 
526
529
  // src/common/CafeTimeTools.ts
@@ -646,6 +649,91 @@ async function apply2(ctx, config) {
646
649
  }, { primary: "id", autoInc: true });
647
650
  await downloadQuitDataIfNotExist(ctx, config, config.forceUpdateWhenLoad);
648
651
  ctx.command("轨迹问答", "证明自己是合格的桂皮吧~");
652
+ ctx.command("轨迹问答/新版出题", "测试新版出题功能", { hidden: true }).action(async (argv, _) => {
653
+ await downloadQuitDataIfNotExist(ctx, config, false);
654
+ var lastQuestion = await ctx.cache.get("question", argv.session.userId);
655
+ if (lastQuestion) {
656
+ await argv.session?.send("上一题还没有回答哦~");
657
+ return;
658
+ }
659
+ var dailyNameKey = DailySeededName(argv.session.userId);
660
+ argv.session.user;
661
+ if (quizDataIds == null || quizDataIds.length <= 0) {
662
+ await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵(导力网络异常波动)`);
663
+ return;
664
+ }
665
+ var todayCount = await ctx.cache.get("todayCache", dailyNameKey);
666
+ if (!todayCount) {
667
+ todayCount = 0;
668
+ }
669
+ if (todayCount >= config.maxQuizPerDay) {
670
+ await argv.session?.send(`${At(argv)}今日答题已到上限哦~明天再来看看吧❤`);
671
+ return;
672
+ }
673
+ todayCount++;
674
+ var cacheTimeoutTime = CafeTimeTools_default.getRemainingSecondsToBeijingMidnight();
675
+ logger2?.debug(`try set cache ${dailyNameKey}, ${todayCount}`);
676
+ await ctx.cache.set("todayCache", dailyNameKey, todayCount, cacheTimeoutTime * 1e3);
677
+ var randomId = import_koishi4.Random.pick(quizDataIds);
678
+ var qItem = quizDataSet[randomId];
679
+ var qOptions = import_koishi4.Random.shuffle(qItem.options);
680
+ var answerIndex = -1;
681
+ logger2?.info(`${argv.session.userId} get a new quiz(id:${randomId})`);
682
+ for (var i = 0; i < qOptions.length; i++) {
683
+ if (qOptions[i].oid === qItem.a) {
684
+ answerIndex = i;
685
+ break;
686
+ }
687
+ }
688
+ await ctx.cache.set("question", argv.session.userId, { question: randomId, answer: answerIndex }, config.answerTimeout * 1e3);
689
+ var msgQQ = {
690
+ "msg_type": 2,
691
+ "msg_id": `${argv.session.messageId}`,
692
+ "markdown": {
693
+ "custom_template_id": `${qItem.question.img.length > 0 ? config.qqQuizMDImgID : config.qqQuizMDTextID}`,
694
+ "params": [
695
+ {
696
+ "key": "user",
697
+ "values": [`${argv.session.userId}`]
698
+ },
699
+ {
700
+ "key": "question",
701
+ "values": [`${ctx.censor ? "<censor>" : ""}${qItem.question.s}${ctx.censor ? "</censor>" : ""}`]
702
+ },
703
+ {
704
+ "key": "max_time",
705
+ "values": [`${config.answerTimeout}`]
706
+ },
707
+ {
708
+ "key": "answer_a",
709
+ "values": [`${ctx.censor ? "<censor>" : ""}${qOptions[0].s}${ctx.censor ? "</censor>" : ""}`]
710
+ },
711
+ {
712
+ "key": "answer_b",
713
+ "values": [`${ctx.censor ? "<censor>" : ""}${qOptions[1].s}${ctx.censor ? "</censor>" : ""}`]
714
+ },
715
+ {
716
+ "key": "answer_c",
717
+ "values": [`${ctx.censor ? "<censor>" : ""}${qOptions[2].s}${ctx.censor ? "</censor>" : ""}`]
718
+ },
719
+ {
720
+ "key": "answer_d",
721
+ "values": [`${ctx.censor ? "<censor>" : ""}${qOptions[3].s}${ctx.censor ? "</censor>" : ""}`]
722
+ }
723
+ ]
724
+ },
725
+ "keyboard": {
726
+ "id": `${config.qqQuizButtonID}`
727
+ }
728
+ };
729
+ console.log(msgQQ);
730
+ if (argv.session.qq) {
731
+ await argv.session.qq.sendMessage(argv.session.channelId, msgQQ);
732
+ } else {
733
+ await argv.session?.send(JSON.stringify(msgQQ));
734
+ }
735
+ return;
736
+ });
649
737
  ctx.command("轨迹问答/出题", "随机抽一道题目").action(async (argv, _) => {
650
738
  await downloadQuitDataIfNotExist(ctx, config, false);
651
739
  var lastQuestion = await ctx.cache.get("question", argv.session.userId);
@@ -9,5 +9,8 @@ export interface CafeBotQuizConfig {
9
9
  maxQuizPerDay: number;
10
10
  redisServer: string;
11
11
  redisAuth: string;
12
+ qqQuizMDTextID: string;
13
+ qqQuizMDImgID: string;
14
+ qqQuizButtonID: string;
12
15
  }
13
16
  export declare const CafeBotQuizConfig: Schema<CafeBotQuizConfig>;
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.27-beta1",
4
+ "version": "0.0.27-beta3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "repository": {
@@ -48,6 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@koishijs/censor": "^1.1.0",
51
+ "@koishijs/plugin-adapter-qq": "^4.9.2",
51
52
  "@stdlib/random-base-uniform": "^0.2.1",
52
53
  "fs.promises.exists": "^1.1.4"
53
54
  }