koishi-plugin-ets2-tools-tmp 2.2.1 → 2.3.1

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.
@@ -1,136 +1,138 @@
1
- const BASE_API = 'https://da.vtcm.link';
1
+ const BASE_API = 'https://da.vtcm.link'
2
+
2
3
  module.exports = {
3
4
  /**
4
5
  * 查询服务器列表
5
6
  */
6
7
  async serverList(http) {
7
- let result = null;
8
+ let result = null
8
9
  try {
9
- result = await http.get(`${BASE_API}/server/list`);
10
- }
11
- catch {
10
+ result = await http.get(`${BASE_API}/server/list`)
11
+ } catch {
12
12
  return {
13
13
  error: true
14
- };
14
+ }
15
15
  }
16
+
16
17
  // 拼接返回数据
17
18
  let data = {
18
19
  error: result.code !== 200
19
- };
20
+ }
20
21
  if (!data.error) {
21
- data.data = result.data;
22
+ data.data = result.data
22
23
  }
23
- return data;
24
+
25
+ return data
24
26
  },
25
27
  /**
26
28
  * 查询在线玩家
27
29
  */
28
30
  async mapPlayerList(http, serverId, ax, ay, bx, by) {
29
- let result = null;
31
+ let result = null
30
32
  try {
31
- result = await http.get(`${BASE_API}/map/playerList?aAxisX=${ax}&aAxisY=${ay}&bAxisX=${bx}&bAxisY=${by}&serverId=${serverId}`);
32
- }
33
- catch {
33
+ result = await http.get(`${BASE_API}/map/playerList?aAxisX=${ax}&aAxisY=${ay}&bAxisX=${bx}&bAxisY=${by}&serverId=${serverId}`)
34
+ } catch {
34
35
  return {
35
36
  error: true
36
- };
37
+ }
37
38
  }
39
+
38
40
  // 拼接返回数据
39
41
  let data = {
40
42
  error: result.code !== 200
41
- };
43
+ }
42
44
  if (!data.error) {
43
- data.data = result.data;
45
+ data.data = result.data
44
46
  }
45
- return data;
47
+ return data
46
48
  },
47
49
  /**
48
50
  * 查询玩家信息
49
51
  */
50
52
  async playerInfo(http, tmpId) {
51
- let result = null;
53
+ let result = null
52
54
  try {
53
- result = await http.get(`${BASE_API}/player/info?tmpId=${tmpId}`);
54
- }
55
- catch {
55
+ result = await http.get(`${BASE_API}/player/info?tmpId=${tmpId}`)
56
+ } catch {
56
57
  return {
57
58
  error: true
58
- };
59
+ }
59
60
  }
61
+
60
62
  // 拼接返回数据
61
63
  let data = {
62
64
  code: result.code,
63
65
  error: result.code !== 200
64
- };
66
+ }
65
67
  if (!data.error) {
66
- data.data = result.data;
68
+ data.data = result.data
67
69
  }
68
- return data;
70
+ return data
69
71
  },
70
72
  /**
71
73
  * DLC列表
72
74
  */
73
75
  async dlcList(http, type) {
74
- let result = null;
76
+ let result = null
75
77
  try {
76
- result = await http.get(`${BASE_API}/dlc/list?type=${type}`);
77
- }
78
- catch (e) {
78
+ result = await http.get(`${BASE_API}/dlc/list?type=${type}`)
79
+ } catch (e) {
79
80
  return {
80
81
  error: true
81
- };
82
+ }
82
83
  }
84
+
83
85
  // 拼接返回数据
84
86
  let data = {
85
87
  error: result.code !== 200
86
- };
88
+ }
87
89
  if (!data.error) {
88
- data.data = result.data;
90
+ data.data = result.data
89
91
  }
90
- return data;
92
+ return data
91
93
  },
92
94
  /**
93
95
  * 玩家里程排行
94
96
  */
95
97
  async mileageRankingList(http, rankingType, tmpId) {
96
- let result = null;
98
+ let result = null
97
99
  try {
98
- result = await http.get(`${BASE_API}/statistics/mileageRankingList?rankingType=${rankingType}&tmpId=${tmpId || ''}&rankingCount=10`);
99
- }
100
- catch (e) {
100
+ result = await http.get(`${BASE_API}/statistics/mileageRankingList?rankingType=${rankingType}&tmpId=${tmpId || ''}&rankingCount=10`)
101
+ } catch (e) {
101
102
  return {
102
103
  error: true
103
- };
104
+ }
104
105
  }
106
+
105
107
  // 拼接返回数据
106
108
  let data = {
107
109
  error: result.code !== 200
108
- };
110
+ }
109
111
  if (!data.error) {
110
- data.data = result.data;
112
+ data.data = result.data
111
113
  }
