koishi-plugin-ets2-tools-tmp 1.1.2 → 1.1.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 +33 -16
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -228,7 +228,13 @@ class ActivityService {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
setupDailyTasks() {
|
|
231
|
-
|
|
231
|
+
const now = new Date();
|
|
232
|
+
const localTime = now.toLocaleString();
|
|
233
|
+
const localDate = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
|
|
234
|
+
const utcDate = now.toISOString().split("T")[0];
|
|
235
|
+
|
|
236
|
+
this.logger.timing(`开始设置每日定时任务,本地时间: ${localTime}, 本地日期: ${localDate}, UTC日期: ${utcDate}`);
|
|
237
|
+
|
|
232
238
|
const resetHour = 2;
|
|
233
239
|
const resetMinute = 0;
|
|
234
240
|
const resetDelay = this.getNextTime(resetHour, resetMinute);
|
|
@@ -243,6 +249,7 @@ class ActivityService {
|
|
|
243
249
|
}, resetDelay);
|
|
244
250
|
this.timers.push(resetTimer);
|
|
245
251
|
this.logger.timing(`设置数据重置定时器: ${resetHour}:${resetMinute.toString().padStart(2, "0")}, 延迟: ${resetDelay}ms`);
|
|
252
|
+
|
|
246
253
|
this.cfg.adminCheckTimes.forEach((timeStr, index) => {
|
|
247
254
|
const [hours, minutes] = timeStr.split(":").map(Number);
|
|
248
255
|
this.setupTimer(hours, minutes, () => {
|
|
@@ -297,13 +304,24 @@ class ActivityService {
|
|
|
297
304
|
}
|
|
298
305
|
|
|
299
306
|
resetDailyData() {
|
|
307
|
+
const now = new Date();
|
|
308
|
+
const localTime = now.toLocaleString();
|
|
309
|
+
const localDate = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
|
|
310
|
+
const utcDate = now.toISOString().split("T")[0];
|
|
311
|
+
|
|
300
312
|
const previousActivityCount = this.todayActivities.length;
|
|
301
313
|
const previousTMPCount = this.todayTMPEvents.length;
|
|
302
314
|
const previousReminderCount = this.sentReminders.size;
|
|
315
|
+
|
|
316
|
+
this.logger.info(`[数据重置] 开始重置数据,本地时间: ${localTime}, 本地日期: ${localDate}, UTC日期: ${utcDate}`);
|
|
317
|
+
this.logger.info(`[数据重置] 重置前数据: 活动${previousActivityCount}个, TMP${previousTMPCount}个, 提醒${previousReminderCount}个`);
|
|
318
|
+
|
|
303
319
|
this.todayActivities = [];
|
|
304
320
|
this.todayTMPEvents = [];
|
|
305
321
|
this.sentReminders.clear();
|
|
322
|
+
|
|
306
323
|
this.logger.info(`[数据重置] 每日数据已重置: 活动${previousActivityCount}→0, TMP${previousTMPCount}→0, 提醒${previousReminderCount}→0`);
|
|
324
|
+
|
|
307
325
|
this.updateActivityData().then(() => {
|
|
308
326
|
this.logger.info(`[数据重置] 重置后数据更新完成: 活动${this.todayActivities.length}个, TMP${this.todayTMPEvents.length}个`);
|
|
309
327
|
}).catch(error => {
|
|
@@ -350,8 +368,9 @@ class ActivityService {
|
|
|
350
368
|
}
|
|
351
369
|
|
|
352
370
|
if (response.code === 0 && response.data?.list) {
|
|
353
|
-
const
|
|
354
|
-
|
|
371
|
+
const now = new Date();
|
|
372
|
+
const today = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
|
|
373
|
+
this.logger.debug(`[活动更新] 当前本地日期: ${today}, UTC日期: ${new Date().toISOString().split("T")[0]}`);
|
|
355
374
|
|
|
356
375
|
const originalCount = response.data.list.length;
|
|
357
376
|
this.logger.debug(`[活动更新] API返回活动总数: ${originalCount}`);
|
|
@@ -364,7 +383,7 @@ class ActivityService {
|
|
|
364
383
|
const activityDate = activity.startTime?.split(" ")[0];
|
|
365
384
|
const isToday = activityDate === today;
|
|
366
385
|
if (!isToday && this.cfg.debugMode) {
|
|
367
|
-
this.logger.debug(`[活动更新] 跳过非今日活动: ${activity.themeName}, 日期: ${activityDate}`);
|
|
386
|
+
this.logger.debug(`[活动更新] 跳过非今日活动: ${activity.themeName}, 日期: ${activityDate}, 当前日期: ${today}`);
|
|
368
387
|
}
|
|
369
388
|
return isToday;
|
|
370
389
|
});
|
|
@@ -402,8 +421,9 @@ class ActivityService {
|
|
|
402
421
|
this.logger.api(`[TMP活动更新] TMP API响应耗时: ${duration}ms, 错误状态: ${response.error}`);
|
|
403
422
|
|
|
404
423
|
if (!response.error && Array.isArray(response.response)) {
|
|
405
|
-
const
|
|
406
|
-
|
|
424
|
+
const now = new Date();
|
|
425
|
+
const today = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
|
|
426
|
+
this.logger.debug(`[TMP活动更新] 当前本地日期: ${today}, UTC日期: ${new Date().toISOString().split("T")[0]}`);
|
|
407
427
|
|
|
408
428
|
const originalCount = response.response.length;
|
|
409
429
|
this.logger.debug(`[TMP活动更新] API返回活动总数: ${originalCount}`);
|
|
@@ -417,7 +437,7 @@ class ActivityService {
|
|
|
417
437
|
const eventDate = event.start_at?.split(" ")[0];
|
|
418
438
|
const isToday = eventDate === today;
|
|
419
439
|
if (!isToday && this.cfg.debugMode) {
|
|
420
|
-
this.logger.debug(`[TMP活动更新] 跳过非今日活动: ${event.name}, 日期: ${eventDate}`);
|
|
440
|
+
this.logger.debug(`[TMP活动更新] 跳过非今日活动: ${event.name}, 日期: ${eventDate}, 当前日期: ${today}`);
|
|
421
441
|
}
|
|
422
442
|
return isToday;
|
|
423
443
|
});
|
|
@@ -463,15 +483,16 @@ class ActivityService {
|
|
|
463
483
|
|
|
464
484
|
async checkAndSendActivityReminders() {
|
|
465
485
|
const now = new Date();
|
|
466
|
-
const today = now.
|
|
486
|
+
const today = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
|
|
487
|
+
const todayUTC = now.toISOString().split("T")[0];
|
|
467
488
|
let remindersSent = 0;
|
|
468
|
-
this.logger.debug(`检查 ${this.todayActivities.length}
|
|
489
|
+
this.logger.debug(`检查 ${this.todayActivities.length} 个活动的提醒时间,当前本地日期: ${today}, UTC日期: ${todayUTC}`);
|
|
469
490
|
|
|
470
491
|
for (const activity of this.todayActivities) {
|
|
471
492
|
try {
|
|
472
493
|
const activityDate = activity.startTime?.split(" ")[0];
|
|
473
494
|
if (activityDate !== today) {
|
|
474
|
-
this.logger.debug(`跳过非今日活动 "${activity.themeName}",活动日期: ${activityDate}
|
|
495
|
+
this.logger.debug(`跳过非今日活动 "${activity.themeName}",活动日期: ${activityDate},当前本地日期: ${today}`);
|
|
475
496
|
continue;
|
|
476
497
|
}
|
|
477
498
|
|
|
@@ -486,8 +507,6 @@ class ActivityService {
|
|
|
486
507
|
const minutesLeft = Math.floor(totalSecondsLeft / 60);
|
|
487
508
|
const secondsLeft = totalSecondsLeft % 60;
|
|
488
509
|
this.logger.debug(`活动 "${activity.themeName}" 剩余时间: ${minutesLeft} 分 ${secondsLeft} 秒`);
|
|
489
|
-
|
|
490
|
-
// 活动开始提醒:只在活动开始时间点触发(允许30秒误差)
|
|
491
510
|
if (totalSecondsLeft >= -30 && totalSecondsLeft <= 0) {
|
|
492
511
|
const startReminderKey = `${activity.id}_started`;
|
|
493
512
|
if (!this.sentReminders.has(startReminderKey)) {
|
|
@@ -497,8 +516,6 @@ class ActivityService {
|
|
|
497
516
|
remindersSent++;
|
|
498
517
|
}
|
|
499
518
|
}
|
|
500
|
-
|
|
501
|
-
// 活动前提醒:只在精确时间点触发(允许30秒误差)
|
|
502
519
|
if (totalSecondsLeft < 0) continue;
|
|
503
520
|
for (const reminderTime of this.cfg.mainActivityReminderTimes) {
|
|
504
521
|
const reminderTimeSeconds = reminderTime * 60;
|
|
@@ -626,12 +643,12 @@ class ActivityService {
|
|
|
626
643
|
|
|
627
644
|
async sendToGroup(groupId, message, groupType) {
|
|
628
645
|
const availableBots = this.ctx.bots.filter((bot) => {
|
|
629
|
-
const unsupportedPlatforms = ["mail", "telegram", "discord"];
|
|
646
|
+
const unsupportedPlatforms = ["mail", "telegram", "discord", "qq", "wechat-official"];
|
|
630
647
|
return !unsupportedPlatforms.includes(bot.platform);
|
|
631
648
|
});
|
|
632
649
|
|
|
633
650
|
if (availableBots.length === 0) {
|
|
634
|
-
throw new Error(`没有可用的聊天平台适配器(当前不支持邮件/电报/Discord
|
|
651
|
+
throw new Error(`没有可用的聊天平台适配器(当前不支持邮件/电报/Discord/qq官机/微信公众号)`);
|
|
635
652
|
}
|
|
636
653
|
|
|
637
654
|
let lastError = null;
|