@azimiao/koishi-plugin-cafe-bot-exp 0.0.13 → 0.0.17
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 +54 -8
- package/lib/quiz/index.d.ts +11 -0
- package/package.json +1 -1
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.
|
|
41
|
+
var version = "0.0.17";
|
|
42
42
|
|
|
43
43
|
// src/draw/index.ts
|
|
44
44
|
var draw_exports = {};
|
|
@@ -281,7 +281,7 @@ var CafeBotDrawConfig = import_koishi.Schema.object({
|
|
|
281
281
|
// src/common/at.ts
|
|
282
282
|
var import_koishi2 = require("koishi");
|
|
283
283
|
function At(argv, newLine = true) {
|
|
284
|
-
let AtStr = argv.session && !argv.session.isDirect ? `${import_koishi2.segment.at(argv.session.userId)}${newLine ? "\
|
|
284
|
+
let AtStr = argv.session && !argv.session.isDirect ? `${import_koishi2.segment.at(argv.session.userId)}${newLine ? "\n" : ""}` : "";
|
|
285
285
|
return AtStr;
|
|
286
286
|
}
|
|
287
287
|
__name(At, "At");
|
|
@@ -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>", `使用"回答+空格+选项"
|
|
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,31 @@ D. ${qOptions[3].s}`;
|
|
|
740
764
|
await answerHandler(ctx, config, argv, "D");
|
|
741
765
|
return;
|
|
742
766
|
});
|
|
743
|
-
ctx.command("
|
|
744
|
-
await
|
|
745
|
-
|
|
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 right = userQuizA.right;
|
|
775
|
+
let total = right + userQuizA.wrong;
|
|
776
|
+
let percent = Math.round(userQuizA.right * 1 / total * 100);
|
|
777
|
+
let comment = "继续努力吧~";
|
|
778
|
+
if (percent >= 95) {
|
|
779
|
+
comment = "哇,难道您就是传说中的桂皮?!";
|
|
780
|
+
} else if (total >= 80) {
|
|
781
|
+
comment = "离合格的桂皮只有一步之遥?!";
|
|
782
|
+
} else if (total >= 50) {
|
|
783
|
+
comment = "正在成为桂皮中……";
|
|
784
|
+
}
|
|
785
|
+
await argv.session?.send(`${At(argv)}你的答题数据:
|
|
786
|
+
- 答题总数: ${total}
|
|
787
|
+
- 正确回答: ${right}
|
|
788
|
+
- 正确率: ${percent}%
|
|
789
|
+
${comment}`);
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
746
792
|
});
|
|
747
793
|
}
|
|
748
794
|
__name(apply3, "apply");
|
|
@@ -757,7 +803,7 @@ var Config4 = import_koishi7.Schema.intersect([
|
|
|
757
803
|
|
|
758
804
|
// src/index.ts
|
|
759
805
|
var name4 = "cafe-bot-exp";
|
|
760
|
-
var inject3 = ["http", "cache", "logger"];
|
|
806
|
+
var inject3 = ["http", "cache", "logger", "database"];
|
|
761
807
|
async function apply4(ctx, config) {
|
|
762
808
|
ctx.plugin(draw_exports, config);
|
|
763
809
|
ctx.plugin(quiz_exports, config);
|
package/lib/quiz/index.d.ts
CHANGED
|
@@ -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 {};
|