@azimiao/koishi-plugin-cafe-bot-exp 0.0.27 → 0.0.28
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 +99 -8
- package/lib/quiz/config.d.ts +4 -0
- package/package.json +2 -1
- package/lib/DailySeededName.d.ts +0 -1
- package/lib/DailySeededRandom.d.ts +0 -2
- package/lib/PseudoRandom.d.ts +0 -11
- package/lib/templete/html.d.ts +0 -2
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.
|
|
43
|
+
var version = "0.0.28";
|
|
44
44
|
|
|
45
45
|
// src/index.ts
|
|
46
46
|
var import_censor = require("@koishijs/censor");
|
|
@@ -100,12 +100,12 @@ var PseudoRandom = class {
|
|
|
100
100
|
"seed": this.seed
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
next =
|
|
103
|
+
next = () => {
|
|
104
104
|
return this.randFunc();
|
|
105
|
-
}
|
|
106
|
-
nextInt =
|
|
105
|
+
};
|
|
106
|
+
nextInt = (min, max) => {
|
|
107
107
|
return Math.floor(this.next() * (max - min + 1)) + min;
|
|
108
|
-
}
|
|
108
|
+
};
|
|
109
109
|
};
|
|
110
110
|
var PseudoRandom_default = PseudoRandom;
|
|
111
111
|
|
|
@@ -520,12 +520,16 @@ 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"),
|
|
527
|
+
appendMDBtn: import_koishi3.Schema.boolean().description("是否追加QQ按钮").default(false)
|
|
524
528
|
}).description("答题配置");
|
|
525
529
|
|
|
526
530
|
// src/common/CafeTimeTools.ts
|
|
527
531
|
var CafeTimeTools = {
|
|
528
|
-
getRemainingSecondsToBeijingMidnight:
|
|
532
|
+
getRemainingSecondsToBeijingMidnight: function() {
|
|
529
533
|
const now = /* @__PURE__ */ new Date();
|
|
530
534
|
const utcNow = now.getTime();
|
|
531
535
|
const target = new Date(now);
|
|
@@ -536,7 +540,7 @@ var CafeTimeTools = {
|
|
|
536
540
|
const diff = target.getTime() - utcNow;
|
|
537
541
|
const seconds = Math.ceil(diff / 1e3);
|
|
538
542
|
return seconds;
|
|
539
|
-
}
|
|
543
|
+
}
|
|
540
544
|
};
|
|
541
545
|
var CafeTimeTools_default = CafeTimeTools;
|
|
542
546
|
|
|
@@ -646,6 +650,93 @@ async function apply2(ctx, config) {
|
|
|
646
650
|
}, { primary: "id", autoInc: true });
|
|
647
651
|
await downloadQuitDataIfNotExist(ctx, config, config.forceUpdateWhenLoad);
|
|
648
652
|
ctx.command("轨迹问答", "证明自己是合格的桂皮吧~");
|
|
653
|
+
ctx.command("轨迹问答/新版出题", "测试新版出题功能", { hidden: true }).action(async (argv, _) => {
|
|
654
|
+
await downloadQuitDataIfNotExist(ctx, config, false);
|
|
655
|
+
var lastQuestion = await ctx.cache.get("question", argv.session.userId);
|
|
656
|
+
if (lastQuestion) {
|
|
657
|
+
await argv.session?.send("上一题还没有回答哦~");
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
var dailyNameKey = DailySeededName(argv.session.userId);
|
|
661
|
+
argv.session.user;
|
|
662
|
+
if (quizDataIds == null || quizDataIds.length <= 0) {
|
|
663
|
+
await argv.session?.send(`${At(argv)}超级计算机『卡佩尔』发生核心故障😵(导力网络异常波动)`);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
var todayCount = await ctx.cache.get("todayCache", dailyNameKey);
|
|
667
|
+
if (!todayCount) {
|
|
668
|
+
todayCount = 0;
|
|
669
|
+
}
|
|
670
|
+
if (todayCount >= config.maxQuizPerDay) {
|
|
671
|
+
await argv.session?.send(`${At(argv)}今日答题已到上限哦~明天再来看看吧❤`);
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
todayCount++;
|
|
675
|
+
var cacheTimeoutTime = CafeTimeTools_default.getRemainingSecondsToBeijingMidnight();
|
|
676
|
+
logger2?.debug(`try set cache ${dailyNameKey}, ${todayCount}`);
|
|
677
|
+
await ctx.cache.set("todayCache", dailyNameKey, todayCount, cacheTimeoutTime * 1e3);
|
|
678
|
+
var randomId = import_koishi4.Random.pick(quizDataIds);
|
|
679
|
+
var qItem = quizDataSet[randomId];
|
|
680
|
+
var qOptions = import_koishi4.Random.shuffle(qItem.options);
|
|
681
|
+
var answerIndex = -1;
|
|
682
|
+
logger2?.info(`${argv.session.userId} get a new quiz(id:${randomId})`);
|
|
683
|
+
for (var i = 0; i < qOptions.length; i++) {
|
|
684
|
+
if (qOptions[i].oid === qItem.a) {
|
|
685
|
+
answerIndex = i;
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
await ctx.cache.set("question", argv.session.userId, { question: randomId, answer: answerIndex }, config.answerTimeout * 1e3);
|
|
690
|
+
var msgQQ = {
|
|
691
|
+
msg_type: 2,
|
|
692
|
+
msg_id: argv.session.messageId,
|
|
693
|
+
markdown: {
|
|
694
|
+
custom_template_id: `${qItem.question.img.length > 0 ? config.qqQuizMDImgID : config.qqQuizMDTextID}`,
|
|
695
|
+
params: [
|
|
696
|
+
{
|
|
697
|
+
key: "user",
|
|
698
|
+
values: [`${argv.session.userId}`]
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
key: "question",
|
|
702
|
+
values: [ctx.censor ? await ctx.censor.transform(qItem.question.s, argv.session) : qItem.question.s]
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
key: "max_time",
|
|
706
|
+
values: [`${config.answerTimeout}`]
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
key: "answer_a",
|
|
710
|
+
values: [ctx.censor ? await ctx.censor.transform(qOptions[0].s, argv.session) : qOptions[0].s]
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
key: "answer_b",
|
|
714
|
+
values: [ctx.censor ? await ctx.censor.transform(qOptions[1].s, argv.session) : qOptions[1].s]
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
key: "answer_c",
|
|
718
|
+
values: [ctx.censor ? await ctx.censor.transform(qOptions[2].s, argv.session) : qOptions[2].s]
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
key: "answer_d",
|
|
722
|
+
values: [ctx.censor ? await ctx.censor.transform(qOptions[3].s, argv.session) : qOptions[3].s]
|
|
723
|
+
}
|
|
724
|
+
]
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
if (config.appendMDBtn) {
|
|
728
|
+
msgQQ.keyboard = {
|
|
729
|
+
id: config.qqQuizButtonID
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
logger2?.debug(JSON.stringify(msgQQ));
|
|
733
|
+
if (argv.session.qq) {
|
|
734
|
+
await argv.session.qq.sendMessage(argv.session.channelId, msgQQ);
|
|
735
|
+
} else {
|
|
736
|
+
await argv.session?.send(JSON.stringify(msgQQ));
|
|
737
|
+
}
|
|
738
|
+
return;
|
|
739
|
+
});
|
|
649
740
|
ctx.command("轨迹问答/出题", "随机抽一道题目").action(async (argv, _) => {
|
|
650
741
|
await downloadQuitDataIfNotExist(ctx, config, false);
|
|
651
742
|
var lastQuestion = await ctx.cache.get("question", argv.session.userId);
|
package/lib/quiz/config.d.ts
CHANGED
|
@@ -9,5 +9,9 @@ export interface CafeBotQuizConfig {
|
|
|
9
9
|
maxQuizPerDay: number;
|
|
10
10
|
redisServer: string;
|
|
11
11
|
redisAuth: string;
|
|
12
|
+
qqQuizMDTextID: string;
|
|
13
|
+
qqQuizMDImgID: string;
|
|
14
|
+
qqQuizButtonID: string;
|
|
15
|
+
appendMDBtn: boolean;
|
|
12
16
|
}
|
|
13
17
|
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.
|
|
4
|
+
"version": "0.0.28",
|
|
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.10.0",
|
|
51
52
|
"@stdlib/random-base-uniform": "^0.2.1",
|
|
52
53
|
"fs.promises.exists": "^1.1.4"
|
|
53
54
|
}
|
package/lib/DailySeededName.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function DailySeededName(uid: any): string;
|
package/lib/PseudoRandom.d.ts
DELETED
package/lib/templete/html.d.ts
DELETED