koishi-plugin-ets2-tools-tmp 3.3.63 → 3.3.65
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/command/tmpActivityService.js +105 -2
- package/lib/index.js +3 -0
- package/lib/util/constant.js +17 -1
- package/package.json +2 -3
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ActivityService = void 0;
|
|
4
4
|
|
|
5
5
|
const koishi_1 = require("koishi");
|
|
6
|
+
const { LeadRoleCallMessage, LeadRoleCallTime } = require("../util/constant");
|
|
6
7
|
|
|
7
8
|
const v1Methods = require('./tmpActivityService/tmpActivityServiceV1');
|
|
8
9
|
|
|
@@ -13,6 +14,7 @@ class ActivityService {
|
|
|
13
14
|
this.todayActivities = [];
|
|
14
15
|
this.todayTMPEvents = [];
|
|
15
16
|
this.sentReminders = new Set();
|
|
17
|
+
this.sentRoleCalls = new Set();
|
|
16
18
|
this.sentNoActivityNotification = false;
|
|
17
19
|
this.timers = [];
|
|
18
20
|
this.logger = this.initLogger();
|
|
@@ -79,6 +81,21 @@ class ActivityService {
|
|
|
79
81
|
this.resetDailyData();
|
|
80
82
|
return "✅ 今日活动数据已重置完成!";
|
|
81
83
|
});
|
|
84
|
+
|
|
85
|
+
// 仅配置了联运部群号时才注册,方便立即验证效果(定时任务每天 15:00 才触发一次)
|
|
86
|
+
if (this.cfg.leadGroups && this.cfg.leadGroups.length > 0) {
|
|
87
|
+
this.ctx.command("联运接龙", "手动发布今日活动的联运接龙")
|
|
88
|
+
.action(async () => {
|
|
89
|
+
this.logger.debug("手动执行联运接龙命令");
|
|
90
|
+
const sent = await this.checkAndSendLeadRoleCall();
|
|
91
|
+
if (sent.length === 0) {
|
|
92
|
+
return this.todayActivities.length === 0
|
|
93
|
+
? "今日没有活动,无需发布接龙"
|
|
94
|
+
: "今日接龙已发布过了(需要重发请先执行「重置数据」)";
|
|
95
|
+
}
|
|
96
|
+
return `✅ 已发布接龙:${sent.join('、')}`;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
82
99
|
}
|
|
83
100
|
|
|
84
101
|
setupDailyTasks() {
|
|
@@ -145,6 +162,19 @@ class ActivityService {
|
|
|
145
162
|
}, `在线成员检查定时器: ${this.cfg.onlineCheck.time}`);
|
|
146
163
|
}
|
|
147
164
|
|
|
165
|
+
// 联运部接龙:配置了联运群号后,每天定时检查当天活动并发布接龙
|
|
166
|
+
const leadGroups = this.cfg.leadGroups || [];
|
|
167
|
+
if (leadGroups.length > 0) {
|
|
168
|
+
const leadTimeText = `${LeadRoleCallTime.hour}:${LeadRoleCallTime.minute.toString().padStart(2, "0")}`;
|
|
169
|
+
this.setupTimer(LeadRoleCallTime.hour, LeadRoleCallTime.minute, async () => {
|
|
170
|
+
this.logger.timing(`执行联运接龙任务 (${leadTimeText})`);
|
|
171
|
+
await this.checkAndSendLeadRoleCall();
|
|
172
|
+
}, `联运接龙定时器: ${leadTimeText}`);
|
|
173
|
+
this.logger.info(`[联运接龙] 已启用,${leadGroups.length} 个联运群,每天 ${leadTimeText} 检查当天活动并发布接龙`);
|
|
174
|
+
} else {
|
|
175
|
+
this.logger.debug("未配置联运部群号,跳过联运接龙定时器");
|
|
176
|
+
}
|
|
177
|
+
|
|
148
178
|
const minuteTimer = setInterval(async () => {
|
|
149
179
|
await this.checkAndSendActivityReminders();
|
|
150
180
|
}, koishi_1.Time.minute);
|
|
@@ -191,17 +221,19 @@ class ActivityService {
|
|
|
191
221
|
const previousActivityCount = this.todayActivities.length;
|
|
192
222
|
const previousTMPCount = this.todayTMPEvents.length;
|
|
193
223
|
const previousReminderCount = this.sentReminders.size;
|
|
224
|
+
const previousRoleCallCount = this.sentRoleCalls.size;
|
|
194
225
|
const previousNoActivityNotification = this.sentNoActivityNotification;
|
|
195
226
|
|
|
196
227
|
this.logger.info(`[数据重置] 开始重置数据,本地时间: ${localTime}, 本地日期: ${localDate}, UTC日期: ${utcDate}`);
|
|
197
|
-
this.logger.info(`[数据重置] 重置前数据: 活动${previousActivityCount}个, TMP${previousTMPCount}个, 提醒${previousReminderCount}个, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}`);
|
|
228
|
+
this.logger.info(`[数据重置] 重置前数据: 活动${previousActivityCount}个, TMP${previousTMPCount}个, 提醒${previousReminderCount}个, 联运接龙${previousRoleCallCount}个, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}`);
|
|
198
229
|
|
|
199
230
|
this.todayActivities = [];
|
|
200
231
|
this.todayTMPEvents = [];
|
|
201
232
|
this.sentReminders.clear();
|
|
233
|
+
this.sentRoleCalls.clear();
|
|
202
234
|
this.sentNoActivityNotification = false;
|
|
203
235
|
|
|
204
|
-
this.logger.info(`[数据重置] 每日数据已重置: 活动${previousActivityCount}→0, TMP${previousTMPCount}→0, 提醒${previousReminderCount}→0, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}→未发送`);
|
|
236
|
+
this.logger.info(`[数据重置] 每日数据已重置: 活动${previousActivityCount}→0, TMP${previousTMPCount}→0, 提醒${previousReminderCount}→0, 联运接龙${previousRoleCallCount}→0, 无活动通知${previousNoActivityNotification ? "已发送" : "未发送"}→未发送`);
|
|
205
237
|
|
|
206
238
|
this.updateActivityData().then(() => {
|
|
207
239
|
this.logger.info(`[数据重置] 重置后数据更新完成: 活动${this.todayActivities.length}个, TMP${this.todayTMPEvents.length}个`);
|
|
@@ -605,6 +637,76 @@ class ActivityService {
|
|
|
605
637
|
throw lastError || new Error(`所有onebot适配器都无法发送消息到${groupType} ${groupId}`);
|
|
606
638
|
}
|
|
607
639
|
|
|
640
|
+
/**
|
|
641
|
+
* 联运部接龙:当天有活动时,在联运群发布接龙消息。
|
|
642
|
+
* 返回本次实际发布的活动名称数组(未配置群号 / 今日无活动 / 今日已发布时为空数组)。
|
|
643
|
+
*/
|
|
644
|
+
async checkAndSendLeadRoleCall() {
|
|
645
|
+
const groups = this.cfg.leadGroups || [];
|
|
646
|
+
if (groups.length === 0) {
|
|
647
|
+
this.logger.debug("[联运接龙] 未配置联运部群号,跳过");
|
|
648
|
+
return [];
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// 先刷新活动数据,避免依赖上一次定时检查(默认 14:00)的结果
|
|
652
|
+
await this.updateActivityData();
|
|
653
|
+
|
|
654
|
+
if (this.todayActivities.length === 0) {
|
|
655
|
+
this.logger.debug("[联运接龙] 今日没有活动,跳过");
|
|
656
|
+
return [];
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const template = this.cfg.leadCallMessage || LeadRoleCallMessage;
|
|
660
|
+
const now = new Date();
|
|
661
|
+
const dateText = `${now.getMonth() + 1}月${now.getDate()}日`;
|
|
662
|
+
const sent = [];
|
|
663
|
+
|
|
664
|
+
for (const activity of this.todayActivities) {
|
|
665
|
+
const name = activity.themeName || '未知活动';
|
|
666
|
+
const key = `rolecall_${activity.id}`;
|
|
667
|
+
if (this.sentRoleCalls.has(key)) {
|
|
668
|
+
this.logger.debug(`[联运接龙] "${name}" 今日已发布过,跳过`);
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
const text = template
|
|
673
|
+
.replace(/\{date\}/g, dateText)
|
|
674
|
+
.replace(/\{name\}/g, name)
|
|
675
|
+
.replace(/\\n/g, "\n")
|
|
676
|
+
.trim();
|
|
677
|
+
|
|
678
|
+
// 模板以「@全体成员」开头时替换成真实的全体 @(onebot 适配器会转成 [CQ:at,qq=all]);
|
|
679
|
+
// 纯文本的 "@全体成员" 在 QQ 里只是一串字,不会触发全员提醒。
|
|
680
|
+
// 想退回纯文本:把模板开头的「@全体成员」删掉即可。
|
|
681
|
+
const AT_ALL_PREFIX = '@全体成员';
|
|
682
|
+
const payload = text.startsWith(AT_ALL_PREFIX)
|
|
683
|
+
? [koishi_1.h('at', { type: 'all' }), text.slice(AT_ALL_PREFIX.length)]
|
|
684
|
+
: text;
|
|
685
|
+
|
|
686
|
+
let anySuccess = false;
|
|
687
|
+
for (const groupId of groups) {
|
|
688
|
+
try {
|
|
689
|
+
await this.sendToGroup(groupId, payload, "联运群");
|
|
690
|
+
this.logger.message(`[联运接龙] 已发布到联运群 ${groupId}: ${name}`);
|
|
691
|
+
anySuccess = true;
|
|
692
|
+
} catch (error) {
|
|
693
|
+
this.logger.error(`[联运接龙] 发布到联运群 ${groupId} 失败:`, error.message);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// 发送全部失败时不记「已发布」,留待下次触发(手动命令 / 重置数据后)重试
|
|
698
|
+
if (anySuccess) {
|
|
699
|
+
this.sentRoleCalls.add(key);
|
|
700
|
+
sent.push(name);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (sent.length > 0) {
|
|
705
|
+
this.logger.info(`[联运接龙] 本次发布完成:${sent.join('、')}`);
|
|
706
|
+
}
|
|
707
|
+
return sent;
|
|
708
|
+
}
|
|
709
|
+
|
|
608
710
|
async checkAutoClockStatus() {
|
|
609
711
|
await this.updateActivityData();
|
|
610
712
|
|
|
@@ -649,6 +751,7 @@ class ActivityService {
|
|
|
649
751
|
this.todayActivities = [];
|
|
650
752
|
this.todayTMPEvents = [];
|
|
651
753
|
this.sentReminders.clear();
|
|
754
|
+
this.sentRoleCalls.clear();
|
|
652
755
|
this.timers.forEach((timer) => {
|
|
653
756
|
clearTimeout(timer);
|
|
654
757
|
clearInterval(timer);
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const koishi_1 = require("koishi");
|
|
|
7
7
|
const model = require('./database/model');
|
|
8
8
|
const { ServerType } = require('./util/constant');
|
|
9
9
|
const { MileageRankingType } = require('./util/constant');
|
|
10
|
+
const { LeadRoleCallMessage, LeadRoleCallTime } = require('./util/constant');
|
|
10
11
|
|
|
11
12
|
const commands = {
|
|
12
13
|
tmpQuery: require('./command/tmpQuery/tmpQuery'),
|
|
@@ -194,6 +195,8 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
194
195
|
activityStartReminderMessage: koishi_1.Schema.string().description("活动开始提醒消息模板,支持变量:{name}, {server}, {startingPoint}, {terminalPoint}, {distance}, {banner}").default("活动 {name} 现在开始集合啦!\n服务器: {server}\n起点: {startingPoint}\n终点: {terminalPoint}\n距离: {distance}KM\n活动将于20:30分开始!"),
|
|
195
196
|
activityReminderTimes: koishi_1.Schema.array(koishi_1.Schema.number()).role("table").description("活动开始前提醒时间(分钟)").default([60, 30, 15])
|
|
196
197
|
}).description("主群配置"),
|
|
198
|
+
leadGroups: koishi_1.Schema.array(koishi_1.Schema.string()).role("table").description("联运部群号(填写后,当天有活动时会在该群 " + LeadRoleCallTime.hour + ":00 自动发布接龙)").default([]),
|
|
199
|
+
leadCallMessage: koishi_1.Schema.string().description("联运接龙消息模板,支持变量:{date} 日期、{name} 活动名称").default(LeadRoleCallMessage),
|
|
197
200
|
debug: koishi_1.Schema.object({
|
|
198
201
|
debugMode: koishi_1.Schema.boolean().description("启用调试模式").default(false),
|
|
199
202
|
logApiResponses: koishi_1.Schema.boolean().description("记录API响应详情").default(false),
|
package/lib/util/constant.js
CHANGED
|
@@ -32,5 +32,21 @@ module.exports = {
|
|
|
32
32
|
ServerType: {
|
|
33
33
|
ets: 1,
|
|
34
34
|
promods: 2
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* 联运部接龙:每天发布的时间
|
|
38
|
+
*/
|
|
39
|
+
LeadRoleCallTime: { hour: 15, minute: 0 },
|
|
40
|
+
/**
|
|
41
|
+
* 联运部接龙:默认消息模板,支持变量 {date} 日期、{name} 活动名称
|
|
42
|
+
*/
|
|
43
|
+
LeadRoleCallMessage: [
|
|
44
|
+
'@全体成员 {date}{name}接龙',
|
|
45
|
+
'头车:',
|
|
46
|
+
'备头:',
|
|
47
|
+
'中车:',
|
|
48
|
+
'备尾:',
|
|
49
|
+
'尾车:',
|
|
50
|
+
'中途档:'
|
|
51
|
+
].join('\n')
|
|
36
52
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-ets2-tools-tmp",
|
|
3
3
|
"description": "欧卡2 TruckersMP信息查询、车队平台查询及活动提醒",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.65",
|
|
5
5
|
"contributors": [
|
|
6
|
-
"opwop <slhp1013@qq.com>"
|
|
7
|
-
"bot_actions <168329908@qq.com>"
|
|
6
|
+
"opwop <slhp1013@qq.com>"
|
|
8
7
|
],
|
|
9
8
|
"main": "lib/index.js",
|
|
10
9
|
"typings": "lib/index.d.ts",
|