koishi-plugin-toram 4.2.0-test.3 → 4.2.0-test.4
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 +6 -5
- package/lib/script/BotTodoMgr.d.ts +3 -2
- package/package.json +1 -1
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.
|
|
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
|
-
|
|
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,7 +690,7 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
689
690
|
saveTodos() {
|
|
690
691
|
const data = [];
|
|
691
692
|
this._todos.forEach((list) => data.push(...list));
|
|
692
|
-
|
|
693
|
+
this.ctx.database.upsert("toram_todo", data);
|
|
693
694
|
}
|
|
694
695
|
// 新增一条 todo,返回 id
|
|
695
696
|
addTodo(ts, type, payload) {
|
|
@@ -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,3 +1,4 @@
|
|
|
1
|
+
import { Context } from "koishi";
|
|
1
2
|
export interface BotTodoItem {
|
|
2
3
|
id: string;
|
|
3
4
|
ts: number;
|
|
@@ -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
|
|
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[];
|