koishi-plugin-ets2-tools-tmp 3.1.91 → 3.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.
- package/lib/api/evmOpenApi.js +47 -3
- package/lib/command/tmpVtcMileageRanking.js +57 -0
- package/lib/command/tmpVtcOnline/tmpVtcOnlineImg.js +3 -2
- package/lib/command/tmpVtcOnline/tmpVtcOnlineText.js +3 -2
- package/lib/index.js +13 -0
- package/lib/resource/mileage-leaderboard.html +5 -2
- package/package.json +1 -1
package/lib/api/evmOpenApi.js
CHANGED
|
@@ -21,8 +21,8 @@ module.exports = {
|
|
|
21
21
|
let result = null
|
|
22
22
|
try {
|
|
23
23
|
result = game === 'ATS'
|
|
24
|
-
? await http.get(
|
|
25
|
-
: await requestWithFallback(http,
|
|
24
|
+
? await http.get(`${BASE_APIS[0]}/proxy/truckersmp/servers`)
|
|
25
|
+
: await requestWithFallback(http, `/server/list`)
|
|
26
26
|
} catch {
|
|
27
27
|
return {
|
|
28
28
|
error: true
|
|
@@ -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
|
*/
|
|
@@ -173,5 +195,27 @@ module.exports = {
|
|
|
173
195
|
data.data = result.data
|
|
174
196
|
}
|
|
175
197
|
return data
|
|
176
|
-
}
|
|
198
|
+
},
|
|
199
|
+
/**
|
|
200
|
+
* VTC在线成员
|
|
201
|
+
*/
|
|
202
|
+
async vtcOnlineList(http, vtcId) {
|
|
203
|
+
let result = null
|
|
204
|
+
try {
|
|
205
|
+
result = await requestWithFallback(http, `/vtc/memberOnline?vtcId=${vtcId}`)
|
|
206
|
+
} catch (e) {
|
|
207
|
+
return {
|
|
208
|
+
error: true
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 拼接返回数据
|
|
213
|
+
let data = {
|
|
214
|
+
error: result.code !== 200
|
|
215
|
+
}
|
|
216
|
+
if (!data.error) {
|
|
217
|
+
data.data = result.data
|
|
218
|
+
}
|
|
219
|
+
return data
|
|
220
|
+
},
|
|
177
221
|
}
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { segment } = require('koishi');
|
|
2
2
|
const { resolve } = require('path');
|
|
3
3
|
const common = require('../../util/common');
|
|
4
|
+
const evmOpenApi = require('../../api/evmOpenApi');
|
|
4
5
|
|
|
5
6
|
module.exports = async (ctx, cfg) => {
|
|
6
7
|
const vtcId = cfg.tmpActivityService?.api?.vtcId;
|
|
@@ -10,12 +11,12 @@ module.exports = async (ctx, cfg) => {
|
|
|
10
11
|
|
|
11
12
|
let result;
|
|
12
13
|
try {
|
|
13
|
-
result = await ctx.http
|
|
14
|
+
result = await evmOpenApi.vtcOnlineList(ctx.http, vtcId);
|
|
14
15
|
} catch {
|
|
15
16
|
return '查询车队在线成员失败,请稍后重试';
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
if (
|
|
19
|
+
if (result.error || !Array.isArray(result.data)) {
|
|
19
20
|
return '查询车队在线成员失败,请稍后重试';
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const evmOpenApi = require('../../api/evmOpenApi');
|
|
1
2
|
module.exports = async (ctx, cfg) => {
|
|
2
3
|
const vtcId = cfg.tmpActivityService?.api?.vtcId;
|
|
3
4
|
if (!vtcId) {
|
|
@@ -6,12 +7,12 @@ module.exports = async (ctx, cfg) => {
|
|
|
6
7
|
|
|
7
8
|
let result;
|
|
8
9
|
try {
|
|
9
|
-
result = await ctx.http
|
|
10
|
+
result = await evmOpenApi.vtcOnlineList(ctx.http, vtcId);
|
|
10
11
|
} catch {
|
|
11
12
|
return '查询车队在线成员失败,请稍后重试';
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
if (
|
|
15
|
+
if (result.error || !Array.isArray(result.data)) {
|
|
15
16
|
return '查询车队在线成员失败,请稍后重试';
|
|
16
17
|
}
|
|
17
18
|
|
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
|
|
490
|
-
const
|
|
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] || '里程排行榜';
|