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

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
@@ -662,7 +662,7 @@ var UserMgr = _UserMgr;
662
662
  // src/script/BotTodoMgr.ts
663
663
  var _BotTodoMgr = class _BotTodoMgr {
664
664
  constructor() {
665
- this.jsonName = "botTodos.json";
665
+ this.ctx = null;
666
666
  this._todos = /* @__PURE__ */ new Map();
667
667
  this._handlers = /* @__PURE__ */ new Map();
668
668
  this._timer = null;
@@ -675,8 +675,9 @@ var _BotTodoMgr = class _BotTodoMgr {
675
675
  return _BotTodoMgr.instance;
676
676
  }
677
677
  // 读取 json 到内存
678
- setTodos() {
679
- const data = JsonMgr.Inst().getJson(this.jsonName);
678
+ async setTodos(ctx) {
679
+ this.ctx = ctx;
680
+ const data = await ctx.database.get("toram_todo", {});
680
681
  if (!data) return;
681
682
  this._todos.clear();
682
683
  data.forEach((item) => {
@@ -689,12 +690,12 @@ var _BotTodoMgr = class _BotTodoMgr {
689
690
  saveTodos() {
690
691
  const data = [];
691
692
  this._todos.forEach((list) => data.push(...list));
692
- JsonMgr.Inst().saveJson(this.jsonName, data);
693
+ this.ctx.database.upsert("toram_todo", data);
693
694
  }
694
695
  // 新增一条 todo,返回 id
695
696
  addTodo(ts, type, payload) {
696
697
  const id = `${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
697
- const todo = { id, ts, type, payload };
698
+ const todo = { todoId: id, ts, type, payload };
698
699
  const list = this._todos.get(ts) || [];
699
700
  list.push(todo);
700
701
  this._todos.set(ts, list);
@@ -715,7 +716,7 @@ var _BotTodoMgr = class _BotTodoMgr {
715
716
  removeTodo(ts, id) {
716
717
  const list = this._todos.get(ts);
717
718
  if (!list) return;
718
- const next = list.filter((x) => x.id !== id);
719
+ const next = list.filter((x) => x.todoId !== id);
719
720
  if (next.length > 0) this._todos.set(ts, next);
720
721
  else this._todos.delete(ts);
721
722
  this.saveTodos();
@@ -868,7 +869,7 @@ async function apply(ctx, config) {
868
869
  });
869
870
  ctx.model.extend("toram_todo", {
870
871
  // 各字段的类型声明
871
- id: "string",
872
+ todoId: "string",
872
873
  ts: "double",
873
874
  type: "string",
874
875
  payload: "json"
@@ -880,7 +881,7 @@ async function apply(ctx, config) {
880
881
  TalkMgr.Inst().setTalks();
881
882
  await UserMgr.Inst().setUsers(ctx);
882
883
  MonsterMgr.Inst().setMonsters();
883
- BotTodoMgr.Inst().setTodos();
884
+ BotTodoMgr.Inst().setTodos(ctx);
884
885
  registerBotTodoHandlers();
885
886
  BotTodoMgr.Inst().start();
886
887
  scheduleMonthlyCardReminders(config.groupId, [
@@ -1,5 +1,6 @@
1
+ import { Context } from "koishi";
1
2
  export interface BotTodoItem {
2
- id: string;
3
+ todoId: string;
3
4
  ts: number;
4
5
  type: string;
5
6
  payload?: any;
@@ -12,13 +13,13 @@ export interface BotTodoItem {
12
13
  export declare class BotTodoMgr {
13
14
  private static instance;
14
15
  static Inst(): BotTodoMgr;
15
- private readonly jsonName;
16
+ private ctx;
16
17
  private _todos;
17
18
  private _handlers;
18
19
  private _timer;
19
20
  private _nextTs;
20
21
  private _started;
21
- setTodos(): void;
22
+ setTodos(ctx: Context): Promise<void>;
22
23
  private saveTodos;
23
24
  addTodo(ts: number, type: string, payload?: any): string;
24
25
  getTodosAt(ts: number): BotTodoItem[];
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.3",
4
+ "version": "4.2.0-test.5",
5
5
  "contributors": [
6
6
  "青灯 <1874053520@qq.com>"
7
7
  ],