112
- return data;
114
+ return data
113
115
  },
114
116
  /**
115
117
  * 查询玩家历史数据
116
118
  */
117
119
  async mapPlayerHistory(http, tmpId, serverId, startTime, endTime) {
118
- let result = null;
120
+ let result = null
119
121
  try {
120
- result = await http.get(`${BASE_API}/map/playerHistory?tmpId=${tmpId}&serverId=${serverId}&startTime=${startTime}&endTime=${endTime}`);
121
- }
122
- catch {
122
+ result = await http.get(`${BASE_API}/map/playerHistory?tmpId=${tmpId || ''}&serverId=${serverId || ''}&startTime=${startTime || ''}&endTime=${endTime || ''}`)
123
+ } catch {
123
124
  return {
124
125
  error: true
125
- };
126
+ }
126
127
  }
128
+
127
129
  // 拼接返回数据
128
130
  let data = {
129
131
  error: result.code !== 200
130
- };
132
+ }
131
133
  if (!data.error) {
132
- data.data = result.data;
134
+ data.data = result.data
133
135
  }
134
- return data;
136
+ return data
135
137
  }
136
- };
138
+ }
@@ -1,68 +1,109 @@
1
- const { segment } = require('koishi');
2
- const dayjs = require('dayjs');
3
- const { resolve } = require('path');
4
- const common = require('../util/common');
5
- const { ServerAliasToId, PromodsIds } = require('../util/constant');
6
- const evmOpenApi = require('../api/evmOpenApi');
7
- const guildBind = require('../database/guildBind');
8
- module.exports = async (ctx, session, serverName) => {
1
+ const { segment } = require('koishi')
2
+ const dayjs = require('dayjs')
3
+ const { resolve } = require('path')
4
+ const common = require('../util/common')
5
+ const { PromodsIds, ServerType } = require('../util/constant')
6
+ const evmOpenApi = require('../api/evmOpenApi')
7
+ const guildBind = require('../database/guildBind')
8
+
9
+ module.exports = async (ctx, session, serverType, tmpId) => {
9
10
  if (!ctx.puppeteer) {
10
- return '未启用 puppeteer 服务';
11
+ return '未启用 puppeteer 服务'
11
12
  }
12
- // 转换服务器别名到ID
13
- let serverId = ServerAliasToId[serverName];
14
- if (!serverId) {
15
- return '请输入正确的服务器名称 (s1, s2, p, a)';
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;
16
33
  }
17
- // 尝试从数据库查询绑定信息
18
- let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
19
- if (!guildBindData) {
20
- return `请先绑定玩家编号`;
34
+
35
+ if (tmpId && isNaN(tmpId)) {
36
+ return `请输入正确的玩家编号,或绑定玩家编号`
21
37
  }
22
- let tmpId = guildBindData.tmp_id;
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
46
+ }
47
+
23
48
  // 查询玩家信息
24
- let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId);
49
+ let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId)
25
50
  if (playerInfo.error && playerInfo.code === 10001) {
26
- return '玩家不存在';
27
- }
28
- else if (playerInfo.error) {
29
- return '查询玩家信息失败,请重试';
51
+ return '玩家不存在'
52
+ } else if (playerInfo.error) {
53
+ return '查询玩家信息失败,请重试'
30
54
  }
55
+
31
56
  // 查询当日历史位置数据
32
57
  const startTime = dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss');
33
58
  const endTime = dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss');
34
- let mapPlayerHistory = await evmOpenApi.mapPlayerHistory(ctx.http, tmpId, serverId, startTime, endTime);
35
- if (mapPlayerHistory.data.length === 0) {
36
- return `当日暂无数据`;
59
+ let mapPlayerHistory = await evmOpenApi.mapPlayerHistory(ctx.http, tmpId, null, startTime, endTime)
60
+ if (mapPlayerHistory.error) {
61
+ return '查询玩家历史位置数据失败,请稍后重试'
37
62
  }
63
+
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
+ }
77
+
38
78
  // 拼接数据
