koishi-plugin-ets2-tools-tmp 3.3.61 → 3.3.62

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.
@@ -55,16 +55,22 @@ module.exports = async (ctx, cfg, session, tmpId) => {
55
55
  }
56
56
  tmpId = guildBindData.tmp_id;
57
57
  }
58
- // 查询玩家信息
59
- let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId);
58
+ // 并行请求玩家信息与线上状态(互不依赖,避免串行等待)
59
+ const [playerInfo, playerMapInfo] = await Promise.all([
60
+ evmOpenApi.playerInfo(ctx.http, tmpId),
61
+ truckyAppApi.online(ctx.http, tmpId)
62
+ ]);
60
63
  if (playerInfo.error && playerInfo.code === 10001) {
61
64
  return '玩家不存在';
62
65
  }
63
66
  else if (playerInfo.error) {
64
67
  return '查询玩家信息失败,请重试';
65
68
  }
66
- // 查询线上信息
67
- let playerMapInfo = await truckyAppApi.online(ctx.http, tmpId);
69
+ // Steam游戏时长请求提前发起,与下方积分查询/翻译并行执行
70
+ const steamApiKey = cfg.steamApi?.key;
71
+ const steamGameTimePromise = (cfg.commands?.tmpQueryGameTime && steamApiKey)
72
+ ? evmOpenApi.steamGameTime(ctx.http, steamApiKey, playerInfo.data.steamId)
73
+ : null;
68
74
  // 拼接数据
69
75
  let data = {};
70
76
  data.showAvatar = cfg.tmpQuery?.showAvatar !== false;
@@ -94,8 +100,12 @@ module.exports = async (ctx, cfg, session, tmpId) => {
94
100
  if (data.isOnline) {
95
101
  data.onlineStatus = '在线';
96
102
  data.onlineServerName = playerMapInfo.data.serverDetails.name;
97
- data.onlineCountry = await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country);
98
- data.onlineCity = await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName);
103
+ const [onlineCountry, onlineCity] = await Promise.all([
104
+ baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country),
105
+ baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName)
106
+ ]);
107
+ data.onlineCountry = onlineCountry;
108
+ data.onlineCity = onlineCity;
99
109
  data.onlineX = playerMapInfo.data.x;
100
110
  data.onlineY = playerMapInfo.data.y;
101
111
  data.onlineMapType = playerMapInfo.data.serverDetails.id === 50 ? 'promods' : 'ets';
@@ -157,17 +167,13 @@ module.exports = async (ctx, cfg, session, tmpId) => {
157
167
  }
158
168
  }
159
169
  }
160
- // 查询Steam游戏时长
170
+ // 等待Steam游戏时长结果(请求已提前发起,与积分查询/翻译并行)
161
171
  data.ets2GameTime = null;
162
172
  data.atsGameTime = null;
163
- if (cfg.commands?.tmpQueryGameTime) {
164
- const steamApiKey = cfg.steamApi?.key;
165
- if (steamApiKey) {
166
- const steamId = playerInfo.data.steamId;
167
- const gameTimes = await evmOpenApi.steamGameTime(ctx.http, steamApiKey, steamId);
168
- data.ets2GameTime = gameTimes.ets2;
169
- data.atsGameTime = gameTimes.ats;
170
- }
173
+ if (steamGameTimePromise) {
174
+ const gameTimes = await steamGameTimePromise;
175
+ data.ets2GameTime = gameTimes.ets2;
176
+ data.atsGameTime = gameTimes.ats;
171
177
  }
172
178
  let page;
173
179
  try {
@@ -51,16 +51,22 @@ module.exports = async (ctx, cfg, session, tmpId) => {
51
51
  }
52
52
  tmpId = guildBindData.tmp_id;
53
53
  }
54
- // 查询玩家信息
55
- let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId);
54
+ // 并行请求玩家信息与线上状态(互不依赖,避免串行等待)
55
+ const [playerInfo, playerMapInfo] = await Promise.all([
56
+ evmOpenApi.playerInfo(ctx.http, tmpId),
57
+ truckyAppApi.online(ctx.http, tmpId)
58
+ ]);
56
59
  if (playerInfo.error && playerInfo.code === 10001) {
57
60
  return '玩家不存在';
58
61
  }
59
62
  else if (playerInfo.error) {
60
63
  return '玩家信息查询失败,请重试';
61
64
  }
62
- // 查询线上信息
63
- let playerMapInfo = await truckyAppApi.online(ctx.http, tmpId);
65
+ // Steam游戏时长请求提前发起,与下方积分查询并行执行
66
+ const steamApiKey = cfg.steamApi?.key;
67
+ const steamGameTimePromise = (cfg.commands?.tmpQueryGameTime && steamApiKey)
68
+ ? evmOpenApi.steamGameTime(ctx.http, steamApiKey, playerInfo.data.steamId)
69
+ : null;
64
70
  // 拼接消息模板
65
71
  let message = '';
66
72
  if (cfg.tmpQuery?.showAvatar) {
@@ -171,30 +177,20 @@ module.exports = async (ctx, cfg, session, tmpId) => {
171
177
  if (playerMapInfo && !playerMapInfo.error) {
172
178
  message += '\n📶在线状态: ' + (playerMapInfo.data.online ? `在线🟢 (${playerMapInfo.data.serverDetails.name})` : '离线⚫');
173
179
  if (playerMapInfo.data.online) {
174
- message += '\n🌍线上位置: ';
175
- message += await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country);
176
- message += ' - ';
177
- message += await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName);
180
+ const [onlineCountry, onlineCity] = await Promise.all([
181
+ baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country),
182
+ baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName)
183
+ ]);
184
+ message += '\n🌍线上位置: ' + onlineCountry + ' - ' + onlineCity;
178
185
  }
179
186
  else if (playerInfo.data.lastOnlineTime) {
180
187
  message += '\n📶上次在线: ' + dayjs(playerInfo.data.lastOnlineTime).fromNow(false);
181
188
  }
182
189
  }
183
- const steamID = playerInfo.data.steamId;
184
-
185
- // 查询Steam游戏时长
186
- async function getSteamGameTimes(steamId) {
187
- const steamApiKey = cfg.steamApi?.key;
188
- if (!steamApiKey) {
189
- return { ets2: null, ats: null };
190
- }
191
- return evmOpenApi.steamGameTime(ctx.http, steamApiKey, steamId);
192
- }
193
-
194
- // 获取欧卡和美卡游戏时长
190
+ // 获取欧卡和美卡游戏时长(请求已提前发起,与积分查询/翻译并行)
195
191
  if (cfg.commands?.tmpQueryGameTime) {
196
- const gameTimes = await getSteamGameTimes(steamID);
197
-
192
+ const gameTimes = (await steamGameTimePromise) || { ets2: null, ats: null };
193
+
198
194
  // 添加游戏时长信息
199
195
  if (gameTimes.ets2) {
200
196
  message += '\n🎮欧卡游戏时长: ' + gameTimes.ets2;
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": "3.3.61",
4
+ "version": "3.3.62",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"