koishi-plugin-ets2-tools-tmp 2.3.3 → 2.4.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.
@@ -117,6 +117,14 @@ class ActivityService {
117
117
  }, `发送定时器 #${index + 1}: ${timeStr}`);
118
118
  });
119
119
 
120
+ this.cfg.admin.autoClockCheckTimes.forEach((timeStr, index) => {
121
+ const [hours, minutes] = timeStr.split(":").map(Number);
122
+ this.setupTimer(hours, minutes, async () => {
123
+ this.logger.timing(`执行自动打卡检查任务 #${index + 1} (${timeStr})`);
124
+ await this.checkAutoClockStatus();
125
+ }, `自动打卡检查定时器 #${index + 1}: ${timeStr}`);
126
+ });
127
+
120
128
  if (this.cfg.noActivity?.enable) {
121
129
  const [noActivityHours, noActivityMinutes] = this.cfg.noActivity.time.split(":").map(Number);
122
130
  this.setupTimer(noActivityHours, noActivityMinutes, () => {
@@ -212,7 +220,7 @@ class ActivityService {
212
220
  this.todayActivities = [];
213
221
 
214
222
  const protocol = this.cfg.api.useHttps ? "https://" : "http://";
215
- const fullUrl = `${protocol}${this.cfg.api.url}/api/activity/info/list?token=${this.cfg.api.token}&page=1&limit=50&themeName=`;
223
+ const fullUrl = `${protocol}${this.cfg.api.url}/api/activity/info/list?token=${this.cfg.api.token}&page=1&limit=100&themeName=`;
216
224
  this.logger.api(`请求车队平台API: ${fullUrl.replace(this.cfg.api.token, "***")}`);
217
225
 
218
226
  const startTime = Date.now();
@@ -560,19 +568,18 @@ class ActivityService {
560
568
  }
561
569
 
562
570
  async sendToGroup(groupId, message, groupType) {
563
- const availableBots = this.ctx.bots.filter((bot) => {
564
- const unsupportedPlatforms = ["mail", "telegram", "discord", "qq", "wechat-official"];
565
- return !unsupportedPlatforms.includes(bot.platform);
571
+ const onebotBots = this.ctx.bots.filter((bot) => {
572
+ return bot.platform === "onebot";
566
573
  });
567
574
 
568
- if (availableBots.length === 0) {
569
- throw new Error(`没有可用的聊天平台适配器(当前不支持邮件/电报/Discord/QQ/微信公众号)`);
575
+ if (onebotBots.length === 0) {
576
+ throw new Error(`请启用onebot适配器以发送${groupType}消息`);
570
577
  }
571
578
 
572
579
  let lastError = null;
573
- this.logger.debug(`尝试通过 ${availableBots.length} 个适配器发送消息到${groupType} ${groupId}`);
580
+ this.logger.debug(`尝试通过 ${onebotBots.length} 个onebot适配器发送消息到${groupType} ${groupId}`);
574
581
 
575
- for (const bot of availableBots) {
582
+ for (const bot of onebotBots) {
576
583
  try {
577
584
  await bot.sendMessage(groupId, message);
578
585
  this.logger.debug(`已通过 ${bot.platform} 适配器发送消息到${groupType} ${groupId}`);
@@ -583,7 +590,101 @@ class ActivityService {
583
590
  }
584
591
  }
585
592
 
586
- throw lastError || new Error(`所有适配器都无法发送消息到${groupType} ${groupId}`);
593
+ throw lastError || new Error(`所有onebot适配器都无法发送消息到${groupType} ${groupId}`);
594
+ }
595
+
596
+ async checkAutoClockStatus() {
597
+ await this.updateActivityData();
598
+
599
+ if (this.todayActivities.length === 0) {
600
+ this.logger.debug("今日没有活动,跳过自动打卡检查");
601
+ return;
602
+ }
603
+
604
+ this.logger.debug(`开始检查 ${this.todayActivities.length} 个活动的自动打卡状态`);
605
+
606
+ const platformVersion = (this.cfg.mainSettings?.platformVersion || "v1").toLowerCase();
607
+
608
+ for (const activity of this.todayActivities) {
609
+ try {
610
+ let autoClockEnabled = false;
611
+
612
+ if (platformVersion === "v1") {
613
+ autoClockEnabled = await this.checkV1AutoClock(activity);
614
+ } else if (platformVersion === "v2") {
615
+ autoClockEnabled = await this.checkV2AutoClock(activity);
616
+ }
617
+
618
+ const message = autoClockEnabled
619
+ ? `今日活动自动打卡已设置`
620
+ : `请注意,今日活动打卡未设置。\n 活动名称: ${activity.themeName || '未知活动'}`;
621
+
622
+ this.logger.message(`自动打卡检查: "${activity.themeName || '未知活动'}" - ${autoClockEnabled ? "已设置" : "未设置"}`);
623
+
624
+ for (const groupId of this.cfg.admin.groups) {
625
+ try {
626
+ await this.sendToGroup(groupId, message, "管理群组");
627
+ this.logger.message(`已发送自动打卡检查到管理群组 ${groupId}: ${activity.themeName || '未知活动'}`);
628
+ } catch (error) {
629
+ this.logger.error(`发送自动打卡检查到管理群组 ${groupId} 失败:`, error.message);
630
+ }
631
+ }
632
+ } catch (error) {
633
+ this.logger.error(`检查活动 "${activity.themeName || '未知活动'}" 自动打卡状态失败:`, error.message);
634
+ }
635
+ }
636
+ }
637
+
638
+ async checkV1AutoClock(activity) {
639
+ try {
640
+ const protocol = this.cfg.api.useHttps ? "https://" : "http://";
641
+ const fullUrl = `${protocol}${this.cfg.api.url}/api/activity/info/info/${activity.id}?token=${this.cfg.api.token}`;
642
+ this.logger.api(`请求V1活动详情API: ${fullUrl.replace(this.cfg.api.token, "***")}`);
643
+
644
+ const response = await this.ctx.http.get(fullUrl, { timeout: 10000 });
645
+ this.logger.api(`V1活动详情API响应:`, response);
646
+
647
+ if (response.code === 0 && response.data) {
648
+ const enableAutoClock = response.data.enableAutoClock;
649
+ this.logger.debug(`活动 "${activity.themeName}" V1自动打卡状态: ${enableAutoClock}`);
650
+ return enableAutoClock === 1;
651
+ } else {
652
+ this.logger.error(`V1活动详情API返回错误: ${response.msg || '未知错误'} (代码: ${response.code || '无'})`);
653
+ return false;
654
+ }
655
+ } catch (error) {
656
+ this.logger.error(`检查V1活动 "${activity.themeName}" 自动打卡状态失败:`, error.message);
657
+ return false;
658
+ }
659
+ }
660
+
661
+ async checkV2AutoClock(activity) {
662
+ try {
663
+ const protocol = this.cfg.api.useHttps ? "https://" : "http://";
664
+ const fullUrl = `${protocol}${this.cfg.api.url}/activity/list?token=${this.cfg.api.token}`;
665
+ this.logger.api(`请求V2活动列表API: ${fullUrl.replace(this.cfg.api.token, "***")}`);
666
+
667
+ const response = await this.ctx.http.get(fullUrl, { timeout: 10000 });
668
+ this.logger.api(`V2活动列表API响应:`, response);
669
+
670
+ if (response.code === 200 && response.data?.rows) {
671
+ const activityDetail = response.data.rows.find(row => row.id === activity.id);
672
+ if (activityDetail) {
673
+ const autoCheckInEnable = activityDetail.autoCheckInEnable;
674
+ this.logger.debug(`活动 "${activity.themeName}" V2自动打卡状态: ${autoCheckInEnable}`);
675
+ return autoCheckInEnable === 1;
676
+ } else {
677
+ this.logger.warn(`在V2活动列表中未找到活动ID: ${activity.id}`);
678
+ return false;
679
+ }
680
+ } else {
681
+ this.logger.error(`V2活动列表API返回错误: ${response.msg || '未知错误'} (代码: ${response.code || '无'})`);
682
+ return false;
683
+ }
684
+ } catch (error) {
685
+ this.logger.error(`检查V2活动 "${activity.themeName}" 自动打卡状态失败:`, error.message);
686
+ return false;
687
+ }
587
688
  }
588
689
 
589
690
  cleanup() {
package/lib/index.js CHANGED
@@ -130,6 +130,7 @@ exports.Config = koishi_1.Schema.intersect([
130
130
  admin: koishi_1.Schema.object({
131
131
  checkTimes: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("活动检查时间(HH:mm格式)").default(["08:00", "12:00", "14:00", "20:00"]),
132
132
  sendTimes: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("信息发送时间(HH:mm格式)").default(["08:05", "12:05", "14:05", "20:05"]),
133
+ autoClockCheckTimes: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("自动打卡检查时间(HH:mm格式)").default(["09:00"]),
133
134
  groups: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("管理群组ID列表").default([])
134
135
  }).description("管理群配置"),
135
136
  dataSource: koishi_1.Schema.object({
@@ -352,7 +353,8 @@ function apply(ctx, cfg) {
352
353
  const activityConfig = {
353
354
  ...cfg.tmpActivityService,
354
355
  debugMode: cfg.debugMode,
355
- debug: cfg.tmpActivityService.debug
356
+ debug: cfg.tmpActivityService.debug,
357
+ mainSettings: cfg.mainSettings?.settings || {}
356
358
  };
357
359
  const activityService = new ActivityService(ctx, activityConfig);
358
360
  activityService.start();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ets2-tools-tmp",
3
3
  "description": "欧卡2 TruckersMP信息查询、车队平台查询及活动提醒",
4
- "version": "2.3.3",
4
+ "version": "2.4.0",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"