koishi-plugin-ets2-tools-tmp 2.1.1 → 2.2.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,8 +1,6 @@
1
1
  module.exports = async (ctx, cfg, session, targetQQ) => {
2
- const { url, token, logOutput, platformVersion } = cfg.mainSettings?.settings || {};
3
- if ((platformVersion || "v1").toLowerCase() === "v2") {
4
- return "车队平台V2.0暂不支持积分查询";
5
- }
2
+ const { Name, url, token, logOutput, platformVersion } = cfg.mainSettings?.settings || {};
3
+ const platform = (platformVersion || "v1").toLowerCase();
6
4
  let queryQQ = targetQQ;
7
5
  if (!queryQQ) {
8
6
  queryQQ = session.userId;
@@ -30,27 +28,48 @@ module.exports = async (ctx, cfg, session, targetQQ) => {
30
28
  if (logOutput) {
31
29
  ctx.logger.info(`开始查询用户 ${queryQQ} 的积分`);
32
30
  }
33
- const userInfoUrl = `https://${url}/api/user/info/list?token=${token}&page=0&limit=7&tmpId=&tmpName=&teamId=&qq=${queryQQ}&state=0&teamRole=`;
34
- if (logOutput) {
35
- ctx.logger.info(`请求用户信息: ${userInfoUrl}`);
36
- }
37
- const userInfoResponse = await ctx.http.post(userInfoUrl);
38
- if (logOutput) {
39
- ctx.logger.info(`用户信息响应: ${JSON.stringify(userInfoResponse)}`);
40
- }
41
- if (userInfoResponse.code !== 0) {
42
- return `获取用户信息失败: ${userInfoResponse.msg || "未知错误"}`;
43
- }
44
- const userList = userInfoResponse.page?.list || [];
45
- if (userList.length === 0) {
46
- return `未找到QQ号 ${queryQQ} 关联的用户信息`;
31
+ let userInfo;
32
+ if (platform === "v2") {
33
+ const baseUrl = url || "open.vtcm.link";
34
+ const userInfoUrl = `https://${baseUrl}/members/get?token=${token}&qq=${queryQQ}`;
35
+ if (logOutput) {
36
+ ctx.logger.info(`请求V2.0用户信息: ${userInfoUrl}`);
37
+ }
38
+ const userInfoResponse = await ctx.http.get(userInfoUrl);
39
+ if (logOutput) {
40
+ ctx.logger.info(`V2.0用户信息响应: ${JSON.stringify(userInfoResponse)}`);
41
+ }
42
+ if (userInfoResponse.code !== 200) {
43
+ return `获取用户信息失败: ${userInfoResponse.msg || "未知错误"}`;
44
+ }
45
+ if (!userInfoResponse.data) {
46
+ return `未找到QQ号 ${queryQQ} 关联的用户信息`;
47
+ }
48
+ userInfo = userInfoResponse.data;
49
+ } else {
50
+ const userInfoUrl = `https://${url}/api/user/info/list?token=${token}&page=0&limit=7&tmpId=&tmpName=&teamId=&qq=${queryQQ}&state=0&teamRole=`;
51
+ if (logOutput) {
52
+ ctx.logger.info(`请求V1.0用户信息: ${userInfoUrl}`);
53
+ }
54
+ const userInfoResponse = await ctx.http.post(userInfoUrl);
55
+ if (logOutput) {
56
+ ctx.logger.info(`V1.0用户信息响应: ${JSON.stringify(userInfoResponse)}`);
57
+ }
58
+ if (userInfoResponse.code !== 0) {
59
+ return `获取用户信息失败: ${userInfoResponse.msg || "未知错误"}`;
60
+ }
61
+ const userList = userInfoResponse.page?.list || [];
62
+ if (userList.length === 0) {
63
+ return `未找到QQ号 ${queryQQ} 关联的用户信息`;
64
+ }
65
+ userInfo = userList[0];
47
66
  }
48
- const userInfo = userList[0];
49
- const rewardPoints = userInfo.rewardPoints || 0;
50
67
  const tmpName = userInfo.tmpName || "未知用户";
51
- const teamRole = userInfo.teamRole || "未知职位";
52
- const teamId = userInfo.teamId || "未知编号";
53
- let message = `🚛 晚风车队平台 - 积分查询🚚
68
+ const teamRole = userInfo.teamRole || userInfo.tmpRole || "未知职位";
69
+ const teamId = userInfo.teamId || userInfo.uid || "未知编号";
70
+ const rewardPoints = userInfo.rewardPoints || userInfo.point || 0;
71
+ const joinDate = userInfo.joinDate || "未知";
72
+ let message = `🚛 ${Name}平台 - 积分查询🚚
54
73
  `;
55
74
  message += `👤 用户: ${tmpName}
56
75
  `;
@@ -62,7 +81,7 @@ module.exports = async (ctx, cfg, session, targetQQ) => {
62
81
  `;
63
82
  message += `⭐ 当前积分: ${rewardPoints}
64
83
  `;
65
- message += `📅 加入日期: ${userInfo.joinDate || "未知"}`;
84
+ message += `📅 加入日期: ${joinDate}`;
66
85
  return message;
67
86
  } catch (error) {
68
87
  ctx.logger.error(`积分查询过程出错: ${error}`);
package/lib/index.js CHANGED
@@ -99,6 +99,7 @@ exports.Config = koishi_1.Schema.intersect([
99
99
  }).description('路况查询配置'),
100
100
  mainSettings: koishi_1.Schema.object({
101
101
  settings: koishi_1.Schema.object({
102
+ Name: koishi_1.Schema.string().description("车队名称"),
102
103
  platformVersion: koishi_1.Schema.union([
103
104
  koishi_1.Schema.const("v1").description("车队平台V1.0"),
104
105
  koishi_1.Schema.const("v2").description("车队平台V2.0")
@@ -111,7 +112,7 @@ exports.Config = koishi_1.Schema.intersect([
111
112
  mailTemplate: koishi_1.Schema.string().description("V2.0重置密码邮件内容模板,支持变量:{uid} {qq} {password} {psw}").default("我们已将您平台的密码进行重置,您的账号:{uid},新的密码为:{psw} 请妥善保管好您的密码,以防泄露"),
112
113
  mailFromName: koishi_1.Schema.string().description("V2.0重置密码邮件发件人名字(覆盖 adapter-mail 的 name)").default(""),
113
114
  logOutput: koishi_1.Schema.boolean().description("是否输出日志").default(true)
114
- }).description("V1/V2通用配置")
115
+ }).description("通用配置")
115
116
  }).description("车队平台配置"),
116
117
  resetPassword: koishi_1.Schema.object({
117
118
  settings: koishi_1.Schema.object({
@@ -174,25 +175,25 @@ exports.Config = koishi_1.Schema.intersect([
174
175
 
175
176
  function logDisabledCommands(ctx, cfg) {
176
177
  const commandFlags = cfg.commands || {};
177
- const disabled = [];
178
+ const enabled = [];
178
179
  const commandList = [
179
- { key: 'tmpQuery', label: '??/??' },
180
- { key: 'tmpServer', label: '?????/?????' },
181
- { key: 'tmpTraffic', label: '??' },
182
- { key: 'tmpPosition', label: '??' },
183
- { key: 'tmpVersion', label: 'tmp??' },
184
- { key: 'tmpDlcMap', label: '??dlc??' },
185
- { key: 'tmpMileageRanking', label: '?????/???????' },
186
- { key: 'tmpVtc', label: 'vtc??' },
187
- { key: 'tmpFootprint', label: '???' },
188
- { key: 'resetPassword', label: '????' },
189
- { key: 'mainSettings', label: '????' }
180
+ { key: 'tmpQuery', label: '查询/绑定' },
181
+ { key: 'tmpServer', label: '美卡/欧卡服务器' },
182
+ { key: 'tmpTraffic', label: '路况' },
183
+ { key: 'tmpPosition', label: '定位' },
184
+ { key: 'tmpVersion', label: 'tmp版本' },
185
+ { key: 'tmpDlcMap', label: '地图dlc价格' },
186
+ { key: 'tmpMileageRanking', label: '里程排行榜/今日里程排行榜' },
187
+ { key: 'tmpVtc', label: 'vtc查询' },
188
+ { key: 'tmpFootprint', label: '今日足迹' },
189
+ { key: 'resetPassword', label: '重置密码' },
190
+ { key: 'mainSettings', label: '查询积分' }
190
191
  ];
191
192
  for (const item of commandList) {
192
- if (commandFlags[item.key] === false) disabled.push(item.label);
193
+ if (commandFlags[item.key] !== false) enabled.push(item.label);
193
194
  }
194
- if (disabled.length) {
195
- ctx.logger.info(`[TMP-BOT] ??????????? commands ?????${disabled.join('?')}`);
195
+ if (enabled.length) {
196
+ ctx.logger.info(`[TMP-BOT] 已启用以下功能: ${enabled.join(', ')}`);
196
197
  }
197
198
  }
198
199
 
@@ -2,28 +2,22 @@ const md5 = require('js-md5');
2
2
  const translateCache = require('../database/translateCache');
3
3
  const TRANSLATE_API = 'https://fanyi-api.baidu.com/api/trans/vip/translate';
4
4
  module.exports = async (ctx, cfg, content, cache = true) => {
5
- // 没有开启百度翻译功能,直接返回文本
6
- if (!cfg.baiduTranslateEnable) {
5
+ if (!cfg.baiduTranslate.enable) {
7
6
  return content;
8
7
  }
9
- // 如果开启了缓存,尝试从缓存中查询翻译
10
- if (cfg.baiduTranslateCacheEnable && cache) {
8
+ if (cfg.baiduTranslate.enableCache && cache) {
11
9
  let translateContent = await translateCache.getTranslate(ctx.database, md5(content));
12
10
  if (translateContent) {
13
11
  return translateContent;
14
12
  }
15
13
  }
16
- // 创建请求秘钥
17
14
  let randomInt = Math.floor(Math.random() * 10000);
18
- let sign = md5(cfg.baiduTranslateAppId + content + randomInt + cfg.baiduTranslateKey);
19
- // 调用请求
20
- let result = await ctx.http.get(`${TRANSLATE_API}?q=${encodeURI(content)}&from=auto&to=zh&appid=${cfg.baiduTranslateAppId}&salt=${randomInt}&sign=${sign}`);
21
- // 如果翻译失败,直接返回内容
15
+ let sign = md5(cfg.baiduTranslate.appId + content + randomInt + cfg.baiduTranslate.key);
16
+ let result = await ctx.http.get(`${TRANSLATE_API}?q=${encodeURI(content)}&from=auto&to=zh&appid=${cfg.baiduTranslate.appId}&salt=${randomInt}&sign=${sign}`);
22
17
  if (result.error_code) {
23
18
  return content;
24
19
  }
25
- // 如果开启了缓存,将翻译内容缓存到数据库
26
- if (cfg.baiduTranslateCacheEnable && cache) {
20
+ if (cfg.baiduTranslate.enableCache && cache) {
27
21
  translateCache.save(ctx.database, md5(content), content, result.trans_result[0].dst);
28
22
  }
29
23
  return result.trans_result[0].dst;
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.1.1",
4
+ "version": "2.2.1",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"
package/readme.md CHANGED
@@ -16,7 +16,7 @@
16
16
  - **VTC与规则**:支持指定VTC ID查询,提供TruckersMP官方规则快速链接
17
17
 
18
18
  ### 🚚 车队活动管理
19
- - **双数据源支持**:同时对接车队平台(V1.0)和TruckersMP API获取活动数据
19
+ - **双数据源支持**:同时对接车队平台和TruckersMP API获取活动数据
20
20
  - **智能提醒机制**:活动开始前按配置时间自动发送提醒,支持多时间点精准设置
21
21
  - **档位状态检查**:自动检测活动档上传状态,及时向管理群发送提醒
22
22
  - **多群组适配**:区分管理群与主群,按需发送不同类型通知消息
@@ -117,7 +117,6 @@
117
117
  - 活动开始前按配置时间点向主群发送提醒
118
118
 
119
119
  ### 注意事项
120
- - 车队平台仅支持V1.0版本,V2.0版本适配将在后续更新
121
120
  - 路况查询仅支持指定服务器简称,需按规则输入(s1/s2/p/a)
122
121
  - 管理员专用功能(如重置密码)需提前配置管理员权限
123
122
 
@@ -139,4 +138,4 @@ TMP数据接口文档:https://apifox.com/apidoc/shared/38508a88-5ff4-4b29-b724
139
138
  - 支持平台: Koishi
140
139
  - 依赖: HTTP请求、定时任务、数据库
141
140
  - 适配器: 支持主流聊天平台(除邮件适配器外)
142
- - 车队平台支持: V1.0V2.0适配待更新)
141
+ - 车队平台支持: V1.0, V2.0