koishi-plugin-toram 4.1.2 → 4.2.0-test.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.d.ts +4 -0
- package/lib/index.js +27 -19
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { Context, Logger, Schema, Session } from 'koishi';
|
|
|
2
2
|
export declare const name = "toram";
|
|
3
3
|
export declare const inject: string[];
|
|
4
4
|
declare module 'koishi' {
|
|
5
|
+
interface Events {
|
|
6
|
+
'notice.notify'(...args: any[]): void;
|
|
7
|
+
}
|
|
5
8
|
}
|
|
6
9
|
export interface Config {
|
|
7
10
|
qq: string;
|
|
@@ -17,6 +20,7 @@ export interface Config {
|
|
|
17
20
|
monthlyCardReminder_afternoonTime: number;
|
|
18
21
|
monthlyCardReminder_eveningTime: number;
|
|
19
22
|
monthlyCardReminder_latenightTime: number;
|
|
23
|
+
sendDialog: boolean;
|
|
20
24
|
}
|
|
21
25
|
export declare const Config: Schema<Config>;
|
|
22
26
|
export interface SessionEvent {
|
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");
|
|
@@ -319,6 +319,14 @@ function checkArgs(args, config) {
|
|
|
319
319
|
if (date.getFullYear() !== y || date.getMonth() !== m - 1 || date.getDate() !== d) return null;
|
|
320
320
|
return { date, yearProvided };
|
|
321
321
|
}, "parseSingleDay");
|
|
322
|
+
const timeStr = timePointStr.trim().replace(/:/g, ":");
|
|
323
|
+
const tm = timeStr.match(/^(\d{1,2}):(\d{1,2})$/);
|
|
324
|
+
if (!tm) return new Result(3002 /* 时间不正确 */);
|
|
325
|
+
const hour = Number(tm[1]);
|
|
326
|
+
const minute = Number(tm[2]);
|
|
327
|
+
if (!Number.isInteger(hour) || !Number.isInteger(minute) || hour < 0 || hour > 23 || minute < 0 || minute > 59) {
|
|
328
|
+
return new Result(3002 /* 时间不正确 */);
|
|
329
|
+
}
|
|
322
330
|
const periodParts = timePeriod.split("-").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
323
331
|
if (periodParts.length < 1 || periodParts.length > 2) {
|
|
324
332
|
return new Result(3002 /* 时间不正确 */);
|
|
@@ -335,13 +343,13 @@ function checkArgs(args, config) {
|
|
|
335
343
|
endDate = new Date(endDate.getFullYear() + 1, endDate.getMonth(), endDate.getDate());
|
|
336
344
|
}
|
|
337
345
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
346
|
+
if (periodParts.length === 1 && !startParsed.yearProvided) {
|
|
347
|
+
const firstDt = new Date(startDate);
|
|
348
|
+
firstDt.setHours(hour, minute, 0, 0);
|
|
349
|
+
if (firstDt.getTime() <= now.getTime()) {
|
|
350
|
+
startDate = new Date(startDate.getFullYear() + 1, startDate.getMonth(), startDate.getDate());
|
|
351
|
+
endDate = startDate;
|
|
352
|
+
}
|
|
345
353
|
}
|
|
346
354
|
if (endDate.getTime() < startDate.getTime()) return new Result(3002 /* 时间不正确 */);
|
|
347
355
|
const timeList = [];
|
|
@@ -351,7 +359,9 @@ function checkArgs(args, config) {
|
|
|
351
359
|
while (cursor.getTime() <= endDate.getTime()) {
|
|
352
360
|
const dt = new Date(cursor);
|
|
353
361
|
dt.setHours(hour, minute, 0, 0);
|
|
354
|
-
|
|
362
|
+
if (dt.getTime() > now.getTime()) {
|
|
363
|
+
timeList.push(dt.getTime());
|
|
364
|
+
}
|
|
355
365
|
cursor.setDate(cursor.getDate() + 1);
|
|
356
366
|
guard++;
|
|
357
367
|
if (guard > maxDays) return new Result(3002 /* 时间不正确 */);
|
|
@@ -816,7 +826,10 @@ var Config = import_koishi.Schema.intersect([
|
|
|
816
826
|
monthlyCardReminder_afternoonTime: import_koishi.Schema.number().description("月卡提醒的下午时间").default(16),
|
|
817
827
|
monthlyCardReminder_eveningTime: import_koishi.Schema.number().description("月卡提醒的晚上时间").default(20),
|
|
818
828
|
monthlyCardReminder_latenightTime: import_koishi.Schema.number().description("月卡提醒的深夜时间").default(23)
|
|
819
|
-
}).description("月卡提醒管理")
|
|
829
|
+
}).description("月卡提醒管理"),
|
|
830
|
+
import_koishi.Schema.object({
|
|
831
|
+
sendDialog: import_koishi.Schema.boolean().description("是否发送日志以调试").default(false)
|
|
832
|
+
}).description("调试相关")
|
|
820
833
|
]);
|
|
821
834
|
async function apply(ctx, config) {
|
|
822
835
|
const logger = ctx.logger("toram");
|
|
@@ -839,7 +852,7 @@ async function apply(ctx, config) {
|
|
|
839
852
|
config.monthlyCardReminder_latenightTime
|
|
840
853
|
]);
|
|
841
854
|
ctx.middleware(async (session, next) => {
|
|
842
|
-
logger.info(session);
|
|
855
|
+
if (config.sendDialog) logger.info(session);
|
|
843
856
|
if (session.event.message.elements.some((e) => e.type === "at" && e.attrs.id === config.qq)) {
|
|
844
857
|
const event = newEvent(ctx, session, config, logger);
|
|
845
858
|
TalkMgr.Inst().reply(event, "被@", {
|
|
@@ -853,6 +866,9 @@ async function apply(ctx, config) {
|
|
|
853
866
|
}
|
|
854
867
|
return next();
|
|
855
868
|
});
|
|
869
|
+
ctx.on("notice.notify", (session) => {
|
|
870
|
+
if (config.sendDialog) logger.info(session);
|
|
871
|
+
});
|
|
856
872
|
ctx.command("升级 <等级数>").action(async ({ session }, ...args) => {
|
|
857
873
|
const event = newEvent(ctx, session, config, logger);
|
|
858
874
|
command_levelUP(event, args);
|
|
@@ -869,14 +885,6 @@ async function apply(ctx, config) {
|
|
|
869
885
|
const event = newEvent(ctx, session, config, logger);
|
|
870
886
|
allMemberRemind(event, args);
|
|
871
887
|
});
|
|
872
|
-
ctx.command("魔导书,测试全员提醒").action(async ({ session }) => {
|
|
873
|
-
if (!config.adminQQList.includes(session.event.user.id)) return;
|
|
874
|
-
const event = newEvent(ctx, session, config, logger);
|
|
875
|
-
const groupId = event.config.groupId;
|
|
876
|
-
const content = "这是一个测试全员提醒的消息";
|
|
877
|
-
const message = genAtAllMessage(content);
|
|
878
|
-
TalkMgr.Inst().send(groupId, "简易回复", { result: message });
|
|
879
|
-
});
|
|
880
888
|
}
|
|
881
889
|
__name(apply, "apply");
|
|
882
890
|
function registerBotTodoHandlers() {
|