39
79
  let data = {
40
- mapType: PromodsIds.indexOf(serverId) !== -1 ? 'promods' : 'ets',
80
+ mapType: ServerType.promods === serverType ? 'promods' : 'ets',
41
81
  name: playerInfo.data.name,
42
82
  smallAvatarUrl: playerInfo.data.smallAvatarUrl,
43
83
  todayMileage: playerInfo.data.todayMileage,
44
84
  points: mapPlayerHistory.data
45
- };
46
- let page;
85
+ }
86
+
87
+ let page
47
88
  try {
48
- page = await ctx.puppeteer.page();
49
- await page.setViewport({ width: 1000, height: 1000 });
50
- await page.goto(`file:///${resolve(__dirname, '../resource/footprint.html')}`);
51
- await page.evaluate(`init(${JSON.stringify(data)})`);
52
- await common.sleep(100);
53
- await page.waitForNetworkIdle();
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()
54
95
  const element = await page.$("#container");
55
- return (segment.image(await element.screenshot({
56
- encoding: "binary"
57
- }), "image/jpg"));
58
- }
59
- catch (e) {
60
- return '渲染异常,请重试';
61
- }
62
- finally {
96
+ return (
97
+ segment.image(await element.screenshot({
98
+ encoding: "binary"
99
+ }), "image/jpg")
100
+ )
101
+ } catch (e) {
102
+ return '渲染异常,请重试'
103
+ } finally {
63
104
  if (page) {
64
- await page.close();
105
+ await page.close()
65
106
  }
66
107
  }
67
- return `OK: ` + playerInfo.data.name;
68
- };
108
+ return `OK: ` + playerInfo.data.name
109
+ }
@@ -22,6 +22,7 @@ const userGroup = {
22
22
  * 查询玩家信息
23
23
  */
24
24
  module.exports = async (ctx, cfg, session, tmpId) => {
25
+ const { vtcId } = cfg.tmpActivityService?.api || {};
25
26
  if (tmpId && tmpId.startsWith("<at ")) {
26
27
  if (tmpId.startsWith('<at ')) {
27
28
  queryQQ = tmpId.replace('<at ', '');
@@ -79,26 +80,41 @@ module.exports = async (ctx, cfg, session, tmpId) => {
79
80
  }
80
81
  }
81
82
  message += '\n🚚车队角色: ' + playerInfo.data.vtcRole;
82
- if (playerInfo.data.vtcId == 86009) {
83
+ if (playerInfo.data.vtcId == vtcId) {
83
84
  const { url, token, logOutput, platformVersion } = cfg.mainSettings?.settings || {};
84
- if ((platformVersion || "v1").toLowerCase() === "v2") {
85
- message += "\n车队平台V2.0暂不支持积分查询";
86
- } else {
85
+ const platform = (platformVersion || "v1").toLowerCase();
87
86
  try {
88
- if (logOutput) {
89
- ctx.logger.info(`tmpQuery:开始查询TmpID ${tmpId} 的积分`);
87
+ let rewardPoints = 0;
88
+ if (platform === "v2") {
89
+ const baseUrl = url;
90
+ const userInfoUrl = `https://${baseUrl}/members/get?token=${token}&tmpId=${tmpId}`;
91
+ if (logOutput) {
92
+ ctx.logger.info(`[TMP_BOT] tmpQuery:开始查询TmpID ${tmpId} 的V2.0积分`);
93
+ ctx.logger.info(`[TMP_BOT] 请求V2.0用户信息: ${userInfoUrl}`);
94
+ }
95
+ const userInfoResponse = await ctx.http.get(userInfoUrl);
96
+ if (logOutput) {
97
+ ctx.logger.info(`[TMP_BOT] V2.0用户信息响应: ${JSON.stringify(userInfoResponse)}`);
98
+ }
99
+ if (userInfoResponse.code === 200 && userInfoResponse.data) {
100
+ rewardPoints = userInfoResponse.data.point || 0;
101
+ }
102
+ } else {
103
+ if (logOutput) {
104
+ ctx.logger.info(`[TMP_BOT] tmpQuery:开始查询TmpID ${tmpId} 的V1.0积分`);
105
+ }
106
+ const userInfoUrl = `https://${url}/api/user/info/list?token=${token}&page=0&limit=7&tmpId=${tmpId}&tmpName=&teamId=&qq=&state=0&teamRole=`;
107
+ if (logOutput) {
108
+ ctx.logger.info(`[TMP_BOT] 请求V1.0用户信息: ${userInfoUrl}`);
109
+ }
110
+ const userInfoResponse = await ctx.http.post(userInfoUrl);
111
+ if (logOutput) {
112
+ ctx.logger.info(`[TMP_BOT] V1.0用户信息响应: ${JSON.stringify(userInfoResponse)}`);
113
+ }
114
+ const userList = userInfoResponse.page?.list || [];
115
+ const userInfo = userList[0];
116
+ rewardPoints = userInfo.rewardPoints || 0;
90
117
  }
91
- const userInfoUrl = `https://${url}/api/user/info/list?token=${token}&page=0&limit=7&tmpId=${tmpId}&tmpName=&teamId=&qq=&state=0&teamRole=`;
92
- if (logOutput) {
93
- ctx.logger.info(`请求用户信息: ${userInfoUrl}`);
94
- }
95
- const userInfoResponse = await ctx.http.post(userInfoUrl);
96
- if (logOutput) {
97
- ctx.logger.info(`用户信息响应: ${JSON.stringify(userInfoResponse)}`);
98
- }
99
- const userList = userInfoResponse.page?.list || [];
100
- const userInfo = userList[0];
101
- const rewardPoints = userInfo.rewardPoints || 0;
102
118
  message += `\n⭐ 当前车队积分: ${rewardPoints}`;
103
119
  } catch (error) {
104
120
  ctx.logger.error(`积分查询过程出错: ${error}`);
@@ -106,7 +122,6 @@ module.exports = async (ctx, cfg, session, tmpId) => {
106
122
  message += '查询出错';
107
123
  }
108
124
  }
109
- }
110
125
  }
111
126
  }
112
127
  message += '\n\n🚫是否封禁: ' + (playerInfo.data.isBan ? '是' : '否');
package/lib/index.js CHANGED
@@ -5,7 +5,7 @@ exports.apply = apply;
5
5
 
6
6
  const koishi_1 = require("koishi");
7
7
  const model = require('./database/model');
8
- const { MileageRankingType } = require('./util/constant');
8
+ const { ServerType } = require('./util/constant')
9
9
 
10
10
  const commands = {
11
11
  tmpQuery: require('./command/tmpQuery/tmpQuery'),
@@ -262,10 +262,17 @@ function registerBaseCommands(ctx, cfg) {
262
262
  }
263
263
 
264
264
  if (cfg.commands?.tmpFootprint) {
265
- ctx.command('今日足迹 <serverName>')
266
- .usage("查询今日足迹")
267
- .example("今日足迹 s1")
268
- .action(async ({ session }, serverName) => await commands.tmpFootprint(ctx, session, serverName));
265
+ ctx.command('今日足迹 [tmpId:string]')
266
+ .usage("查询ETS服务器今日足迹")
267
+ .example("今日足迹")
268
+ .example("今日足迹 12345")
269
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.ets, tmpId));
270
+
271
+ ctx.command('今日足迹p [tmpId:string]')
272
+ .usage("查询Promods服务器今日足迹")
273
+ .example("今日足迹p")
274
+ .example("今日足迹p 12345")
275
+ .action(async ({ session }, tmpId) => await commands.tmpFootprint(ctx, session, ServerType.promods, tmpId));
269
276
  }
270
277
 
271
278
  if (cfg.commands?.resetPassword) {
@@ -112,4 +112,4 @@
112
112
  }
113
113
  </script>
114
114
  </body>
115
- </html>
115
+ </html>
@@ -238,4 +238,4 @@
238
238
  }
239
239
  </script>
240
240
  </body>
241
- </html>
241
+ </html>
@@ -220,4 +220,4 @@
220
220
  }
221
221
  </script>
222
222
  </body>
223
- </html>
223
+ </html>
@@ -204,4 +204,4 @@
204
204
  }
