koishi-plugin-ets2-tools-tmp 2.3.2 → 2.3.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.
@@ -6,104 +6,142 @@ const { PromodsIds, ServerType } = require('../util/constant')
6
6
  const evmOpenApi = require('../api/evmOpenApi')
7
7
  const guildBind = require('../database/guildBind')
8
8
 
9
- module.exports = async (ctx, session, serverType, tmpId) => {
10
- if (!ctx.puppeteer) {
11
- return '未启用 puppeteer 服务'
12
- }
9
+ module.exports = async (ctx, session, serverType, tmpId, date) => {
10
+ if (!ctx.puppeteer) {
11
+ return '未启用 puppeteer 服务'
12
+ }
13
13
 
14
- if (tmpId && tmpId.startsWith("<at ")) {
15
- if (tmpId.startsWith('<at ')) {
16
- queryQQ = tmpId.replace('<at ', '');
17
- }
18
- let id = '';
19
- const idStart = queryQQ.indexOf('id="');
20
- if (idStart !== -1) {
21
- const valueStart = idStart + 4;
22
- const valueEnd = queryQQ.indexOf('"', valueStart);
23
- if (valueEnd !== -1) {
24
- id = queryQQ.substring(valueStart, valueEnd);
25
- }
26
- }
27
- queryQQ = id;
28
- let guildBindData = await guildBind.get(ctx.database, session.platform, queryQQ);
29
- if (!guildBindData) {
30
- return `该用户没有绑定玩家编号`;
31
- }
32
- tmpId = guildBindData.tmp_id;
14
+ if (tmpId && tmpId.startsWith("<at ")) {
15
+ if (tmpId.startsWith('<at ')) {
16
+ queryQQ = tmpId.replace('<at ', '');
33
17
  }
34
-
35
- if (tmpId && isNaN(tmpId)) {
36
- return `请输入正确的玩家编号,或绑定玩家编号`
18
+ let id = '';
19
+ const idStart = queryQQ.indexOf('id="');
20
+ if (idStart !== -1) {
21
+ const valueStart = idStart + 4;
22
+ const valueEnd = queryQQ.indexOf('"', valueStart);
23
+ if (valueEnd !== -1) {
24
+ id = queryQQ.substring(valueStart, valueEnd);
25
+ }
37
26
  }
38
-
39
- // 如果没有传入tmpId,尝试从数据库查询绑定信息
40
- if (!tmpId) {
41
- let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId)
42
- if (!guildBindData) {
43
- return `请输入正确的玩家编号,或绑定玩家编号`
44
- }
45
- tmpId = guildBindData.tmp_id
27
+ queryQQ = id;
28
+ let guildBindData = await guildBind.get(ctx.database, session.platform, queryQQ);
29
+ if (!guildBindData) {
30
+ return `该用户没有绑定玩家编号`;
46
31
  }
32
+ tmpId = guildBindData.tmp_id;
33
+ }
47
34
 
48
- // 查询玩家信息
49
- let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId)
50
- if (playerInfo.error && playerInfo.code === 10001) {
51
- return '玩家不存在'
52
- } else if (playerInfo.error) {
53
- return '查询玩家信息失败,请重试'
54
- }
35
+ if (tmpId && isNaN(tmpId)) {
36
+ return `请输入正确的玩家编号,或绑定玩家编号`
37
+ }
55
38
 
56
- // 查询当日历史位置数据
57
- const startTime = dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss');
58
- const endTime = dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss');
59
- let mapPlayerHistory = await evmOpenApi.mapPlayerHistory(ctx.http, tmpId, null, startTime, endTime)
60
- if (mapPlayerHistory.error) {
61
- return '查询玩家历史位置数据失败,请稍后重试'
39
+ // 如果没有传入tmpId,尝试从数据库查询绑定信息
40
+ if (!tmpId) {
41
+ let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId)
42
+ if (!guildBindData) {
43
+ return `请输入正确的玩家编号,或绑定玩家编号`
62
44
  }
45
+ tmpId = guildBindData.tmp_id
46
+ }
63
47
 
64
- // 过滤非对应服务器数据
65
- const promodsIdSet = new Set(PromodsIds)
66
- const mapPlayerHistoryArr = mapPlayerHistory.data.filter(item => {
67
- if (ServerType.ets === serverType) {
68
- return !promodsIdSet.has(item.serverId)
69
- } else if (ServerType.promods === serverType) {
70
- return promodsIdSet.has(item.serverId)
71
- }
72
- return false
73
- })
74
- if (mapPlayerHistoryArr.length === 0) {
75
- return `当日暂无数据`
76
- }
48
+ // 查询玩家信息
49
+ let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId)
50
+ if (playerInfo.error && playerInfo.code === 10001) {
51
+ return '玩家不存在'
52
+ } else if (playerInfo.error) {
53
+ return '查询玩家信息失败,请重试'
54
+ }
55
+
56
+ let startTime = "";
57
+ let endTime = "";
58
+
59
+ if (date === 'yesterday') {
60
+ const yesterday = dayjs().subtract(1, 'day');
61
+ startTime = yesterday.startOf('day').format('YYYY-MM-DD HH:mm:ss');
62
+ endTime = yesterday.endOf('day').format('YYYY-MM-DD HH:mm:ss');
63
+ }
64
+
65
+ if (date === 'today') {
66
+ startTime = dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss');
67
+ endTime = dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss');
68
+ }
69
+
70
+ if (date === 'thisMonth') {
71
+ startTime = dayjs().startOf('month').format('YYYY-MM-DD HH:mm:ss');
72
+ endTime = dayjs().endOf('month').format('YYYY-MM-DD HH:mm:ss');
73
+ }
77
74
 
78
- // 拼接数据
79
- let data = {
80
- mapType: ServerType.promods === serverType ? 'promods' : 'ets',
81
- name: playerInfo.data.name,
82
- smallAvatarUrl: playerInfo.data.smallAvatarUrl,
83
- todayMileage: playerInfo.data.todayMileage,
84
- points: mapPlayerHistory.data
75
+ if (date === 'lastMonth') {
76
+ const lastMonth = dayjs().subtract(1, 'month');
77
+ startTime = lastMonth.startOf('month').format('YYYY-MM-DD HH:mm:ss');
78
+ endTime = lastMonth.endOf('month').format('YYYY-MM-DD HH:mm:ss');
79
+ }
80
+
81
+ if (!startTime || !endTime) {
82
+ return '日期传递错误';
83
+ }
84
+
85
+ let mapPlayerHistory = await evmOpenApi.mapPlayerHistory(ctx.http, tmpId, null, startTime, endTime)
86
+ if (mapPlayerHistory.error) {
87
+ return '查询玩家历史位置数据失败,请稍后重试'
88
+ }
89
+
90
+ // 过滤非对应服务器数据
91
+ const promodsIdSet = new Set(PromodsIds)
92
+ const mapPlayerHistoryArr = mapPlayerHistory.data.filter(item => {
93
+ if (ServerType.ets === serverType) {
94
+ return !promodsIdSet.has(item.serverId)
95
+ } else if (ServerType.promods === serverType) {
96
+ return promodsIdSet.has(item.serverId)
97
+ }
98
+ return false
99
+ })
100
+ if (mapPlayerHistoryArr.length === 0) {
101
+ if (date === 'yesterday') {
102
+ return `昨日暂无数据`;
85
103
  }
104
+ if (date === 'today') {
105
+ return `今日暂无数据`;
106
+ }
107
+ if (date === 'thisMonth') {
108
+ return `本月暂无数据`;
109
+ }
110
+ if (date === 'lastMonth') {
111
+ return `上月暂无数据`;
112
+ }
113
+ return '暂无数据';
114
+ }
115
+
116
+ // 拼接数据
117
+ let data = {
118
+ mapType: ServerType.promods === serverType ? 'promods' : 'ets',
119
+ name: playerInfo.data.name,
120
+ smallAvatarUrl: playerInfo.data.smallAvatarUrl,
121
+ todayMileage: playerInfo.data.todayMileage,
122
+ points: mapPlayerHistoryArr
123
+ }
86
124
 
87
- let page
88
- try {
89
- page = await ctx.puppeteer.page()
90
- await page.setViewport({ width: 1000, height: 1000 })
91
- await page.goto(`file:///${resolve(__dirname, '../resource/footprint.html')}`)
92
- await page.evaluate(`init(${JSON.stringify(data)})`)
93
- await common.sleep(100)
94
- await page.waitForNetworkIdle()
95
- const element = await page.$("#container");
96
- return (
97
- segment.image(await element.screenshot({
98
- encoding: "binary"
99
- }), "image/jpg")
100
- )
101
- } catch (e) {
102
- return '渲染异常,请重试'
103
- } finally {
104
- if (page) {
105
- await page.close()
106
- }
125
+ let page
126
+ try {
127
+ page = await ctx.puppeteer.page()
128
+ await page.setViewport({ width: 1000, height: 1000 })
129
+ await page.goto(`file:///${resolve(__dirname, '../resource/footprint.html')}`)
130
+ await page.evaluate(`init(${JSON.stringify(data)})`)
131
+ await common.sleep(100)
132
+ await page.waitForNetworkIdle()
133
+ const element = await page.$("#container");
134
+ return (
135
+ segment.image(await element.screenshot({
136
+ encoding: "binary"
137
+ }), "image/jpg")
138
+ )
139
+ } catch (e) {
140
+ return '渲染异常,请重试'
141
+ } finally {
142
+ if (page) {
143
+ await page.close()
107
144
  }
108
- return `OK: ` + playerInfo.data.name
145
+ }
146
+ return `OK: ` + playerInfo.data.name
109
147
  }
package/lib/index.js CHANGED
@@ -186,7 +186,7 @@ function logDisabledCommands(ctx, cfg) {
186
186
  { key: 'tmpDlcMap', label: '地图dlc价格' },
187
187
  { key: 'tmpMileageRanking', label: '里程排行榜/今日里程排行榜' },
188
188
  { key: 'tmpVtc', label: 'vtc查询' },
189
- { key: 'tmpFootprint', label: '今日足迹' },
189
+ { key: 'tmpFootprint', label: '足迹查询' },
190
190
  { key: 'resetPassword', label: '重置密码' },
191
191
  { key: 'mainSettings', label: '查询积分' }
192
192
  ];
@@ -263,17 +263,53 @@ function registerBaseCommands(ctx, cfg) {
263
263
  }
264
264
 
265
265
  if (cfg.commands?.tmpFootprint) {
266
+ ctx.command('上月足迹 [tmpId:string]')
267
+ .usage("查询ETS服务器今日足迹")
268
+ .example("上月足迹")
269
+ .example("上月足迹 12345")
270
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.ets, tmpId, 'lastMonth'));
271
+
272
+ ctx.command('上月足迹p [tmpId:string]')
273
+ .usage("查询Promods服务器今日足迹")
274
+ .example("本月上月足迹p足迹p")
275
+ .example("上月足迹p 12345")
276
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.promods, tmpId, 'lastMonth'));
277
+
278
+ ctx.command('本月足迹 [tmpId:string]')
279
+ .usage("查询ETS服务器今日足迹")
280
+ .example("本月足迹")
281
+ .example("本月足迹 12345")
282
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.ets, tmpId, 'thisMonth'));
283
+
284
+ ctx.command('本月足迹p [tmpId:string]')
285
+ .usage("查询Promods服务器今日足迹")
286
+ .example("本月足迹p")
287
+ .example("本月足迹p 12345")
288
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.promods, tmpId, 'thisMonth'));
289
+
290
+ ctx.command('昨日足迹 [tmpId:string]')
291
+ .usage("查询ETS服务器今日足迹")
292
+ .example("昨日足迹")
293
+ .example("昨日足迹 12345")
294
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.ets, tmpId, 'yesterday'));
295
+
296
+ ctx.command('昨日足迹p [tmpId:string]')
297
+ .usage("查询Promods服务器今日足迹")
298
+ .example("昨日足迹p")
299
+ .example("昨日足迹p 12345")
300
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.promods, tmpId, 'yesterday'));
301
+
266
302
  ctx.command('今日足迹 [tmpId:string]')
