koishi-plugin-ets2-tools-tmp 1.1.4 → 1.2.0

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 +64 -10
  2. 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
  }
@@ -198,9 +204,6 @@ class ActivityService {
198
204
  return `检查完成!\n车队平台今日活动: ${this.todayActivities.length} 个\nTMP今日参与活动: ${this.todayTMPEvents.length} 个`;
199
205
  });
200
206
 
201
- this.ctx.command("活动DEBUG", "查看插件调试信息")
202
- .action(() => this.getDebugInfo());
203
-
204
207
  this.ctx.command("重置数据", "手动重置今日活动数据")
205
208
  .action(() => {
206
209
  this.logger.debug("手动执行数据重置命令");
@@ -222,6 +225,7 @@ class ActivityService {
222
225
  `• TMP活动: ${this.todayTMPEvents.length} 个\n` +
223
226
  `• 已发送提醒: ${this.sentReminders.size} 个\n` +
224
227
  ` - 活动开始提醒: ${startRemindersSent} 个\n` +
228
+ `• 无活动通知: ${this.sentNoActivityNotification ? "已发送" : "未发送"}\n` +
225
229
  `• 活跃定时器: ${this.timers.length} 个\n` +
226
230
  `• 调试模式: ${this.cfg.debugMode ? "✅ 开启" : "❌ 关闭"}\n` +
227
231
  `• 日志选项: API=${this.cfg.logApiResponses ? "✅" : "❌"}, 定时=${this.cfg.logTimingDetails ? "✅" : "❌"}, 匹配=${this.cfg.logActivityMatching ? "✅" : "❌"}, 消息=${this.cfg.logMessageSending ? "✅" : "❌"}`;
@@ -252,20 +256,29 @@ class ActivityService {
252
256
 
253
257
  this.cfg.adminCheckTimes.forEach((timeStr, index) => {
254
258
  const [hours, minutes] = timeStr.split(":").map(Number);
255
- this.setupTimer(hours, minutes, () => {
259
+ this.setupTimer(hours, minutes, async () => {
256
260
  this.logger.timing(`执行定时检查任务 #${index + 1} (${timeStr})`);
257
- this.updateActivityData();
261
+ await this.updateActivityData();
262
+ await this.checkActivityStatusChange();
258
263
  }, `检查定时器 #${index + 1}: ${timeStr}`);
259
264
  });
260
265
 
261
266
  this.cfg.adminSendTimes.forEach((timeStr, index) => {
262
267
  const [hours, minutes] = timeStr.split(":").map(Number);
263
- this.setupTimer(hours, minutes, () => {
268
+ this.setupTimer(hours, minutes, async () => {
264
269
  this.logger.timing(`执行定时发送任务 #${index + 1} (${timeStr})`);
265
- this.checkAndSendProfileReminders();
270
+ await this.checkAndSendProfileReminders();
266
271
  }, `发送定时器 #${index + 1}: ${timeStr}`);
267
272
  });
268
273
 
274
+ if (this.cfg.adminNoActivityNotification) {
275
+ const [noActivityHours, noActivityMinutes] = this.cfg.adminNoActivityTime.split(":").map(Number);
276
+ this.setupTimer(noActivityHours, noActivityMinutes, () => {
277
+ this.logger.timing(`执行今日无活动通知任务 (${this.cfg.adminNoActivityTime})`);
278
+ this.checkAndSendNoActivityNotification();
279
+ }, `无活动通知定时器: ${this.cfg.adminNoActivityTime}`);
280
+ }
281
+
269
282
  const minuteTimer = setInterval(async () => {
270
283
  await this.checkAndSendActivityReminders();
271
284
  }, koishi_1.Time.minute);
@@ -312,15 +325,17 @@ class ActivityService {
312
325
  const previousActivityCount = this.todayActivities.length;
313
326
  const previousTMPCount = this.todayTMPEvents.length;
314
327
  const previousReminderCount = this.sentReminders.size;
328
+ const previousNoActivityNotification = this.sentNoActivityNotification;
315
329
 
316
330
  this.logger.info(`[数据重置] 开始重置数据,本地时间: ${localTime}, 本地日期: ${localDate}, UTC日期: ${utcDate}`);
317
- this.logger.info(`[数据重置] 重置前数据: 活动${previousActivityCount}个, TMP${previousTMPCount}个, 提醒${previousReminderCount}个`);
331
+ this.logger.info(`[数据重置] 重置前数据: 活动${previousActivityCount}个, TMP${previousTMPCount}个, 提醒${previousReminderCount}个, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}`);
318
332
 
319
333
  this.todayActivities = [];
320
334
  this.todayTMPEvents = [];
321
335
  this.sentReminders.clear();
336
+ this.sentNoActivityNotification = false;
322
337
 
323
- this.logger.info(`[数据重置] 每日数据已重置: 活动${previousActivityCount}→0, TMP${previousTMPCount}→0, 提醒${previousReminderCount}→0`);
338
+ this.logger.info(`[数据重置] 每日数据已重置: 活动${previousActivityCount}→0, TMP${previousTMPCount}→0, 提醒${previousReminderCount}→0, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}→未发送`);
324
339
 
325
340
  this.updateActivityData().then(() => {
326
341
  this.logger.info(`[数据重置] 重置后数据更新完成: 活动${this.todayActivities.length}个, TMP${this.todayTMPEvents.length}个`);
@@ -457,6 +472,8 @@ class ActivityService {
457
472
  }
458
473
 
459
474
  async checkAndSendProfileReminders() {
475
+ await this.updateActivityData();
476
+
460
477
  if (this.todayActivities.length === 0) {
461
478
  this.logger.debug("今日没有活动,跳过档位检查");
462
479
  return;
@@ -481,6 +498,43 @@ class ActivityService {
481
498
  }
482
499
  }
483
500
 
501
+ async checkAndSendNoActivityNotification(manualTest = false) {
502
+ if (!manualTest && this.sentNoActivityNotification) {
503
+ this.logger.debug("今日已发送过无活动通知,跳过");
504
+ return;
505
+ }
506
+
507
+ if (this.todayActivities.length > 0 || this.todayTMPEvents.length > 0) {
508
+ this.logger.debug(`今日有活动(车队平台: ${this.todayActivities.length}个, TMP: ${this.todayTMPEvents.length}个),不发送无活动通知`);
509
+ return;
510
+ }
511
+
512
+ this.logger.info(`${manualTest ? "手动测试" : "自动"}今日无活动,发送通知到管理群`);
513
+
514
+ for (const groupId of this.cfg.adminGroups) {
515
+ try {
516
+ await this.sendToGroup(groupId, this.cfg.adminNoActivityMessage, "管理群组");
517
+ this.logger.message(`已发送无活动通知到管理群组 ${groupId}`);
518
+ } catch (error) {
519
+ this.logger.error(`发送无活动通知到管理群组 ${groupId} 失败:`, error.message);
520
+ }
521
+ }
522
+
523
+ if (!manualTest) {
524
+ this.sentNoActivityNotification = true;
525
+ this.logger.debug("已标记今日无活动通知为已发送");
526
+ }
527
+ }
528
+
529
+ async checkActivityStatusChange() {
530
+ await this.updateActivityData();
531
+ if (this.sentNoActivityNotification && (this.todayActivities.length > 0 || this.todayTMPEvents.length > 0)) {
532
+ this.logger.info(`检测到活动状态变化:之前无活动,现在有活动(车队平台: ${this.todayActivities.length}个, TMP: ${this.todayTMPEvents.length}个)`);
533
+ this.sentNoActivityNotification = false;
534
+ await this.checkAndSendProfileReminders();
535
+ }
536
+ }
537
+
484
538
  async checkAndSendActivityReminders() {
485
539
  const now = new Date();
486
540
  const today = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
@@ -648,7 +702,7 @@ class ActivityService {
648
702
  });
649
703
 
650
704
  if (availableBots.length === 0) {
651
- throw new Error(`没有可用的聊天平台适配器(当前不支持邮件/电报/Discord/qq官机/微信公众号)`);
705
+ throw new Error(`没有可用的聊天平台适配器(当前不支持邮件/电报/Discord/QQ/微信公众号)`);
652
706
  }
653
707
 
654
708
  let lastError = null;
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.4",
4
+ "version": "1.2.0",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"