koishi-plugin-toram 4.2.1-test.1 → 4.2.1
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
|
@@ -178,7 +178,7 @@ var JsonMgr = _JsonMgr;
|
|
|
178
178
|
|
|
179
179
|
// src/script/botFunction/monthlyCardReminder.ts
|
|
180
180
|
var MONTHLY_CARD_REMINDER_TYPE = "monthly-card-reminder";
|
|
181
|
-
function scheduleMonthlyCardReminders(groupId, hours) {
|
|
181
|
+
async function scheduleMonthlyCardReminders(groupId, hours) {
|
|
182
182
|
const now = /* @__PURE__ */ new Date();
|
|
183
183
|
for (let i = 0; i < hours.length; i++) {
|
|
184
184
|
const hour = hours[i];
|
|
@@ -190,7 +190,7 @@ function scheduleMonthlyCardReminders(groupId, hours) {
|
|
|
190
190
|
(x) => x.type === MONTHLY_CARD_REMINDER_TYPE && x.payload?.groupId === groupId && x.payload?.timeIndex === i
|
|
191
191
|
);
|
|
192
192
|
if (!exists) {
|
|
193
|
-
BotTodoMgr.Inst().addTodo(ts, MONTHLY_CARD_REMINDER_TYPE, { groupId, timeIndex: i });
|
|
193
|
+
await BotTodoMgr.Inst().addTodo(ts, MONTHLY_CARD_REMINDER_TYPE, { groupId, timeIndex: i });
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
}
|
|
@@ -712,22 +712,22 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
712
712
|
return list.map((x) => ({ ...x }));
|
|
713
713
|
}
|
|
714
714
|
// 删除某个时间戳下的指定 todo
|
|
715
|
-
removeTodo(ts, id) {
|
|
715
|
+
async removeTodo(ts, id) {
|
|
716
716
|
const list = this._todos.get(ts);
|
|
717
717
|
if (!list) return;
|
|
718
718
|
const next = list.filter((x) => x.id !== id);
|
|
719
719
|
if (next.length > 0) this._todos.set(ts, next);
|
|
720
720
|
else this._todos.delete(ts);
|
|
721
|
-
this.saveTodos();
|
|
721
|
+
await this.saveTodos();
|
|
722
722
|
}
|
|
723
723
|
// 删除某个时间戳下的所有 todo
|
|
724
|
-
removeTodosAt(ts) {
|
|
724
|
+
async removeTodosAt(ts) {
|
|
725
725
|
if (!this._todos.has(ts)) return;
|
|
726
726
|
this._todos.delete(ts);
|
|
727
|
-
this.saveTodos();
|
|
727
|
+
await this.saveTodos();
|
|
728
728
|
}
|
|
729
729
|
// 取出并删除“到期”的 todo 列表(ts <= now)
|
|
730
|
-
popDueTodos(now) {
|
|
730
|
+
async popDueTodos(now) {
|
|
731
731
|
const result = [];
|
|
732
732
|
const keys = Array.from(this._todos.keys()).filter((ts) => ts <= now).sort((a, b) => a - b);
|
|
733
733
|
keys.forEach((ts) => {
|
|
@@ -735,7 +735,7 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
735
735
|
if (list && list.length) result.push(...list);
|
|
736
736
|
this._todos.delete(ts);
|
|
737
737
|
});
|
|
738
|
-
if (keys.length > 0) this.saveTodos();
|
|
738
|
+
if (keys.length > 0) await this.saveTodos();
|
|
739
739
|
return result;
|
|
740
740
|
}
|
|
741
741
|
// 下一个最近的时间戳(若不存在返回 undefined)
|
|
@@ -763,10 +763,10 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
763
763
|
this._nextTs = void 0;
|
|
764
764
|
}
|
|
765
765
|
// 立即重新计算下一个调度点
|
|
766
|
-
scheduleNext() {
|
|
766
|
+
async scheduleNext() {
|
|
767
767
|
if (!this._started) return;
|
|
768
768
|
try {
|
|
769
|
-
const dropped = this.popDueTodos(Date.now());
|
|
769
|
+
const dropped = await this.popDueTodos(Date.now());
|
|
770
770
|
if (dropped.length) {
|
|
771
771
|
console.warn("BotTodoMgr 清理过期任务数量: ", dropped.length);
|
|
772
772
|
}
|
|
@@ -796,7 +796,7 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
796
796
|
const list = this._todos.get(scheduledTs) || [];
|
|
797
797
|
if (list.length) {
|
|
798
798
|
this._todos.delete(scheduledTs);
|
|
799
|
-
this.saveTodos();
|
|
799
|
+
await this.saveTodos();
|
|
800
800
|
await this.executeBatch(list);
|
|
801
801
|
}
|
|
802
802
|
} catch (e) {
|
|
@@ -23,14 +23,14 @@ export declare class BotTodoMgr {
|
|
|
23
23
|
private saveTodos;
|
|
24
24
|
addTodo(ts: number, type: string, payload?: any): Promise<string>;
|
|
25
25
|
getTodosAt(ts: number): BotTodoItem[];
|
|
26
|
-
removeTodo(ts: number, id: string): void
|
|
27
|
-
removeTodosAt(ts: number): void
|
|
28
|
-
popDueTodos(now: number): BotTodoItem[]
|
|
26
|
+
removeTodo(ts: number, id: string): Promise<void>;
|
|
27
|
+
removeTodosAt(ts: number): Promise<void>;
|
|
28
|
+
popDueTodos(now: number): Promise<BotTodoItem[]>;
|
|
29
29
|
getNextTimestamp(): number | undefined;
|
|
30
30
|
on(type: string, handler: (item: BotTodoItem) => any | Promise<any>): void;
|
|
31
31
|
start(): void;
|
|
32
32
|
stop(): void;
|
|
33
|
-
scheduleNext(): void
|
|
33
|
+
scheduleNext(): Promise<void>;
|
|
34
34
|
private internalPlanNext;
|
|
35
35
|
private executeBatch;
|
|
36
36
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BotTodoItem } from "../BotTodoMgr";
|
|
2
2
|
export declare const MONTHLY_CARD_REMINDER_TYPE = "monthly-card-reminder";
|
|
3
|
-
export declare function scheduleMonthlyCardReminders(groupId: string, hours: number[]): void
|
|
3
|
+
export declare function scheduleMonthlyCardReminders(groupId: string, hours: number[]): Promise<void>;
|
|
4
4
|
export declare function executeMonthlyCardReminder(item: BotTodoItem): void;
|