205
205
  </script>
206
206
  </body>
207
- </html>
207
+ </html>
@@ -1,29 +1,36 @@
1
1
  module.exports = {
2
- /**
3
- * 路况信息展示方式
4
- */
5
- TmpTrafficType: {
6
- text: 1, // 文本
7
- heatMap: 2, // 热力图
8
- },
9
- /**
10
- * 里程排行榜类型
11
- */
12
- MileageRankingType: {
13
- total: 1,
14
- today: 2
15
- },
16
- /**
17
- * 服务器别名映射ID
18
- */
19
- ServerAliasToId: {
20
- 's1': 2,
21
- 's2': 41,
22
- 'p': 50,
23
- 'a': 7
24
- },
25
- /**
26
- * P服务器ID集合
27
- */
28
- PromodsIds: [50, 51]
29
- };
2
+ /**
3
+ * 路况信息展示方式
4
+ */
5
+ TmpTrafficType: {
6
+ text: 1, // 文本
7
+ heatMap: 2, // 热力图
8
+ },
9
+ /**
10
+ * 里程排行榜类型
11
+ */
12
+ MileageRankingType: {
13
+ total: 1,
14
+ today: 2
15
+ },
16
+ /**
17
+ * 服务器别名映射ID
18
+ */
19
+ ServerAliasToId: {
20
+ 's1': 2,
21
+ 's2': 41,
22
+ 'p': 50,
23
+ 'a': 7
24
+ },
25
+ /**
26
+ * P服务器ID集合
27
+ */
28
+ PromodsIds: [50, 51],
29
+ /**
30
+ * 服务器类型
31
+ */
32
+ ServerType: {
33
+ ets: 1,
34
+ promods: 2
35
+ }
36
+ }
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": "2.2.1",
4
+ "version": "2.3.1",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"