koishi-plugin-ets2-tools-tmp 3.1.9 → 3.2.0

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.
@@ -152,6 +152,28 @@ module.exports = {
152
152
  }
153
153
  return data
154
154
  },
155
+ /**
156
+ * VTC成员里程排行
157
+ */
158
+ async vtcMileageRankingList(http, rankingType, vtcId) {
159
+ let result = null
160
+ try {
161
+ result = await requestWithFallback(http, `/statistics/VTCmileageRankingList?rankingType=${rankingType}&vtcId=${vtcId}`)
162
+ } catch (e) {
163
+ return {
164
+ error: true
165
+ }
166
+ }
167
+
168
+ // 拼接返回数据
169
+ let data = {
170
+ error: result.code !== 200
171
+ }
172
+ if (!data.error) {
173
+ data.data = result.data
174
+ }
175
+ return data
176
+ },
155
177
  /**
156
178
  * 查询玩家历史数据
157
179
  */
@@ -298,7 +298,7 @@ class ActivityService {
298
298
 
299
299
  for (const activity of this.todayActivities) {
300
300
  const hasProfile = !!activity.profileFile;
301
- const message = hasProfile ? this.cfg.messages.profileUploaded : this.cfg.messages.profileNotUploaded;
301
+ let message = hasProfile ? this.cfg.messages.profileUploaded : this.cfg.messages.profileNotUploaded;
302
302
  if (hasProfile && activity.state == 0) {
303
303
  message += ",当前状态草稿。";
304
304
  }
@@ -0,0 +1,57 @@
1
+ const { segment } = require('koishi');
2
+ const { resolve } = require('path');
3
+ const common = require('../util/common');
4
+ const evmOpenApi = require('../api/evmOpenApi');
5
+ const guildBind = require('../database/guildBind');
6
+ module.exports = async (ctx, cfg, session, rankingType) => {
7
+ if (!ctx.puppeteer) {
8
+ return '未启用 Puppeteer 功能';
9
+ }
10
+ const vtcId = cfg.tmpActivityService?.api?.vtcId;
11
+ if (!vtcId) {
12
+ return '未配置VTC ID,请在插件配置中设置';
13
+ }
14
+ // 查询VTC排行榜信息
15
+ let mileageRankingList = await evmOpenApi.vtcMileageRankingList(ctx.http, rankingType, vtcId);
16
+ if (mileageRankingList.error) {
17
+ return '查询排行榜信息失败';
18
+ }
19
+ else if (mileageRankingList.data.length === 0) {
20
+ return '暂无数据';
21
+ }
22
+ // 从排行榜中查找当前玩家的排行信息
23
+ let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
24
+ let playerMileageRanking = null;
25
+ if (guildBindData) {
26
+ playerMileageRanking = mileageRankingList.data.find(p => p.tmpId == guildBindData.tmp_id) || null;
27
+ }
28
+ // 拼接页面数据
29
+ let data = {
30
+ rankingType: rankingType,
31
+ isVtc: true,
32
+ mileageRankingList: mileageRankingList.data,
33
+ playerMileageRanking: playerMileageRanking
34
+ };
35
+ let page;
36
+ try {
37
+ page = await ctx.puppeteer.page();
38
+ await page.setViewport({ width: 1000, height: 1000, deviceScaleFactor: 2 });
39
+ await page.goto(`file:///${resolve(__dirname, '../resource/mileage-leaderboard.html')}`);
40
+ await page.evaluate(`setData(${JSON.stringify(data)})`);
41
+ await page.waitForNetworkIdle();
42
+ await common.sleep(500);
43
+ const element = await page.$("#container");
44
+ return (segment.image(await element.screenshot({
45
+ encoding: "binary"
46
+ }), "image/jpg"));
47
+ }
48
+ catch (e) {
49
+ console.info(e);
50
+ return '渲染异常,请重试';
51
+ }
52
+ finally {
53
+ if (page) {
54
+ await page.close();
55
+ }
56
+ }
57
+ };
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ const commands = {
17
17
  tmpVersion: require('./command/tmpVersion'),
18
18
  tmpDlcMap: require('./command/tmpDlcMap'),
19
19
  tmpMileageRanking: require('./command/tmpMileageRanking'),
20
+ tmpVtcMileageRanking: require('./command/tmpVtcMileageRanking'),
20
21
  resetPassword: require('./command/ets-app/resetPassword/resetPassword'),
21
22
  queryPoint: require('./command/ets-app/queryPoint/queryPoint'),
22
23
  changePoint: require('./command/ets-app/changePoint/changePoint'),
@@ -77,6 +78,7 @@ exports.Config = koishi_1.Schema.intersect([
77
78
  tmpVersion: koishi_1.Schema.boolean().default(true).description('是否启用版本查询'),
78
79
  tmpDlcMap: koishi_1.Schema.boolean().default(true).description('是否启用DLC地图查询'),
79
80
  tmpMileageRanking: koishi_1.Schema.boolean().default(true).description('是否启用里程排行榜'),
81
+ tmpVtcMileageRanking: koishi_1.Schema.boolean().default(true).description('是否启用VTC里程排行榜'),
80
82
  pointRanking: koishi_1.Schema.boolean().default(false).description('是否启用积分排行榜'),
81
83
  tmpVtc: koishi_1.Schema.boolean().default(true).description('是否启用VTC查询'),
82
84
  tmpVtcOnline: koishi_1.Schema.boolean().default(false).description('是否启用车队在线成员查询功能'),
@@ -230,6 +232,7 @@ function logDisabledCommands(ctx, cfg) {
230
232
  { key: 'tmpVersion', label: 'tmp版本' },
231
233
  { key: 'tmpDlcMap', label: '地图dlc价格' },
232
234
  { key: 'tmpMileageRanking', label: '里程排行榜/今日里程排行榜' },
235
+ { key: 'tmpVtcMileageRanking', label: 'vtc里程排行榜/vtc今日里程排行榜' },
233
236
  { key: 'pointRanking', label: '积分排行榜' },
234
237
  { key: 'tmpVtc', label: 'vtc查询' },
235
238
  { key: 'tmpVtcOnline', label: '车队在线成员' },
@@ -306,6 +309,16 @@ function registerBaseCommands(ctx, cfg) {
306
309
  .action(async ({ session }) => await commands.tmpMileageRanking(ctx, session, MileageRankingType.today));
307
310
  }
308
311
 
312
+ if (cfg.commands?.tmpVtcMileageRanking) {
313
+ ctx.command('vtc里程排行榜')
314
+ .usage("查询车队总里程排行榜")
315
+ .action(async ({ session }) => await commands.tmpVtcMileageRanking(ctx, cfg, session, MileageRankingType.total));
316
+
317
+ ctx.command('vtc今日里程排行榜')
318
+ .usage("查询车队今日里程排行榜")
319
+ .action(async ({ session }) => await commands.tmpVtcMileageRanking(ctx, cfg, session, MileageRankingType.today));
320
+ }
321
+
309
322
  if (cfg.commands?.pointRanking) {
310
323
  ctx.command('积分排行')
311
324
  .usage("查询车队积分排行榜(仅限总群和管理群使用)")
@@ -486,8 +486,11 @@
486
486
  function setData(apiData) {
487
487
  if (!apiData) return;
488
488
 
489
- const titles = { 1: '总里程排行榜', 2: '今日里程排行榜' };
490
- const subs = { 1: 'ALL-TIME MILEAGE RANKING', 2: 'TODAY\'S MILEAGE RANKING' };
489
+ const isVtc = !!apiData.isVtc;
490
+ const titles = isVtc ? { 1: 'VTC总里程排行榜', 2: 'VTC今日里程排行榜' } : { 1: '总里程排行榜', 2: '今日里程排行榜' };
491
+ const subs = isVtc
492
+ ? { 1: 'VTC ALL-TIME MILEAGE RANKING', 2: 'VTC TODAY\'S MILEAGE RANKING' }
493
+ : { 1: 'ALL-TIME MILEAGE RANKING', 2: 'TODAY\'S MILEAGE RANKING' };
491
494
  const footers = { 1: '* 数据自 2025年8月23日 20:00 开始统计', 2: '* 每日 0:00 重置统计' };
492
495
 
493
496
  document.getElementById('header-title').textContent = titles[apiData.rankingType] || '里程排行榜';
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.1.9",
4
+ "version": "3.2.0",
5
5
  "contributors": [
6
6
  "opwop <slhp1013@qq.com>",
7
7
  "bot_actions <168329908@qq.com>"