koishi-plugin-toram 4.2.0-test.2 → 4.2.0-test.3

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.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import { Context, Logger, Schema, Session } from 'koishi';
2
+ import { UserData, BotTodoItem } from './script';
2
3
  export declare const name = "toram";
3
4
  export declare const inject: string[];
4
5
  declare module 'koishi' {
6
+ interface Tables {
7
+ toram_user: UserData;
8
+ toram_todo: BotTodoItem;
9
+ }
5
10
  }
6
11
  export interface Config {
7
12
  qq: string;
package/lib/index.js CHANGED
@@ -219,7 +219,7 @@ __name(executeMonthlyCardReminder, "executeMonthlyCardReminder");
219
219
  function genMonthlyCardReminderUsers(timeIndex) {
220
220
  const users = UserMgr.Inst().getUsersWithMonthlyCardRemindTimeIndex(timeIndex);
221
221
  if (users.length === 0) return;
222
- const atUsers = users.map((user) => `<at id="${user.qq}"/>`).join(" ") + " ";
222
+ const atUsers = users.map((user) => `<at id="${user.qq}"/>`).join(" ");
223
223
  return atUsers;
224
224
  }
225
225
  __name(genMonthlyCardReminderUsers, "genMonthlyCardReminderUsers");
@@ -463,7 +463,7 @@ function command_monthlyCardRemind(event, args) {
463
463
  return;
464
464
  }
465
465
  const { timeIndex } = checkResult.result;
466
- const qq = Number(event.session.event.user.id);
466
+ const qq = event.session.event.user.id;
467
467
  UserMgr.Inst().setUserMonthlyCardRemindTimeIndex(qq, timeIndex);
468
468
  const hours = [
469
469
  event.config.monthlyCardReminder_midnightTime,
@@ -491,13 +491,25 @@ function checkArgs3(args) {
491
491
  }
492
492
  __name(checkArgs3, "checkArgs");
493
493
  function command_cancelMonthlyCardRemind(event, args) {
494
- const qq = Number(event.session.event.user.id);
494
+ const qq = event.session.event.user.id;
495
495
  UserMgr.Inst().setUserMonthlyCardRemindTimeIndex(qq, -1);
496
496
  TalkMgr.Inst().reply(event, "简易回复", {
497
497
  result: "月卡提醒取消成功!"
498
498
  });
499
499
  }
500
500
  __name(command_cancelMonthlyCardRemind, "command_cancelMonthlyCardRemind");
501
+ function confirmMonthlyCardGet(event) {
502
+ const qq = event.session.event.user.id;
503
+ const user = UserMgr.Inst().getAllMonthlyCardRemindUsers().find((u) => u.qq === qq);
504
+ let result;
505
+ if (user) {
506
+ result = UserMgr.Inst().updateUserLastGetMonthlyCardDate(qq);
507
+ } else {
508
+ result = new Result(1002 /* 无需处理 */);
509
+ }
510
+ return result;
511
+ }
512
+ __name(confirmMonthlyCardGet, "confirmMonthlyCardGet");
501
513
 
502
514
  // src/script/monster/monsterClass.ts
503
515
  var ElementType = /* @__PURE__ */ ((ElementType2) => {
@@ -576,16 +588,16 @@ var _UserMgr = class _UserMgr {
576
588
  }
577
589
  return _UserMgr.instance;
578
590
  }
579
- setUsers() {
580
- const data = JsonMgr.Inst().getJson("users.json");
591
+ async setUsers(ctx) {
592
+ this.ctx = ctx;
593
+ const data = await ctx.database.get("toram_user", {});
581
594
  if (!data) return;
582
595
  data.forEach((user) => {
583
596
  this._users.set(user.qq, user);
584
597
  });
585
598
  }
586
- saveUsers() {
587
- const data = Array.from(this._users.values());
588
- JsonMgr.Inst().saveJson("users.json", data);
599
+ saveUser(user) {
600
+ this.ctx.database.upsert("toram_user", () => [user]);
589
601
  }
590
602
  addUser(qq, saveNow = true) {
591
603
  const user = {
@@ -597,7 +609,7 @@ var _UserMgr = class _UserMgr {
597
609
  };
598
610
  this._users.set(user.qq, user);
599
611
  if (saveNow) {
600
- this.saveUsers();
612
+ this.saveUser(user);
601
613
  }
602
614
  }
603
615
  setUserMonthlyCardRemindTimeIndex(qq, timeIndex) {
@@ -607,7 +619,7 @@ var _UserMgr = class _UserMgr {
607
619
  user = this._users.get(qq);
608
620
  }
609
621
  user.monthlyCardRemindTimeIndex = timeIndex;
610
- this.saveUsers();
622
+ this.saveUser(user);
611
623
  }
612
624
  getUsersWithMonthlyCardRemindTimeIndex(timeIndex) {
613
625
  const result = [];
@@ -619,6 +631,14 @@ var _UserMgr = class _UserMgr {
619
631
  });
620
632
  return result;
621
633
  }
634
+ getAllMonthlyCardRemindUsers() {
635
+ const result = [];
636
+ this._users.forEach((user) => {
637
+ if (user.monthlyCardRemindTimeIndex === -1) return;
638
+ result.push(user);
639
+ });
640
+ return result;
641
+ }
622
642
  updateUserLastGetMonthlyCardDate(qq) {
623
643
  let user = this._users.get(qq);
624
644
  if (!user) {
@@ -626,8 +646,13 @@ var _UserMgr = class _UserMgr {
626
646
  user = this._users.get(qq);
627
647
  }
628
648
  const now = /* @__PURE__ */ new Date();
629
- user.lastGetMonthlyCardDate = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
630
- this.saveUsers();
649
+ const dateStr = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
650
+ if (user.lastGetMonthlyCardDate === dateStr) {
651
+ return new Result(1002 /* 无需处理 */);
652
+ }
653
+ user.lastGetMonthlyCardDate = dateStr;
654
+ this.saveUser(user);
655
+ return new Result(1001 /* 通过 */);
631
656
  }
632
657
  };
633
658
  __name(_UserMgr, "UserMgr");
@@ -833,12 +858,27 @@ var Config = import_koishi.Schema.intersect([
833
858
  ]);
834
859
  async function apply(ctx, config) {
835
860
  const logger = ctx.logger("toram");
861
+ ctx.model.extend("toram_user", {
862
+ // 各字段的类型声明
863
+ qq: "string",
864
+ nickname: "string",
865
+ otherNames: "list",
866
+ monthlyCardRemindTimeIndex: "integer",
867
+ lastGetMonthlyCardDate: "string"
868
+ });
869
+ ctx.model.extend("toram_todo", {
870
+ // 各字段的类型声明
871
+ id: "string",
872
+ ts: "double",
873
+ type: "string",
874
+ payload: "json"
875
+ });
836
876
  JsonMgr.Inst().setLogger(logger);
837
877
  await JsonMgr.Inst().loadJson();
838
878
  const bot = ctx.bots.find((bot2) => bot2.selfId === config.qq);
839
879
  TalkMgr.Inst().setBot(bot);
840
880
  TalkMgr.Inst().setTalks();
841
- UserMgr.Inst().setUsers();
881
+ await UserMgr.Inst().setUsers(ctx);
842
882
  MonsterMgr.Inst().setMonsters();
843
883
  BotTodoMgr.Inst().setTodos();
844
884
  registerBotTodoHandlers();
@@ -853,6 +893,13 @@ async function apply(ctx, config) {
853
893
  ]);
854
894
  ctx.on("notice", (session) => {
855
895
  if (config.sendDialog) logger.info(session);
896
+ const event = newEvent(ctx, session, config, logger);
897
+ const result = confirmMonthlyCardGet(event);
898
+ if (result.code === 1001 /* 通过 */) {
899
+ TalkMgr.Inst().reply(event, "月卡确认领取");
900
+ } else {
901
+ TalkMgr.Inst().reply(event, "戳一戳");
902
+ }
856
903
  });
857
904
  ctx.middleware(async (session, next) => {
858
905
  if (config.sendDialog) logger.info(session);
@@ -24,12 +24,12 @@
24
24
  "你输入的时间段不正确哦?\n时间段可选:凌晨 早上 中午 下午 晚上 深夜"
25
25
  ],
26
26
  "月卡提醒": [
27
- "@_atUsers_@\n魔导书来提醒你去领今天的月卡啦~",
28
- "@_atUsers_@\n记得去领今天的月卡哦?",
29
- "@_atUsers_@\n你领了今天的月卡了吗?",
30
- "@_atUsers_@\n别忘了今天的月卡哦~",
31
- "@_atUsers_@\n今天的月卡记得领取哦!",
32
- "@_atUsers_@\n布谷布谷,领月卡的时间到啦~",
33
- "@_atUsers_@\n快去领今天的月卡吧!"
27
+ "@_atUsers_@ \n魔导书来提醒你去领今天的月卡啦~",
28
+ "@_atUsers_@ \n记得去领今天的月卡哦?",
29
+ "@_atUsers_@ \n你领了今天的月卡了吗?",
30
+ "@_atUsers_@ \n别忘了今天的月卡哦~",
31
+ "@_atUsers_@ \n今天的月卡记得领取哦!",
32
+ "@_atUsers_@ \n布谷布谷,领月卡的时间到啦~",
33
+ "@_atUsers_@ \n快去领今天的月卡吧!"
34
34
  ]
35
35
  }
@@ -1,5 +1,6 @@
1
1
  export declare enum Code {
2
2
  通过 = 1001,
3
+ 无需处理 = 1002,
3
4
  参数缺失 = 2001,
4
5
  无权限 = 2002,
5
6
  等级不正确 = 3001,
@@ -1,3 +1,5 @@
1
1
  import { SessionEvent } from "../..";
2
+ import { Result } from "..";
2
3
  export declare function command_monthlyCardRemind(event: SessionEvent, args: string[]): void;
3
4
  export declare function command_cancelMonthlyCardRemind(event: SessionEvent, args: string[]): void;
5
+ export declare function confirmMonthlyCardGet(event: SessionEvent): Result<void>;
@@ -1,12 +1,15 @@
1
- import { UserData } from "..";
1
+ import { Context } from "koishi";
2
+ import { Result, UserData } from "..";
2
3
  export declare class UserMgr {
3
4
  private static instance;
4
5
  static Inst(): UserMgr;
6
+ private ctx;
5
7
  private _users;
6
- setUsers(): void;
7
- private saveUsers;
8
- addUser(qq: number, saveNow?: boolean): void;
9
- setUserMonthlyCardRemindTimeIndex(qq: number, timeIndex: number): void;
8
+ setUsers(ctx: Context): Promise<void>;
9
+ private saveUser;
10
+ addUser(qq: string, saveNow?: boolean): void;
11
+ setUserMonthlyCardRemindTimeIndex(qq: string, timeIndex: number): void;
10
12
  getUsersWithMonthlyCardRemindTimeIndex(timeIndex: number): UserData[];
11
- updateUserLastGetMonthlyCardDate(qq: number): void;
13
+ getAllMonthlyCardRemindUsers(): UserData[];
14
+ updateUserLastGetMonthlyCardDate(qq: string): Result<void>;
12
15
  }
@@ -1,5 +1,5 @@
1
1
  export interface UserData {
2
- qq: number;
2
+ qq: string;
3
3
  nickname: string;
4
4
  otherNames: string[];
5
5
  monthlyCardRemindTimeIndex: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-toram",
3
3
  "description": "托拉姆物语小工具",
4
- "version": "4.2.0-test.2",
4
+ "version": "4.2.0-test.3",
5
5
  "contributors": [
6
6
  "青灯 <1874053520@qq.com>"
7
7
  ],