koishi-plugin-toram 4.2.1-test.1 → 4.2.2
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
|
}
|
|
@@ -241,6 +241,53 @@ function executeAllMemberReminder(item) {
|
|
|
241
241
|
}
|
|
242
242
|
__name(executeAllMemberReminder, "executeAllMemberReminder");
|
|
243
243
|
|
|
244
|
+
// src/script/botFunction/monthlyCardFinalReminder.ts
|
|
245
|
+
var MONTHLY_CARD_FINAL_REMINDER_TYPE = "monthly-card-final-reminder";
|
|
246
|
+
async function scheduleMonthlyCardFinalReminder(groupId) {
|
|
247
|
+
const now = /* @__PURE__ */ new Date();
|
|
248
|
+
const next = new Date(now);
|
|
249
|
+
next.setHours(23, 30, 0, 0);
|
|
250
|
+
if (next.getTime() <= now.getTime()) next.setDate(next.getDate() + 1);
|
|
251
|
+
const ts = next.getTime();
|
|
252
|
+
const exists = (BotTodoMgr.Inst().getTodosAt(ts) || []).some(
|
|
253
|
+
(x) => x.type === MONTHLY_CARD_FINAL_REMINDER_TYPE && x.payload?.groupId === groupId
|
|
254
|
+
);
|
|
255
|
+
if (!exists) {
|
|
256
|
+
await BotTodoMgr.Inst().addTodo(ts, MONTHLY_CARD_FINAL_REMINDER_TYPE, { groupId });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
__name(scheduleMonthlyCardFinalReminder, "scheduleMonthlyCardFinalReminder");
|
|
260
|
+
function executeMonthlyCardFinalReminder(item) {
|
|
261
|
+
const payload = item.payload || {};
|
|
262
|
+
const groupId = payload.groupId;
|
|
263
|
+
if (!groupId) return;
|
|
264
|
+
const atUsers = genMonthlyCardFinalReminderUsers();
|
|
265
|
+
if (atUsers) {
|
|
266
|
+
TalkMgr.Inst().send(groupId, "月卡最后提醒", { atUsers });
|
|
267
|
+
}
|
|
268
|
+
const next = new Date(item.ts + 24 * 60 * 60 * 1e3);
|
|
269
|
+
next.setHours(23, 30, 0, 0);
|
|
270
|
+
const nextTs = next.getTime();
|
|
271
|
+
const exists = (BotTodoMgr.Inst().getTodosAt(nextTs) || []).some(
|
|
272
|
+
(x) => x.type === MONTHLY_CARD_FINAL_REMINDER_TYPE && x.payload?.groupId === groupId
|
|
273
|
+
);
|
|
274
|
+
if (!exists) {
|
|
275
|
+
BotTodoMgr.Inst().addTodo(nextTs, MONTHLY_CARD_FINAL_REMINDER_TYPE, { groupId });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
__name(executeMonthlyCardFinalReminder, "executeMonthlyCardFinalReminder");
|
|
279
|
+
function genMonthlyCardFinalReminderUsers() {
|
|
280
|
+
const users = UserMgr.Inst().getAllMonthlyCardRemindUsers();
|
|
281
|
+
if (users.length === 0) return;
|
|
282
|
+
const now = /* @__PURE__ */ new Date();
|
|
283
|
+
const todayStr = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
|
|
284
|
+
const notConfirmed = users.filter((user) => user.lastGetMonthlyCardDate !== todayStr);
|
|
285
|
+
if (notConfirmed.length === 0) return;
|
|
286
|
+
const atUsers = notConfirmed.map((user) => `<at id="${user.qq}"/>`).join(" ");
|
|
287
|
+
return atUsers;
|
|
288
|
+
}
|
|
289
|
+
__name(genMonthlyCardFinalReminderUsers, "genMonthlyCardFinalReminderUsers");
|
|
290
|
+
|
|
244
291
|
// src/script/command/allMemberRemindCommand.ts
|
|
245
292
|
function allMemberRemind(event, args) {
|
|
246
293
|
const qq = event.session.event.user.id;
|
|
@@ -712,22 +759,22 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
712
759
|
return list.map((x) => ({ ...x }));
|
|
713
760
|
}
|
|
714
761
|
// 删除某个时间戳下的指定 todo
|
|
715
|
-
removeTodo(ts, id) {
|
|
762
|
+
async removeTodo(ts, id) {
|
|
716
763
|
const list = this._todos.get(ts);
|
|
717
764
|
if (!list) return;
|
|
718
765
|
const next = list.filter((x) => x.id !== id);
|
|
719
766
|
if (next.length > 0) this._todos.set(ts, next);
|
|
720
767
|
else this._todos.delete(ts);
|
|
721
|
-
this.saveTodos();
|
|
768
|
+
await this.saveTodos();
|
|
722
769
|
}
|
|
723
770
|
// 删除某个时间戳下的所有 todo
|
|
724
|
-
removeTodosAt(ts) {
|
|
771
|
+
async removeTodosAt(ts) {
|
|
725
772
|
if (!this._todos.has(ts)) return;
|
|
726
773
|
this._todos.delete(ts);
|
|
727
|
-
this.saveTodos();
|
|
774
|
+
await this.saveTodos();
|
|
728
775
|
}
|
|
729
776
|
// 取出并删除“到期”的 todo 列表(ts <= now)
|
|
730
|
-
popDueTodos(now) {
|
|
777
|
+
async popDueTodos(now) {
|
|
731
778
|
const result = [];
|
|
732
779
|
const keys = Array.from(this._todos.keys()).filter((ts) => ts <= now).sort((a, b) => a - b);
|
|
733
780
|
keys.forEach((ts) => {
|
|
@@ -735,7 +782,7 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
735
782
|
if (list && list.length) result.push(...list);
|
|
736
783
|
this._todos.delete(ts);
|
|
737
784
|
});
|
|
738
|
-
if (keys.length > 0) this.saveTodos();
|
|
785
|
+
if (keys.length > 0) await this.saveTodos();
|
|
739
786
|
return result;
|
|
740
787
|
}
|
|
741
788
|
// 下一个最近的时间戳(若不存在返回 undefined)
|
|
@@ -763,10 +810,10 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
763
810
|
this._nextTs = void 0;
|
|
764
811
|
}
|
|
765
812
|
// 立即重新计算下一个调度点
|
|
766
|
-
scheduleNext() {
|
|
813
|
+
async scheduleNext() {
|
|
767
814
|
if (!this._started) return;
|
|
768
815
|
try {
|
|
769
|
-
const dropped = this.popDueTodos(Date.now());
|
|
816
|
+
const dropped = await this.popDueTodos(Date.now());
|
|
770
817
|
if (dropped.length) {
|
|
771
818
|
console.warn("BotTodoMgr 清理过期任务数量: ", dropped.length);
|
|
772
819
|
}
|
|
@@ -796,7 +843,7 @@ var _BotTodoMgr = class _BotTodoMgr {
|
|
|
796
843
|
const list = this._todos.get(scheduledTs) || [];
|
|
797
844
|
if (list.length) {
|
|
798
845
|
this._todos.delete(scheduledTs);
|
|
799
|
-
this.saveTodos();
|
|
846
|
+
await this.saveTodos();
|
|
800
847
|
await this.executeBatch(list);
|
|
801
848
|
}
|
|
802
849
|
} catch (e) {
|
|
@@ -899,6 +946,7 @@ async function apply(ctx, config) {
|
|
|
899
946
|
config.monthlyCardReminder_eveningTime,
|
|
900
947
|
config.monthlyCardReminder_latenightTime
|
|
901
948
|
]);
|
|
949
|
+
scheduleMonthlyCardFinalReminder(config.groupId);
|
|
902
950
|
ctx.on("notice", (session) => {
|
|
903
951
|
if (config.sendDialog) logger.info(session);
|
|
904
952
|
const event = newEvent(ctx, session, config, logger);
|
|
@@ -940,11 +988,19 @@ async function apply(ctx, config) {
|
|
|
940
988
|
const event = newEvent(ctx, session, config, logger);
|
|
941
989
|
allMemberRemind(event, args);
|
|
942
990
|
});
|
|
991
|
+
ctx.command("我领月卡啦").action(async ({ session }, ...args) => {
|
|
992
|
+
const event = newEvent(ctx, session, config, logger);
|
|
993
|
+
const result = confirmMonthlyCardGet(event);
|
|
994
|
+
if (result.code === 1001 /* 通过 */) {
|
|
995
|
+
TalkMgr.Inst().reply(event, "月卡确认领取");
|
|
996
|
+
}
|
|
997
|
+
});
|
|
943
998
|
}
|
|
944
999
|
__name(apply, "apply");
|
|
945
1000
|
function registerBotTodoHandlers() {
|
|
946
1001
|
BotTodoMgr.Inst().on(ALL_MEMBER_REMINDER_TYPE, executeAllMemberReminder);
|
|
947
1002
|
BotTodoMgr.Inst().on(MONTHLY_CARD_REMINDER_TYPE, executeMonthlyCardReminder);
|
|
1003
|
+
BotTodoMgr.Inst().on(MONTHLY_CARD_FINAL_REMINDER_TYPE, executeMonthlyCardFinalReminder);
|
|
948
1004
|
}
|
|
949
1005
|
__name(registerBotTodoHandlers, "registerBotTodoHandlers");
|
|
950
1006
|
function newEvent(ctx, session, config, logger) {
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BotTodoItem } from "../BotTodoMgr";
|
|
2
|
+
export declare const MONTHLY_CARD_FINAL_REMINDER_TYPE = "monthly-card-final-reminder";
|
|
3
|
+
export declare function scheduleMonthlyCardFinalReminder(groupId: string): Promise<void>;
|
|
4
|
+
export declare function executeMonthlyCardFinalReminder(item: BotTodoItem): void;
|
|
@@ -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;
|