koishi-plugin-ets2-tools-tmp 1.1.4 → 1.1.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 +78 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -119,6 +119,11 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
119
119
|
adminProfileUploadedMessage: koishi_1.Schema.string().description("活动档已上传时的消息").default("今日活动档已做/上传"),
|
|
120
120
|
adminProfileNotUploadedMessage: koishi_1.Schema.string().description("活动档未上传时的消息").default("今日活动档还没做,请负责的管理注意!")
|
|
121
121
|
}).description("活动查询 - 管理群消息配置"),
|
|
122
|
+
koishi_1.Schema.object({
|
|
123
|
+
adminNoActivityNotification: koishi_1.Schema.boolean().description("启用今日无活动通知").default(false),
|
|
124
|
+
adminNoActivityTime: koishi_1.Schema.string().description("今日无活动通知发送时间(HH:mm格式)").default("09:00"),
|
|
125
|
+
adminNoActivityMessage: koishi_1.Schema.string().description("今日无活动通知消息").default("今日没活动")
|
|
126
|
+
}).description("活动查询 - 无活动通知配置"),
|
|
122
127
|
koishi_1.Schema.object({
|
|
123
128
|
mainGroups: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("主群群号列表").default([]),
|
|
124
129
|
mainActivityReminderMessage: koishi_1.Schema.string().description("活动提醒消息模板,支持变量:{name}, {server}, {startingPoint}, {terminalPoint}, {distance}, {banner}, {timeLeft}").default("活动 {name} 还有 {timeLeft} 分钟就要开始啦!\n服务器: {server}\n起点: {startingPoint}\n终点: {terminalPoint}\n距离: {distance}KM"),
|
|
@@ -141,6 +146,7 @@ class ActivityService {
|
|
|
141
146
|
this.todayActivities = [];
|
|
142
147
|
this.todayTMPEvents = [];
|
|
143
148
|
this.sentReminders = new Set();
|
|
149
|
+
this.sentNoActivityNotification = false;
|
|
144
150
|
this.timers = [];
|
|
145
151
|
this.logger = this.initLogger();
|
|
146
152
|
}
|
|
@@ -207,6 +213,20 @@ class ActivityService {
|
|
|
207
213
|
this.resetDailyData();
|
|
208
214
|
return "✅ 今日活动数据已重置完成!";
|
|
209
215
|
});
|
|
216
|
+
|
|
217
|
+
this.ctx.command("测试无活动通知", "手动测试发送无活动通知")
|
|
218
|
+
.action(async () => {
|
|
219
|
+
this.logger.debug("手动执行无活动通知测试命令");
|
|
220
|
+
await this.checkAndSendNoActivityNotification(true);
|
|
221
|
+
return "✅ 无活动通知测试完成!";
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
this.ctx.command("检查活动状态变化", "手动检查活动状态变化")
|
|
225
|
+
.action(async () => {
|
|
226
|
+
this.logger.debug("手动执行活动状态变化检查命令");
|
|
227
|
+
await this.checkActivityStatusChange();
|
|
228
|
+
return "✅ 活动状态变化检查完成!";
|
|
229
|
+
});
|
|
210
230
|
}
|
|
211
231
|
|
|
212
232
|
getDebugInfo() {
|
|
@@ -222,6 +242,7 @@ class ActivityService {
|
|
|
222
242
|
`• TMP活动: ${this.todayTMPEvents.length} 个\n` +
|
|
223
243
|
`• 已发送提醒: ${this.sentReminders.size} 个\n` +
|
|
224
244
|
` - 活动开始提醒: ${startRemindersSent} 个\n` +
|
|
245
|
+
`• 无活动通知: ${this.sentNoActivityNotification ? "已发送" : "未发送"}\n` +
|
|
225
246
|
`• 活跃定时器: ${this.timers.length} 个\n` +
|
|
226
247
|
`• 调试模式: ${this.cfg.debugMode ? "✅ 开启" : "❌ 关闭"}\n` +
|
|
227
248
|
`• 日志选项: API=${this.cfg.logApiResponses ? "✅" : "❌"}, 定时=${this.cfg.logTimingDetails ? "✅" : "❌"}, 匹配=${this.cfg.logActivityMatching ? "✅" : "❌"}, 消息=${this.cfg.logMessageSending ? "✅" : "❌"}`;
|
|
@@ -252,20 +273,29 @@ class ActivityService {
|
|
|
252
273
|
|
|
253
274
|
this.cfg.adminCheckTimes.forEach((timeStr, index) => {
|
|
254
275
|
const [hours, minutes] = timeStr.split(":").map(Number);
|
|
255
|
-
this.setupTimer(hours, minutes, () => {
|
|
276
|
+
this.setupTimer(hours, minutes, async () => {
|
|
256
277
|
this.logger.timing(`执行定时检查任务 #${index + 1} (${timeStr})`);
|
|
257
|
-
this.updateActivityData();
|
|
278
|
+
await this.updateActivityData();
|
|
279
|
+
await this.checkActivityStatusChange();
|
|
258
280
|
}, `检查定时器 #${index + 1}: ${timeStr}`);
|
|
259
281
|
});
|
|
260
282
|
|
|
261
283
|
this.cfg.adminSendTimes.forEach((timeStr, index) => {
|
|
262
284
|
const [hours, minutes] = timeStr.split(":").map(Number);
|
|
263
|
-
this.setupTimer(hours, minutes, () => {
|
|
285
|
+
this.setupTimer(hours, minutes, async () => {
|
|
264
286
|
this.logger.timing(`执行定时发送任务 #${index + 1} (${timeStr})`);
|
|
265
|
-
this.checkAndSendProfileReminders();
|
|
287
|
+
await this.checkAndSendProfileReminders();
|
|
266
288
|
}, `发送定时器 #${index + 1}: ${timeStr}`);
|
|
267
289
|
});
|
|
268
290
|
|
|
291
|
+
if (this.cfg.adminNoActivityNotification) {
|
|
292
|
+
const [noActivityHours, noActivityMinutes] = this.cfg.adminNoActivityTime.split(":").map(Number);
|
|
293
|
+
this.setupTimer(noActivityHours, noActivityMinutes, () => {
|
|
294
|
+
this.logger.timing(`执行今日无活动通知任务 (${this.cfg.adminNoActivityTime})`);
|
|
295
|
+
this.checkAndSendNoActivityNotification();
|
|
296
|
+
}, `无活动通知定时器: ${this.cfg.adminNoActivityTime}`);
|
|
297
|
+
}
|
|
298
|
+
|
|
269
299
|
const minuteTimer = setInterval(async () => {
|
|
270
300
|
await this.checkAndSendActivityReminders();
|
|
271
301
|
}, koishi_1.Time.minute);
|
|
@@ -312,15 +342,17 @@ class ActivityService {
|
|
|
312
342
|
const previousActivityCount = this.todayActivities.length;
|
|
313
343
|
const previousTMPCount = this.todayTMPEvents.length;
|
|
314
344
|
const previousReminderCount = this.sentReminders.size;
|
|
345
|
+
const previousNoActivityNotification = this.sentNoActivityNotification;
|
|
315
346
|
|
|
316
347
|
this.logger.info(`[数据重置] 开始重置数据,本地时间: ${localTime}, 本地日期: ${localDate}, UTC日期: ${utcDate}`);
|
|
317
|
-
this.logger.info(`[数据重置] 重置前数据: 活动${previousActivityCount}个, TMP${previousTMPCount}个, 提醒${previousReminderCount}
|
|
348
|
+
this.logger.info(`[数据重置] 重置前数据: 活动${previousActivityCount}个, TMP${previousTMPCount}个, 提醒${previousReminderCount}个, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}`);
|
|
318
349
|
|
|
319
350
|
this.todayActivities = [];
|
|
320
351
|
this.todayTMPEvents = [];
|
|
321
352
|
this.sentReminders.clear();
|
|
353
|
+
this.sentNoActivityNotification = false;
|
|
322
354
|
|
|
323
|
-
this.logger.info(`[数据重置] 每日数据已重置: 活动${previousActivityCount}→0, TMP${previousTMPCount}→0, 提醒${previousReminderCount}→0
|
|
355
|
+
this.logger.info(`[数据重置] 每日数据已重置: 活动${previousActivityCount}→0, TMP${previousTMPCount}→0, 提醒${previousReminderCount}→0, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}→未发送`);
|
|
324
356
|
|
|
325
357
|
this.updateActivityData().then(() => {
|
|
326
358
|
this.logger.info(`[数据重置] 重置后数据更新完成: 活动${this.todayActivities.length}个, TMP${this.todayTMPEvents.length}个`);
|
|
@@ -457,6 +489,8 @@ class ActivityService {
|
|
|
457
489
|
}
|
|
458
490
|
|
|
459
491
|
async checkAndSendProfileReminders() {
|
|
492
|
+
await this.updateActivityData();
|
|
493
|
+
|
|
460
494
|
if (this.todayActivities.length === 0) {
|
|
461
495
|
this.logger.debug("今日没有活动,跳过档位检查");
|
|
462
496
|
return;
|
|
@@ -481,6 +515,43 @@ class ActivityService {
|
|
|
481
515
|
}
|
|
482
516
|
}
|
|
483
517
|
|
|
518
|
+
async checkAndSendNoActivityNotification(manualTest = false) {
|
|
519
|
+
if (!manualTest && this.sentNoActivityNotification) {
|
|
520
|
+
this.logger.debug("今日已发送过无活动通知,跳过");
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (this.todayActivities.length > 0 || this.todayTMPEvents.length > 0) {
|
|
525
|
+
this.logger.debug(`今日有活动(车队平台: ${this.todayActivities.length}个, TMP: ${this.todayTMPEvents.length}个),不发送无活动通知`);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
this.logger.info(`${manualTest ? "手动测试" : "自动"}今日无活动,发送通知到管理群`);
|
|
530
|
+
|
|
531
|
+
for (const groupId of this.cfg.adminGroups) {
|
|
532
|
+
try {
|
|
533
|
+
await this.sendToGroup(groupId, this.cfg.adminNoActivityMessage, "管理群组");
|
|
534
|
+
this.logger.message(`已发送无活动通知到管理群组 ${groupId}`);
|
|
535
|
+
} catch (error) {
|
|
536
|
+
this.logger.error(`发送无活动通知到管理群组 ${groupId} 失败:`, error.message);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (!manualTest) {
|
|
541
|
+
this.sentNoActivityNotification = true;
|
|
542
|
+
this.logger.debug("已标记今日无活动通知为已发送");
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
async checkActivityStatusChange() {
|
|
547
|
+
await this.updateActivityData();
|
|
548
|
+
if (this.sentNoActivityNotification && (this.todayActivities.length > 0 || this.todayTMPEvents.length > 0)) {
|
|
549
|
+
this.logger.info(`检测到活动状态变化:之前无活动,现在有活动(车队平台: ${this.todayActivities.length}个, TMP: ${this.todayTMPEvents.length}个)`);
|
|
550
|
+
this.sentNoActivityNotification = false;
|
|
551
|
+
await this.checkAndSendProfileReminders();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
484
555
|
async checkAndSendActivityReminders() {
|
|
485
556
|
const now = new Date();
|
|
486
557
|
const today = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
|
|
@@ -648,7 +719,7 @@ class ActivityService {
|
|
|
648
719
|
});
|
|
649
720
|
|
|
650
721
|
if (availableBots.length === 0) {
|
|
651
|
-
throw new Error(`没有可用的聊天平台适配器(当前不支持邮件/电报/Discord/
|
|
722
|
+
throw new Error(`没有可用的聊天平台适配器(当前不支持邮件/电报/Discord/QQ/微信公众号)`);
|
|
652
723
|
}
|
|
653
724
|
|
|
654
725
|
let lastError = null;
|