koishi-plugin-tmp-bot 1.20.0 → 1.20.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 +136 -1
- package/lib/api/truckersMpApi.js +110 -1
- package/lib/api/truckersMpMapApi.js +25 -1
- package/lib/api/truckyAppApi.js +47 -1
- package/lib/command/tmpBind.js +19 -1
- package/lib/command/tmpDlcMap.js +33 -1
- package/lib/command/tmpFootprint.js +82 -1
- package/lib/command/tmpMileageRanking.js +55 -1
- package/lib/command/tmpPosition.d.ts +1 -1
- package/lib/command/tmpPosition.js +95 -1
- package/lib/command/tmpQuery/tmpQuery.js +12 -1
- package/lib/command/tmpQuery/tmpQueryImg.d.ts +1 -1
- package/lib/command/tmpQuery/tmpQueryImg.js +103 -1
- package/lib/command/tmpQuery/tmpQueryText.js +118 -1
- package/lib/command/tmpServer.js +34 -1
- package/lib/command/tmpTraffic/tmpTraffic.js +15 -1
- package/lib/command/tmpTraffic/tmpTrafficMap.js +119 -1
- package/lib/command/tmpTraffic/tmpTrafficText.js +58 -1
- package/lib/command/tmpVersion.js +14 -1
- package/lib/database/guildBind.js +41 -1
- package/lib/database/model.js +65 -1
- package/lib/database/translateCache.js +31 -1
- package/lib/index.js +57 -1
- package/lib/resource/dlc.html +30 -1
- package/lib/resource/footprint.html +125 -1
- package/lib/resource/mileage-leaderboard.html +174 -1
- package/lib/resource/package/ets-map.js +63 -1
- package/lib/resource/package/leaflet/heatmap.min.js +9 -1
- package/lib/resource/package/leaflet/leaflet-heatmap.js +246 -1
- package/lib/resource/package/leaflet/leaflet.min.js +1 -1
- package/lib/resource/position.html +105 -1
- package/lib/resource/query.html +137 -1
- package/lib/resource/traffic.html +121 -1
- package/lib/util/baiduTranslate.js +30 -1
- package/lib/util/common.js +5 -1
- package/lib/util/constant.js +36 -1
- package/package.json +2 -1
|
@@ -1 +1,95 @@
|
|
|
1
|
-
|
|
1
|
+
const { segment } = require('koishi');
|
|
2
|
+
const { resolve } = require('path');
|
|
3
|
+
const guildBind = require('../database/guildBind');
|
|
4
|
+
const truckyAppApi = require('../api/truckyAppApi');
|
|
5
|
+
const truckersMpApi = require('../api/truckersMpApi');
|
|
6
|
+
const evmOpenApi = require('../api/evmOpenApi');
|
|
7
|
+
const baiduTranslate = require('../util/baiduTranslate');
|
|
8
|
+
const common = require('../util/common');
|
|
9
|
+
/**
|
|
10
|
+
* 定位
|
|
11
|
+
*/
|
|
12
|
+
module.exports = async (ctx, cfg, session, tmpId) => {
|
|
13
|
+
if (ctx.puppeteer) {
|
|
14
|
+
if (tmpId && isNaN(tmpId)) {
|
|
15
|
+
return `请输入正确的玩家编号,或绑定玩家编号`;
|
|
16
|
+
}
|
|
17
|
+
// 如果没有传入tmpId,尝试从数据库查询绑定信息
|
|
18
|
+
if (!tmpId) {
|
|
19
|
+
let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
|
|
20
|
+
if (!guildBindData) {
|
|
21
|
+
return `请输入正确的玩家编号,或绑定玩家编号`;
|
|
22
|
+
}
|
|
23
|
+
tmpId = guildBindData.tmp_id;
|
|
24
|
+
}
|
|
25
|
+
// 查询玩家信息
|
|
26
|
+
let playerInfo = await truckersMpApi.player(ctx.http, tmpId);
|
|
27
|
+
if (playerInfo.error) {
|
|
28
|
+
return '查询玩家信息失败,请重试';
|
|
29
|
+
}
|
|
30
|
+
// 查询线上信息
|
|
31
|
+
let playerMapInfo = await truckyAppApi.online(ctx.http, tmpId);
|
|
32
|
+
if (playerMapInfo.error) {
|
|
33
|
+
return '查询玩家信息失败,请重试';
|
|
34
|
+
}
|
|
35
|
+
if (!playerMapInfo.data.online) {
|
|
36
|
+
return '玩家离线';
|
|
37
|
+
}
|
|
38
|
+
// 查询周边玩家,并处理数据
|
|
39
|
+
let areaPlayersData = await evmOpenApi.mapPlayerList(ctx.http, playerMapInfo.data.server, playerMapInfo.data.x - 4000, playerMapInfo.data.y + 2500, playerMapInfo.data.x + 4000, playerMapInfo.data.y - 2500);
|
|
40
|
+
let areaPlayerList = [];
|
|
41
|
+
if (!areaPlayersData.error) {
|
|
42
|
+
areaPlayerList = areaPlayersData.data;
|
|
43
|
+
let index = areaPlayerList.findIndex((player) => {
|
|
44
|
+
return player.tmpId.toString() === tmpId.toString();
|
|
45
|
+
});
|
|
46
|
+
if (index !== -1) {
|
|
47
|
+
areaPlayerList.splice(index, 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
areaPlayerList.push({
|
|
51
|
+
axisX: playerMapInfo.data.x,
|
|
52
|
+
axisY: playerMapInfo.data.y,
|
|
53
|
+
tmpId
|
|
54
|
+
});
|
|
55
|
+
// promods服ID集合
|
|
56
|
+
let promodsServerIdList = [50, 51];
|
|
57
|
+
// 构建地图数据
|
|
58
|
+
let data = {
|
|
59
|
+
mapType: promodsServerIdList.indexOf(playerMapInfo.data.server) !== -1 ? 'promods' : 'ets',
|
|
60
|
+
avatar: playerInfo.data.smallAvatar,
|
|
61
|
+
username: playerInfo.data.name,
|
|
62
|
+
serverName: playerMapInfo.data.serverDetails.name,
|
|
63
|
+
country: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country),
|
|
64
|
+
realName: await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName),
|
|
65
|
+
currentPlayerId: tmpId,
|
|
66
|
+
centerX: playerMapInfo.data.x,
|
|
67
|
+
centerY: playerMapInfo.data.y,
|
|
68
|
+
playerList: areaPlayerList
|
|
69
|
+
};
|
|
70
|
+
let page;
|
|
71
|
+
try {
|
|
72
|
+
page = await ctx.puppeteer.page();
|
|
73
|
+
await page.setViewport({ width: 1000, height: 1000 });
|
|
74
|
+
await page.goto(`file:///${resolve(__dirname, '../resource/position.html')}`);
|
|
75
|
+
await page.evaluate(`setData(${JSON.stringify(data)})`);
|
|
76
|
+
await common.sleep(100);
|
|
77
|
+
await page.waitForNetworkIdle();
|
|
78
|
+
const element = await page.$("#container");
|
|
79
|
+
return (segment.image(await element.screenshot({
|
|
80
|
+
encoding: "binary"
|
|
81
|
+
}), "image/jpg"));
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return '渲染异常,请重试';
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
if (page) {
|
|
88
|
+
await page.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return '未启用 puppeteer 服务';
|
|
94
|
+
}
|
|
95
|
+
};
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
const
|
|
1
|
+
const tmpQueryText = require("./tmpQueryText");
|
|
2
|
+
const tmpQueryImg = require("./tmpQueryImg");
|
|
3
|
+
module.exports = async (ctx, cfg, session, tmpId) => {
|
|
4
|
+
switch (cfg.tmpQueryType) {
|
|
5
|
+
case 1:
|
|
6
|
+
return await tmpQueryText(ctx, cfg, session, tmpId);
|
|
7
|
+
case 2:
|
|
8
|
+
return await tmpQueryImg(ctx, cfg, session, tmpId);
|
|
9
|
+
default:
|
|
10
|
+
return '指令配置错误';
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function _exports(ctx: any, cfg: any, session: any, tmpId: any): Promise<segment | "
|
|
1
|
+
declare function _exports(ctx: any, cfg: any, session: any, tmpId: any): Promise<segment | "渲染异常,请重试" | "未启用 puppeteer 服务" | "请输入正确的玩家编号,或绑定玩家编号" | "玩家不存在" | "查询玩家信息失败,请重试">;
|
|
2
2
|
export = _exports;
|
|
3
3
|
import { segment } from "@koishijs/core";
|
|
@@ -1 +1,103 @@
|
|
|
1
|
-
const
|
|
1
|
+
const dayjs = require('dayjs');
|
|
2
|
+
const guildBind = require('../../database/guildBind');
|
|
3
|
+
const truckyAppApi = require('../../api/truckyAppApi');
|
|
4
|
+
const evmOpenApi = require('../../api/evmOpenApi');
|
|
5
|
+
const baiduTranslate = require('../../util/baiduTranslate');
|
|
6
|
+
const { resolve } = require("path");
|
|
7
|
+
const common = require("../../util/common");
|
|
8
|
+
const { segment } = require("koishi");
|
|
9
|
+
/**
|
|
10
|
+
* 用户组
|
|
11
|
+
*/
|
|
12
|
+
const userGroup = {
|
|
13
|
+
'Player': '玩家',
|
|
14
|
+
'Retired Legend': '退役',
|
|
15
|
+
'Game Developer': '游戏开发者',
|
|
16
|
+
'Retired Team Member': '退休团队成员',
|
|
17
|
+
'Add-On Team': '附加组件团队',
|
|
18
|
+
'Game Moderator': '游戏管理员'
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 查询玩家信息
|
|
22
|
+
*/
|
|
23
|
+
module.exports = async (ctx, cfg, session, tmpId) => {
|
|
24
|
+
if (!ctx.puppeteer) {
|
|
25
|
+
return '未启用 puppeteer 服务';
|
|
26
|
+
}
|
|
27
|
+
if (tmpId && isNaN(tmpId)) {
|
|
28
|
+
return `请输入正确的玩家编号,或绑定玩家编号`;
|
|
29
|
+
}
|
|
30
|
+
// 如果没有传入tmpId,尝试从数据库查询绑定信息
|
|
31
|
+
if (!tmpId) {
|
|
32
|
+
let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
|
|
33
|
+
if (!guildBindData) {
|
|
34
|
+
return `请输入正确的玩家编号,或绑定玩家编号`;
|
|
35
|
+
}
|
|
36
|
+
tmpId = guildBindData.tmp_id;
|
|
37
|
+
}
|
|
38
|
+
// 查询玩家信息
|
|
39
|
+
let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId);
|
|
40
|
+
if (playerInfo.error && playerInfo.code === 10001) {
|
|
41
|
+
return '玩家不存在';
|
|
42
|
+
}
|
|
43
|
+
else if (playerInfo.error) {
|
|
44
|
+
return '查询玩家信息失败,请重试';
|
|
45
|
+
}
|
|
46
|
+
// 查询线上信息
|
|
47
|
+
let playerMapInfo = await truckyAppApi.online(ctx.http, tmpId);
|
|
48
|
+
// 拼接数据
|
|
49
|
+
let data = {};
|
|
50
|
+
data.tmpId = playerInfo.data.tmpId;
|
|
51
|
+
data.name = playerInfo.data.name;
|
|
52
|
+
data.steamId = playerInfo.data.steamId;
|
|
53
|
+
data.registerDate = dayjs(playerInfo.data.registerTime).format('YYYY年MM月DD日');
|
|
54
|
+
data.avatarUrl = playerInfo.data.avatarUrl;
|
|
55
|
+
data.groupColor = playerInfo.data.groupColor;
|
|
56
|
+
data.groupName = (userGroup[playerInfo.data.groupName] || playerInfo.data.groupName);
|
|
57
|
+
data.isJoinVtc = playerInfo.data.isJoinVtc;
|
|
58
|
+
data.vtcName = playerInfo.data.vtcName;
|
|
59
|
+
data.vtcRole = playerInfo.data.vtcRole;
|
|
60
|
+
data.isSponsor = playerInfo.data.isSponsor;
|
|
61
|
+
data.sponsorAmount = playerInfo.data.sponsorAmount;
|
|
62
|
+
data.sponsorCumulativeAmount = playerInfo.data.sponsorCumulativeAmount;
|
|
63
|
+
data.sponsorHide = playerInfo.data.sponsorHide;
|
|
64
|
+
data.isOnline = false;
|
|
65
|
+
if (playerMapInfo && !playerMapInfo.error) {
|
|
66
|
+
data.isOnline = playerMapInfo.data.online;
|
|
67
|
+
if (data.isOnline) {
|
|
68
|
+
data.onlineServerName = playerMapInfo.data.serverDetails.name;
|
|
69
|
+
data.onlineCountry = await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country);
|
|
70
|
+
data.onlineCity = await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName);
|
|
71
|
+
data.onlineX = playerMapInfo.data.x;
|
|
72
|
+
data.onlineY = playerMapInfo.data.y;
|
|
73
|
+
data.onlineMapType = playerMapInfo.data.serverDetails.id === 50 ? 'promods' : 'ets';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
data.isBan = playerInfo.data.isBan;
|
|
77
|
+
data.banUntil = playerInfo.data.banUntil;
|
|
78
|
+
data.banReason = playerInfo.data.banReason;
|
|
79
|
+
data.banReasonZh = playerInfo.data.banReasonZh;
|
|
80
|
+
data.banCount = playerInfo.data.banCount;
|
|
81
|
+
data.banHide = playerInfo.data.banHide;
|
|
82
|
+
let page;
|
|
83
|
+
try {
|
|
84
|
+
page = await ctx.puppeteer.page();
|
|
85
|
+
await page.setViewport({ width: 1000, height: 1000 });
|
|
86
|
+
await page.goto(`file:///${resolve(__dirname, '../../resource/query.html')}`);
|
|
87
|
+
await page.evaluate(`init(${JSON.stringify(data)})`);
|
|
88
|
+
await common.sleep(100);
|
|
89
|
+
await page.waitForNetworkIdle();
|
|
90
|
+
const element = await page.$("#container");
|
|
91
|
+
return (segment.image(await element.screenshot({
|
|
92
|
+
encoding: "binary"
|
|
93
|
+
}), "image/jpg"));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return '渲染异常,请重试';
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (page) {
|
|
100
|
+
await page.close();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
@@ -1 +1,118 @@
|
|
|
1
|
-
const
|
|
1
|
+
const dayjs = require('dayjs');
|
|
2
|
+
const dayjsRelativeTime = require('dayjs/plugin/relativeTime');
|
|
3
|
+
const dayjsLocaleZhCn = require('dayjs/locale/zh-cn');
|
|
4
|
+
const guildBind = require('../../database/guildBind');
|
|
5
|
+
const truckyAppApi = require('../../api/truckyAppApi');
|
|
6
|
+
const evmOpenApi = require('../../api/evmOpenApi');
|
|
7
|
+
const baiduTranslate = require('../../util/baiduTranslate');
|
|
8
|
+
dayjs.extend(dayjsRelativeTime);
|
|
9
|
+
dayjs.locale(dayjsLocaleZhCn);
|
|
10
|
+
/**
|
|
11
|
+
* 用户组
|
|
12
|
+
*/
|
|
13
|
+
const userGroup = {
|
|
14
|
+
'Player': '玩家',
|
|
15
|
+
'Retired Legend': '退役',
|
|
16
|
+
'Game Developer': '游戏开发者',
|
|
17
|
+
'Retired Team Member': '退休团队成员',
|
|
18
|
+
'Add-On Team': '附加组件团队',
|
|
19
|
+
'Game Moderator': '游戏管理员'
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 查询玩家信息
|
|
23
|
+
*/
|
|
24
|
+
module.exports = async (ctx, cfg, session, tmpId) => {
|
|
25
|
+
if (tmpId && isNaN(tmpId)) {
|
|
26
|
+
return `请输入正确的玩家编号,或绑定玩家编号`;
|
|
27
|
+
}
|
|
28
|
+
// 如果没有传入tmpId,尝试从数据库查询绑定信息
|
|
29
|
+
if (!tmpId) {
|
|
30
|
+
let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
|
|
31
|
+
if (!guildBindData) {
|
|
32
|
+
return `请输入正确的玩家编号,或绑定玩家编号`;
|
|
33
|
+
}
|
|
34
|
+
tmpId = guildBindData.tmp_id;
|
|
35
|
+
}
|
|
36
|
+
// 查询玩家信息
|
|
37
|
+
let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId);
|
|
38
|
+
if (playerInfo.error && playerInfo.code === 10001) {
|
|
39
|
+
return '玩家不存在';
|
|
40
|
+
}
|
|
41
|
+
else if (playerInfo.error) {
|
|
42
|
+
return '查询玩家信息失败,请重试';
|
|
43
|
+
}
|
|
44
|
+
// 查询线上信息
|
|
45
|
+
let playerMapInfo = await truckyAppApi.online(ctx.http, tmpId);
|
|
46
|
+
// 拼接消息模板
|
|
47
|
+
let message = '';
|
|
48
|
+
if (cfg.queryShowAvatarEnable) {
|
|
49
|
+
message += `<img src="${playerInfo.data.avatarUrl}"/>\n`;
|
|
50
|
+
}
|
|
51
|
+
message += '🆔TMP编号: ' + playerInfo.data.tmpId;
|
|
52
|
+
message += '\n😀玩家名称: ' + playerInfo.data.name;
|
|
53
|
+
message += '\n🎮SteamID: ' + playerInfo.data.steamId;
|
|
54
|
+
let registerDate = dayjs(playerInfo.data.registerTime);
|
|
55
|
+
message += '\n📑注册日期: ' + registerDate.format('YYYY年MM月DD日') + ` (${dayjs().diff(registerDate, 'day')}天)`;
|
|
56
|
+
message += '\n💼所属分组: ' + (userGroup[playerInfo.data.groupName] || playerInfo.data.groupName);
|
|
57
|
+
if (playerInfo.data.isJoinVtc) {
|
|
58
|
+
message += '\n🚚所属车队: ' + playerInfo.data.vtcName;
|
|
59
|
+
message += '\n🚚车队角色: ' + playerInfo.data.vtcRole;
|
|
60
|
+
}
|
|
61
|
+
message += '\n🚫是否封禁: ' + (playerInfo.data.isBan ? '是' : '否');
|
|
62
|
+
if (playerInfo.data.isBan) {
|
|
63
|
+
message += '\n🚫封禁截止: ';
|
|
64
|
+
if (playerInfo.data.banHide) {
|
|
65
|
+
message += '隐藏';
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
if (!playerInfo.data.banUntil) {
|
|
69
|
+
message += '永久';
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
message += dayjs(playerInfo.data.banUntil).format('YYYY年MM月DD日 HH:mm');
|
|
73
|
+
}
|
|
74
|
+
message += "\n🚫封禁原因: " + (playerInfo.data.banReasonZh || playerInfo.data.banReason);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
message += '\n🚫封禁次数: ' + (playerInfo.data.banCount || 0);
|
|
78
|
+
if (playerInfo.data.mileage) {
|
|
79
|
+
let mileage = playerInfo.data.mileage;
|
|
80
|
+
let mileageUnit = '米';
|
|
81
|
+
if (mileage > 1000) {
|
|
82
|
+
mileage = (mileage / 1000).toFixed(1);
|
|
83
|
+
mileageUnit = '公里';
|
|
84
|
+
}
|
|
85
|
+
message += '\n🚩历史里程: ' + mileage + mileageUnit;
|
|
86
|
+
}
|
|
87
|
+
if (playerInfo.data.todayMileage) {
|
|
88
|
+
let todayMileage = playerInfo.data.todayMileage;
|
|
89
|
+
let mileageUnit = '米';
|
|
90
|
+
if (todayMileage > 1000) {
|
|
91
|
+
todayMileage = (todayMileage / 1000).toFixed(1);
|
|
92
|
+
mileageUnit = '公里';
|
|
93
|
+
}
|
|
94
|
+
message += '\n🚩今日里程: ' + todayMileage + mileageUnit;
|
|
95
|
+
}
|
|
96
|
+
if (playerMapInfo && !playerMapInfo.error) {
|
|
97
|
+
message += '\n📶在线状态: ' + (playerMapInfo.data.online ? `在线🟢 (${playerMapInfo.data.serverDetails.name})` : '离线⚫');
|
|
98
|
+
if (playerMapInfo.data.online) {
|
|
99
|
+
message += '\n🌍线上位置: ';
|
|
100
|
+
message += await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country);
|
|
101
|
+
message += ' - ';
|
|
102
|
+
message += await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName);
|
|
103
|
+
}
|
|
104
|
+
else if (playerInfo.data.lastOnlineTime) {
|
|
105
|
+
message += '\n📶上次在线: ' + dayjs(playerInfo.data.lastOnlineTime).fromNow(false);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (playerInfo.data.isSponsor) {
|
|
109
|
+
message += '\n🎁赞助用户';
|
|
110
|
+
if (!playerInfo.data.sponsorHide) {
|
|
111
|
+
message += `: \$${Math.floor(playerInfo.data.sponsorAmount / 100)}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (playerInfo.data.sponsorCumulativeAmount) {
|
|
115
|
+
message += '\n🎁累计赞助: $' + Math.floor(playerInfo.data.sponsorCumulativeAmount / 100);
|
|
116
|
+
}
|
|
117
|
+
return message;
|
|
118
|
+
};
|
package/lib/command/tmpServer.js
CHANGED
|
@@ -1 +1,34 @@
|
|
|
1
|
-
const
|
|
1
|
+
const truckersMpApi = require('../api/truckersMpApi');
|
|
2
|
+
const evmOpenApi = require('../api/evmOpenApi');
|
|
3
|
+
module.exports = async (ctx) => {
|
|
4
|
+
// 查询服务器信息
|
|
5
|
+
let serverData = await evmOpenApi.serverList(ctx.http);
|
|
6
|
+
if (serverData.error) {
|
|
7
|
+
return '查询服务器失败,请稍后重试';
|
|
8
|
+
}
|
|
9
|
+
// 构建消息
|
|
10
|
+
let message = '';
|
|
11
|
+
for (let server of serverData.data) {
|
|
12
|
+
// 如果前面有内容,换行
|
|
13
|
+
if (message) {
|
|
14
|
+
message += '\n\n';
|
|
15
|
+
}
|
|
16
|
+
message += '服务器: ' + (server.isOnline === 1 ? '🟢' : '⚫') + server.serverName;
|
|
17
|
+
message += `\n玩家人数: ${server.playerCount}/${server.maxPlayer}`;
|
|
18
|
+
if (server.queue) {
|
|
19
|
+
message += ` (队列: ${server.queueCount})`;
|
|
20
|
+
}
|
|
21
|
+
// 服务器特性
|
|
22
|
+
let characteristicList = [];
|
|
23
|
+
if (!(server.afkEnable === 1)) {
|
|
24
|
+
characteristicList.push('⏱挂机');
|
|
25
|
+
}
|
|
26
|
+
if (server.collisionsEnable === 1) {
|
|
27
|
+
characteristicList.push('💥碰撞');
|
|
28
|
+
}
|
|
29
|
+
if (characteristicList && characteristicList.length > 0) {
|
|
30
|
+
message += '\n服务器特性: ' + characteristicList.join(' ');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return message;
|
|
34
|
+
};
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
const
|
|
1
|
+
const tmpTrafficMap = require("./tmpTrafficMap");
|
|
2
|
+
const tmpTrafficText = require("./tmpTrafficText");
|
|
3
|
+
/**
|
|
4
|
+
* 查询路况
|
|
5
|
+
*/
|
|
6
|
+
module.exports = async (ctx, cfg, serverName) => {
|
|
7
|
+
switch (cfg.tmpTrafficType) {
|
|
8
|
+
case 1:
|
|
9
|
+
return await tmpTrafficText(ctx, cfg, serverName);
|
|
10
|
+
case 2:
|
|
11
|
+
return await tmpTrafficMap(ctx, cfg, serverName);
|
|
12
|
+
default:
|
|
13
|
+
return '指令配置错误';
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -1 +1,119 @@
|
|
|
1
|
-
|
|
1
|
+
const truckyAppApi = require('../../api/truckyAppApi');
|
|
2
|
+
const evmOpenApi = require('../../api/evmOpenApi');
|
|
3
|
+
const baiduTranslate = require('../../util/baiduTranslate');
|
|
4
|
+
const { resolve } = require("path");
|
|
5
|
+
const common = require("../../util/common");
|
|
6
|
+
const { segment } = require("koishi");
|
|
7
|
+
/**
|
|
8
|
+
* 服务器别名
|
|
9
|
+
*/
|
|
10
|
+
const serverAlias = {
|
|
11
|
+
's1': {
|
|
12
|
+
name: 'sim1',
|
|
13
|
+
mapType: 'ets',
|
|
14
|
+
serverId: 2,
|
|
15
|
+
bounds: [[-94189, 93775], [79264, -78999]]
|
|
16
|
+
},
|
|
17
|
+
's2': {
|
|
18
|
+
name: 'sim2',
|
|
19
|
+
mapType: 'ets',
|
|
20
|
+
serverId: 41,
|
|
21
|
+
bounds: [[-94189, 93775], [79264, -78999]]
|
|
22
|
+
},
|
|
23
|
+
'p': {
|
|
24
|
+
name: 'eupromods1',
|
|
25
|
+
mapType: 'promods',
|
|
26
|
+
serverId: 50,
|
|
27
|
+
bounds: [[-96355, 16381], [205581, -70750]]
|
|
28
|
+
},
|
|
29
|
+
'a': {
|
|
30
|
+
name: 'arc1',
|
|
31
|
+
mapType: 'ets',
|
|
32
|
+
serverId: 7,
|
|
33
|
+
bounds: [[-94189, 93775], [79264, -78999]]
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* 路况程度转中文
|
|
38
|
+
*/
|
|
39
|
+
const severityToZh = {
|
|
40
|
+
'Fluid': {
|
|
41
|
+
text: '畅通',
|
|
42
|
+
color: '#00d26a'
|
|
43
|
+
},
|
|
44
|
+
'Moderate': {
|
|
45
|
+
text: '正常',
|
|
46
|
+
color: '#ff6723'
|
|
47
|
+
},
|
|
48
|
+
'Congested': {
|
|
49
|
+
text: '缓慢',
|
|
50
|
+
color: '#f8312f'
|
|
51
|
+
},
|
|
52
|
+
'Heavy': {
|
|
53
|
+
text: '拥堵',
|
|
54
|
+
color: '#8d67c5'
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* 位置类型转中文
|
|
59
|
+
*/
|
|
60
|
+
const typeToZh = {
|
|
61
|
+
'City': '城市',
|
|
62
|
+
'Road': '公路',
|
|
63
|
+
'Intersection': '十字路口'
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 查询路况
|
|
67
|
+
*/
|
|
68
|
+
module.exports = async (ctx, cfg, serverName) => {
|
|
69
|
+
if (!ctx.puppeteer) {
|
|
70
|
+
return '未启用 puppeteer 服务';
|
|
71
|
+
}
|
|
72
|
+
// 根据别名获取服务器信息
|
|
73
|
+
let serverInfo = serverAlias[serverName];
|
|
74
|
+
if (!serverInfo) {
|
|
75
|
+
return '请输入正确的服务器名称 (s1, s2, p, a)';
|
|
76
|
+
}
|
|
77
|
+
// 查询路况信息
|
|
78
|
+
let trafficData = await truckyAppApi.trafficTop(ctx.http, serverInfo.name);
|
|
79
|
+
if (trafficData.error) {
|
|
80
|
+
return '查询路况信息失败';
|
|
81
|
+
}
|
|
82
|
+
// 查询地图玩家数据
|
|
83
|
+
let mapData = await evmOpenApi.mapPlayerList(ctx.http, serverInfo.serverId, serverInfo.bounds[0][0], serverInfo.bounds[0][1], serverInfo.bounds[1][0], serverInfo.bounds[1][1]);
|
|
84
|
+
// 构建路况数据
|
|
85
|
+
let data = {
|
|
86
|
+
mapType: serverInfo.mapType,
|
|
87
|
+
trafficList: [],
|
|
88
|
+
playerCoordinateList: mapData.error && mapData.data ? [] : mapData.data.map(item => [item.axisX, item.axisY])
|
|
89
|
+
};
|
|
90
|
+
for (const traffic of trafficData.data) {
|
|
91
|
+
data.trafficList.push({
|
|
92
|
+
country: await baiduTranslate(ctx, cfg, traffic.country),
|
|
93
|
+
province: await baiduTranslate(ctx, cfg, traffic.name.substring(0, traffic.name.lastIndexOf('(') - 1)),
|
|
94
|
+
playerCount: traffic.players,
|
|
95
|
+
severity: severityToZh[traffic.newSeverity] || { text: '未知', color: '#ffffff' }
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
let page;
|
|
99
|
+
try {
|
|
100
|
+
page = await ctx.puppeteer.page();
|
|
101
|
+
await page.setViewport({ width: 1000, height: 1000 });
|
|
102
|
+
await page.goto(`file:///${resolve(__dirname, '../../resource/traffic.html')}`);
|
|
103
|
+
await page.evaluate(`setData(${JSON.stringify(data)})`);
|
|
104
|
+
await common.sleep(100);
|
|
105
|
+
await page.waitForNetworkIdle();
|
|
106
|
+
const element = await page.$("#container");
|
|
107
|
+
return (segment.image(await element.screenshot({
|
|
108
|
+
encoding: "binary"
|
|
109
|
+
}), "image/jpg"));
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return '渲染异常,请重试';
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
if (page) {
|
|
116
|
+
await page.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
@@ -1 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
const truckyAppApi = require('../../api/truckyAppApi');
|
|
2
|
+
const baiduTranslate = require('../../util/baiduTranslate');
|
|
3
|
+
/**
|
|
4
|
+
* 服务器别名
|
|
5
|
+
*/
|
|
6
|
+
const serverNameAlias = {
|
|
7
|
+
's1': 'sim1',
|
|
8
|
+
's2': 'sim2',
|
|
9
|
+
'p': 'eupromods1',
|
|
10
|
+
'a': 'arc1'
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 路况程度转中文
|
|
14
|
+
*/
|
|
15
|
+
const severityToZh = {
|
|
16
|
+
'Fluid': '🟢畅通',
|
|
17
|
+
'Moderate': '🟠正常',
|
|
18
|
+
'Congested': '🔴缓慢',
|
|
19
|
+
'Heavy': '🟣拥堵'
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 位置类型转中文
|
|
23
|
+
*/
|
|
24
|
+
const typeToZh = {
|
|
25
|
+
'City': '城市',
|
|
26
|
+
'Road': '公路',
|
|
27
|
+
'Intersection': '十字路口'
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 查询路况
|
|
31
|
+
*/
|
|
32
|
+
module.exports = async (ctx, cfg, serverName) => {
|
|
33
|
+
// 转换服务器别名
|
|
34
|
+
let serverQueryName = serverNameAlias[serverName];
|
|
35
|
+
if (!serverQueryName) {
|
|
36
|
+
return '请输入正确的服务器名称 (s1, s2, p, a)';
|
|
37
|
+
}
|
|
38
|
+
let trafficData = await truckyAppApi.trafficTop(ctx.http, serverQueryName);
|
|
39
|
+
if (trafficData.error) {
|
|
40
|
+
return '查询路况信息失败';
|
|
41
|
+
}
|
|
42
|
+
// 构建消息
|
|
43
|
+
let message = '';
|
|
44
|
+
for (const traffic of trafficData.data) {
|
|
45
|
+
// 如果已有内容,换行
|
|
46
|
+
if (message) {
|
|
47
|
+
message += '\n\n';
|
|
48
|
+
}
|
|
49
|
+
message += await baiduTranslate(ctx, cfg, traffic.country);
|
|
50
|
+
message += ' - ';
|
|
51
|
+
let name = traffic.name.substring(0, traffic.name.lastIndexOf('(') - 1);
|
|
52
|
+
let type = traffic.name.substring(traffic.name.lastIndexOf('(') + 1, traffic.name.lastIndexOf(')'));
|
|
53
|
+
message += await baiduTranslate(ctx, cfg, name) + ` (${typeToZh[type] || type})`;
|
|
54
|
+
message += '\n路况: ' + (severityToZh[traffic.newSeverity] || traffic.color);
|
|
55
|
+
message += ' | 人数: ' + traffic.players;
|
|
56
|
+
}
|
|
57
|
+
return message;
|
|
58
|
+
};
|