267
303
  .usage("查询ETS服务器今日足迹")
268
304
  .example("今日足迹")
269
305
  .example("今日足迹 12345")
270
- .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.ets, tmpId));
306
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.ets, tmpId, 'today'));
271
307
 
272
308
  ctx.command('今日足迹p [tmpId:string]')
273
309
  .usage("查询Promods服务器今日足迹")
274
310
  .example("今日足迹p")
275
311
  .example("今日足迹p 12345")
276
- .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.promods, tmpId));
312
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.promods, tmpId, 'today'));
277
313
  }
278
314
 
279
315
  if (cfg.commands?.resetPassword) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ets2-tools-tmp",
3
- "description": "欧卡2 TMP在线查询、车队平台查询及活动提醒",
4
- "version": "2.3.2",
3
+ "description": "欧卡2 TruckersMP信息查询、车队平台查询及活动提醒",
4
+ "version": "2.3.3",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"
package/readme.md CHANGED
@@ -89,24 +89,27 @@
89
89
 
90
90
  ## 📋 指令说明
91
91
 
92
- | 指令名称 | 指令介绍 | 使用示例 |
93
- |------------------|---------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
94
- | 绑定 <tmpId> | 绑定TMP ID,绑定后使用其他指令可省略ID输入 | 绑定 123 |
95
- | 查询 <tmpId> | 查询TMP玩家基础信息 | 查询 123 |
96
- | 定位 <tmpId> | 查询玩家当前位置信息 | 定位 123 |
97
- | 路况 <serverName> | 查询服务器热门地点路况,支持简称:s1(Simulation 1)、s2(Simulation 2)、p(ProMods)、a(Arcade) | 路况 s1 |
98
- | 美卡服务器 | 查询美卡(ATS)服务器状态列表 | 美卡服务器 |
99
- | 欧卡服务器 | 查询欧卡(ETS2)服务器状态列表 | 欧卡服务器 |
100
- | tmp版本 | 查询TMP当前版本信息 | tmp版本 |
101
- | 地图dlc价格 | 查看地图DLC价格列表 | 地图dlc价格 |
102
- | 里程排行榜 | 总里程排行榜(数据从2025年8月23日20:00开始统计,绑定ID后可查个人排名) | 里程排行榜 |
103
- | 今日里程排行榜 | 今日里程排行榜(每日0点重置数据,绑定ID后可查个人排名) | 今日里程排行榜 |
104
- | vtc查询 <vtcid> | 查询指定VTC ID的详细信息 | vtc查询 456 |
105
- | 重置密码 [teamId]| 重置车队平台密码,管理员可指定teamId,普通用户重置自身密码 | 重置密码 789 |
106
- | 查询积分 [QQ号] | 查询车队平台积分,可查询自身或指定QQ号积分 | 查询积分 123456 |
107
- | 规则查询 | 获取TruckersMP官方规则链接 | 规则查询 |
108
- | 活动查询 | 手动检查今日活动数据,返回活动数量统计 | 活动查询 |
109
- | 今日足迹 <serverName> | 查看今日的足迹,支持简称:s1(Simulation 1)、s2(Simulation 2)、p(ProMods)、a(Arcade) | 今日足迹 s1 |
92
+ | 指令名称 | 指令介绍 | 使用示例 |
93
+ | ---------------------- | ------------------------------------------------------------------------------------------- | --------------------- |
94
+ | 绑定 <tmpId> | 绑定TMP ID,绑定后使用其他指令可省略ID输入 | 绑定 123 |
95
+ | 查询 <tmpId> | 查询TMP玩家基础信息 | 查询 123 |
96
+ | 定位 <tmpId> | 查询玩家当前位置信息 | 定位 123 |
97
+ | 路况 <serverName> | 查询服务器热门地点路况,支持简称:s1(Simulation 1)、s2(Simulation 2)、p(ProMods)、a(Arcade) | 路况 s1 |
98
+ | 美卡服务器 | 查询美卡(ATS)服务器状态列表 | 美卡服务器 |
99
+ | 欧卡服务器 | 查询欧卡(ETS2)服务器状态列表 | 欧卡服务器 |
100
+ | tmp版本 | 查询TMP当前版本信息 | tmp版本 |
101
+ | 地图dlc价格 | 查看地图DLC价格列表 | 地图dlc价格 |
102
+ | 里程排行榜 | 总里程排行榜(数据从2025年8月23日20:00开始统计,绑定ID后可查个人排名) | 里程排行榜 |
103
+ | 今日里程排行榜 | 今日里程排行榜(每日0点重置数据,绑定ID后可查个人排名) | 今日里程排行榜 |
104
+ | vtc查询 <vtcid> | 查询指定VTC ID的详细信息 | vtc查询 456 |
105
+ | 重置密码 [teamId] | 重置车队平台密码,管理员可指定teamId,普通用户重置自身密码 | 重置密码 789 |
106
+ | 查询积分 [QQ号] | 查询车队平台积分,可查询自身或指定QQ号积分 | 查询积分 123456 |
107
+ | 规则查询 | 获取TruckersMP官方规则链接 | 规则查询 |
108
+ | 活动查询 | 手动检查今日活动数据,返回活动数量统计 | 活动查询 |
109
+ | 今日/昨日足迹 <tmpId> | 查看今日/昨日除p服外的足迹 | 今日/昨日足迹 123456 |
110
+ | 今日/昨日足迹p <tmpId> | 查看今日/昨日p服的足迹 | 今日/昨日足迹p 123456 |
111
+ | 本月/上月足迹 <tmpId> | 查看本月/上月除p服外的足迹 | 本月/上月足迹 123456 |
112
+ | 本月/上月足迹p <tmpId> | 查看本月/上月p服的足迹 | 本月/上月足迹p 123456 |
110
113
 
111
114
  ## 📝 使用方法
112
115