@azimiao/koishi-plugin-cafe-bot-exp 0.0.27 → 0.0.30

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";
43
+ var version = "0.0.30";
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 = /* @__PURE__ */ __name(() => {
103
+ next = () => {
104
104
  return this.randFunc();
105
- }, "next");
106
- nextInt = /* @__PURE__ */ __name((min, max) => {
105
+ };
106
+ nextInt = (min, max) => {
107
107
  return Math.floor(this.next() * (max - min + 1)) + min;
108
- }, "nextInt");
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: /* @__PURE__ */ __name(function() {
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
- }, "getRemainingSecondsToBeijingMidnight")
543
+ }
540
544
  };
541
545
  var CafeTimeTools_default = CafeTimeTools;
542
546
 
@@ -646,6 +650,95 @@ 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
+ content: "111",
692
+ msg_type: 2,
693
+ msg_id: argv.session.messageId,
694
+ timestamp: argv.session.timestamp,
695
+ markdown: {
696
+ custom_template_id: `${qItem.question.img.length > 0 ? config.qqQuizMDImgID : config.qqQuizMDTextID}`,
697
+ params: [
698
+ {
699
+ key: "user",
700
+ values: [`${argv.session.userId}`]
701
+ },
702
+ {
703
+ key: "question",
704
+ values: [ctx.censor ? await ctx.censor.transform(qItem.question.s, argv.session) : qItem.question.s]
705
+ },
706
+ {
707
+ key: "max_time",
708
+ values: [`${config.answerTimeout}`]
709
+ },
710
+ {
711
+ key: "answer_a",
712
+ values: [ctx.censor ? await ctx.censor.transform(qOptions[0].s, argv.session) : qOptions[0].s]
713
+ },
714
+ {
715
+ key: "answer_b",
716
+ values: [ctx.censor ? await ctx.censor.transform(qOptions[1].s, argv.session) : qOptions[1].s]
717
+ },
718
+ {
719
+ key: "answer_c",
720
+ values: [ctx.censor ? await ctx.censor.transform(qOptions[2].s, argv.session) : qOptions[2].s]
721
+ },
722
+ {
723
+ key: "answer_d",
724
+ values: [ctx.censor ? await ctx.censor.transform(qOptions[3].s, argv.session) : qOptions[3].s]
725
+ }
726
+ ]
727
+ }
728
+ };
729
+ if (config.appendMDBtn) {
730
+ msgQQ.keyboard = {
731
+ id: config.qqQuizButtonID
732
+ };
733
+ }
734
+ logger2?.debug(JSON.stringify(msgQQ));
735
+ if (argv.session.qq) {
736
+ await argv.session.qq.sendMessage(argv.session.channelId, msgQQ);
737
+ } else {
738
+ await argv.session?.send(JSON.stringify(msgQQ));
739
+ }
740
+ return;
741
+ });
649
742
  ctx.command("轨迹问答/出题", "随机抽一道题目").action(async (argv, _) => {
650
743
  await downloadQuitDataIfNotExist(ctx, config, false);
651
744
  var lastQuestion = await ctx.cache.get("question", argv.session.userId);
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",
4
+ "version": "0.0.30",
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
  }
@@ -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,9 +0,0 @@
1
- import { Schema } from "koishi";
2
- export interface CafeBotCatConfig {
3
- catName: string;
4
- }
5
- export declare const CafeBotCatConfig: Schema<Schemastery.ObjectS<{
6
- catName: Schema<string, string>;
7
- }>, Schemastery.ObjectT<{
8
- catName: Schema<string, string>;
9
- }>>;
@@ -1,15 +0,0 @@
1
- /**
2
- * 黑猫柯贝
3
- */
4
- import { Context, Schema } from 'koishi';
5
- import { CafeBotCatConfig } from './config';
6
- export declare const name = "cafe-bot-exp.cat";
7
- export interface Config extends CafeBotCatConfig {
8
- }
9
- export declare const Config: Schema<Config>;
10
- export declare const injectDepend: {
11
- required: any[];
12
- optional: string[];
13
- };
14
- export declare const inject: any[];
15
- export declare function apply(ctx: Context): Promise<void>;
@@ -1,4 +0,0 @@
1
- declare const CafeTimeTools: {
2
- getRemainingSecondsToBeijingMidnight: () => number;
3
- };
4
- export default CafeTimeTools;
@@ -1 +0,0 @@
1
- export declare function DailySeededName(uid: any): string;
@@ -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 +0,0 @@
1
- export declare function At(argv: any, newLine?: boolean): string;
@@ -1,3 +0,0 @@
1
- import { HTTP } from "koishi";
2
- declare function downloadFileIfNotExist(http: HTTP, downloadUrl: string, savePath: string, forceUpdate: boolean): Promise<boolean>;
3
- export default downloadFileIfNotExist;
package/lib/config.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { Schema } from "koishi";
2
- import { CafeBotDrawConfig } from "./draw/config";
3
- import { CafeBotQuizConfig } from "./quiz/config";
4
- import { CafeBotCatConfig } from "./cat/config";
5
- export interface CafeBotConfig {
6
- logoUrl: string;
7
- refreshLogoWhenLoad: boolean;
8
- useLocalLogoFile: boolean;
9
- }
10
- export type Config = CafeBotConfig & CafeBotDrawConfig & CafeBotQuizConfig & CafeBotCatConfig;
11
- export declare const Config: Schema<Config>;
@@ -1,24 +0,0 @@
1
- /**
2
- * 轨迹抽卡配置
3
- */
4
- import { Schema } from "koishi";
5
- export interface CafeBotDrawConfig {
6
- baseDataUrl: string;
7
- forceUpdateDataWhenLoad: boolean;
8
- ImageServer: string;
9
- ImageServerAuth: string;
10
- ImageNoCache: boolean;
11
- MinCount: number;
12
- MaxCount: number;
13
- Star1Name: string;
14
- Star1Chance: number;
15
- Star2Name: string;
16
- Star2Chance: number;
17
- Star3Name: string;
18
- Star3Chance: number;
19
- Star4Name: string;
20
- Star4Chance: number;
21
- Star5Name: string;
22
- Star5Chance: number;
23
- }
24
- export declare const CafeBotDrawConfig: Schema<CafeBotDrawConfig>;
@@ -1,15 +0,0 @@
1
- /**
2
- * 轨迹抽卡
3
- */
4
- import { Context, Schema } from 'koishi';
5
- import { CafeBotDrawConfig } from './config';
6
- export declare const name = "cafe-bot-exp.draw";
7
- export declare const injectDepend: {
8
- required: string[];
9
- optional: string[];
10
- };
11
- export declare const inject: string[];
12
- export interface Config extends CafeBotDrawConfig {
13
- }
14
- export declare const Config: Schema<Config>;
15
- export declare function apply(ctx: Context, config: Config): Promise<void>;
@@ -1,2 +0,0 @@
1
- declare function HtmlCreator(cardList: any): string;
2
- export default HtmlCreator;
package/lib/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * 主入口文件
3
- */
4
- import { Context } from 'koishi';
5
- import { Config } from './config';
6
- import '@koishijs/censor';
7
- import * as draw from "./draw/index";
8
- import * as quiz from "./quiz/index";
9
- import * as cat from "./cat/index";
10
- export declare const name = "cafe-bot-exp";
11
- export * from "./config";
12
- export declare const plugins: (typeof draw | typeof quiz | typeof cat)[];
13
- export declare const inject: {
14
- required: any[];
15
- optional: string[];
16
- };
17
- export declare function apply(ctx: Context, config: Config): Promise<void>;
@@ -1,13 +0,0 @@
1
- /**
2
- * 轨迹答题配置
3
- */
4
- import { Schema } from "koishi";
5
- export interface CafeBotQuizConfig {
6
- baseQuizUrl: string;
7
- forceUpdateWhenLoad: boolean;
8
- answerTimeout: number;
9
- maxQuizPerDay: number;
10
- redisServer: string;
11
- redisAuth: string;
12
- }
13
- export declare const CafeBotQuizConfig: Schema<CafeBotQuizConfig>;
@@ -1,37 +0,0 @@
1
- /**
2
- * 轨迹问答
3
- */
4
- import { Context, Schema } from 'koishi';
5
- import { CafeBotQuizConfig } from './config';
6
- export declare const name = "cafe-bot-exp.quiz";
7
- export declare const injectDepend: {
8
- required: string[];
9
- optional: string[];
10
- };
11
- export declare const inject: string[];
12
- export interface Config extends CafeBotQuizConfig {
13
- }
14
- export declare const Config: Schema<Config>;
15
- interface QuestionCache {
16
- question: number;
17
- answer: number;
18
- }
19
- declare module '@koishijs/cache' {
20
- interface Tables {
21
- question: QuestionCache;
22
- todayCache: number;
23
- }
24
- }
25
- declare module 'koishi' {
26
- interface Tables {
27
- 'cafeQuiz': CafeQuiz;
28
- }
29
- }
30
- export interface CafeQuiz {
31
- id: number;
32
- userId: string;
33
- right: number;
34
- wrong: number;
35
- }
36
- export declare function apply(ctx: Context, config: Config): Promise<void>;
37
- export {};
@@ -1,2 +0,0 @@
1
- declare function HtmlCreator(cardList: any): string;
2
- export default HtmlCreator;