koishi-plugin-ets2-tools-tmp 1.1.1 → 1.1.3

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.
Files changed (2) hide show
  1. package/lib/index.js +39 -17
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -228,7 +228,13 @@ class ActivityService {
228
228
  }
229
229
 
230
230
  setupDailyTasks() {
231
- this.logger.timing("开始设置每日定时任务");
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 today = new Date().toISOString().split("T")[0];
354
- this.logger.debug(`[活动更新] 当前日期: ${today}`);
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 today = new Date().toISOString().split("T")[0];
406
- this.logger.debug(`[TMP活动更新] 当前日期: ${today}`);
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.toISOString().split("T")[0];
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} 个活动的提醒时间,当前日期: ${today}`);
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},当前日期: ${today}`);
495
+ this.logger.debug(`跳过非今日活动 "${activity.themeName}",活动日期: ${activityDate},当前本地日期: ${today}`);
475
496
  continue;
476
497
  }
477
498
 
@@ -482,10 +503,11 @@ class ActivityService {
482
503
  }
483
504
 
484
505
  const timeDiff = activityStartTime.getTime() - now.getTime();
485
- const minutesLeft = Math.floor(timeDiff / (1e3 * 60));
486
- this.logger.debug(`活动 "${activity.themeName}" 剩余时间: ${minutesLeft} 分钟`);
487
-
488
- if (minutesLeft <= 0 && minutesLeft > -1) {
506
+ const totalSecondsLeft = Math.floor(timeDiff / 1000);
507
+ const minutesLeft = Math.floor(totalSecondsLeft / 60);
508
+ const secondsLeft = totalSecondsLeft % 60;
509
+ this.logger.debug(`活动 "${activity.themeName}" 剩余时间: ${minutesLeft} ${secondsLeft} 秒`);
510
+ if (totalSecondsLeft >= -30 && totalSecondsLeft <= 0) {
489
511
  const startReminderKey = `${activity.id}_started`;
490
512
  if (!this.sentReminders.has(startReminderKey)) {
491
513
  this.logger.debug(`触发活动开始提醒: ${activity.themeName}`);
@@ -494,10 +516,10 @@ class ActivityService {
494
516
  remindersSent++;
495
517
  }
496
518
  }
497
-
498
- if (minutesLeft < 0) continue;
519
+ if (totalSecondsLeft < 0) continue;
499
520
  for (const reminderTime of this.cfg.mainActivityReminderTimes) {
500
- if (minutesLeft <= reminderTime && minutesLeft > reminderTime - 1) {
521
+ const reminderTimeSeconds = reminderTime * 60;
522
+ if (totalSecondsLeft <= reminderTimeSeconds && totalSecondsLeft > reminderTimeSeconds - 30) {
501
523
  const reminderKey = `${activity.id}_${reminderTime}`;
502
524
  if (!this.sentReminders.has(reminderKey)) {
503
525
  this.logger.debug(`触发提醒: ${activity.themeName} - ${reminderTime} 分钟前`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ets2-tools-tmp",
3
3
  "description": "欧卡2 TMP在线查询、车队平台查询及活动提醒",
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"