koishi-plugin-tmp-bot 1.20.0 → 1.20.2
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.js +118 -0
- 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 +53 -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/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 +3 -2
- package/readme.md +14 -13
- package/lib/command/tmpQuery/tmpQuery.d.ts +0 -2
- package/lib/command/tmpQuery/tmpQuery.js +0 -1
- package/lib/command/tmpQuery/tmpQueryImg.d.ts +0 -3
- package/lib/command/tmpQuery/tmpQueryImg.js +0 -1
- package/lib/command/tmpQuery/tmpQueryText.js +0 -1
- package/lib/resource/query.html +0 -227
- /package/lib/command/{tmpQuery/tmpQueryText.d.ts → tmpQuery.d.ts} +0 -0
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
};
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
const truckersMpApi = require("../api/truckersMpApi");
|
|
2
|
+
module.exports = async (ctx) => {
|
|
3
|
+
// 查询版本信息
|
|
4
|
+
let result = await truckersMpApi.version(ctx.http);
|
|
5
|
+
if (result.error) {
|
|
6
|
+
return '查询失败,请稍后再试';
|
|
7
|
+
}
|
|
8
|
+
// 构建消息返回
|
|
9
|
+
let message = '';
|
|
10
|
+
message += `TMP版本:${result.data.name}\n`;
|
|
11
|
+
message += `欧卡支持版本: ${result.data.supported_game_version}\n`;
|
|
12
|
+
message += `美卡支持版本: ${result.data.supported_ats_game_version}`;
|
|
13
|
+
return message;
|
|
14
|
+
};
|
|
@@ -1 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports = {
|
|
2
|
+
/**
|
|
3
|
+
* 获取绑定信息
|
|
4
|
+
* @param db 数据源
|
|
5
|
+
* @param platform 平台
|
|
6
|
+
* @param userId 用户编号
|
|
7
|
+
*/
|
|
8
|
+
async get(db, platform, userId) {
|
|
9
|
+
const guildBindList = await db.get('tmp_guild_bind', {
|
|
10
|
+
platform,
|
|
11
|
+
user_id: userId
|
|
12
|
+
});
|
|
13
|
+
if (guildBindList && guildBindList.length > 0) {
|
|
14
|
+
return guildBindList[0];
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
},
|
|
18
|
+
/**
|
|
19
|
+
* 新增或更新绑定信息
|
|
20
|
+
* @param db 数据源
|
|
21
|
+
* @param platform 平台
|
|
22
|
+
* @param userId 用户编号
|
|
23
|
+
* @param tmpId TMP ID
|
|
24
|
+
*/
|
|
25
|
+
saveOrUpdate(db, platform, userId, tmpId) {
|
|
26
|
+
this.get(db, platform, userId).then((data) => {
|
|
27
|
+
if (data) {
|
|
28
|
+
db.set('tmp_guild_bind', data.id, {
|
|
29
|
+
tmp_id: tmpId
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
db.create('tmp_guild_bind', {
|
|
34
|
+
platform: platform,
|
|
35
|
+
user_id: userId,
|
|
36
|
+
tmp_id: tmpId
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
package/lib/database/model.js
CHANGED
|
@@ -1 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 数据表声明
|
|
3
|
+
*/
|
|
4
|
+
const modelArray = {
|
|
5
|
+
tmp_guild_bind: {
|
|
6
|
+
id: {
|
|
7
|
+
type: 'unsigned',
|
|
8
|
+
length: 10,
|
|
9
|
+
nullable: false,
|
|
10
|
+
comment: '主键'
|
|
11
|
+
},
|
|
12
|
+
platform: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
length: 50,
|
|
15
|
+
nullable: false,
|
|
16
|
+
comment: '所属平台'
|
|
17
|
+
},
|
|
18
|
+
user_id: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
length: 50,
|
|
21
|
+
nullable: false,
|
|
22
|
+
comment: '用户编号'
|
|
23
|
+
},
|
|
24
|
+
tmp_id: {
|
|
25
|
+
type: 'unsigned',
|
|
26
|
+
length: 50,
|
|
27
|
+
nullable: false,
|
|
28
|
+
comment: 'TMP ID'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
tmp_translate_cache: {
|
|
32
|
+
id: {
|
|
33
|
+
type: 'unsigned',
|
|
34
|
+
length: 10,
|
|
35
|
+
nullable: false,
|
|
36
|
+
comment: '主键'
|
|
37
|
+
},
|
|
38
|
+
content: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
nullable: false,
|
|
41
|
+
length: 200,
|
|
42
|
+
comment: '原文文本'
|
|
43
|
+
},
|
|
44
|
+
content_md5: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
nullable: false,
|
|
47
|
+
length: 32,
|
|
48
|
+
comment: '原文文本md5'
|
|
49
|
+
},
|
|
50
|
+
translate_content: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
nullable: false,
|
|
53
|
+
length: 200,
|
|
54
|
+
comment: '翻译文本'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 初始化数据库
|
|
60
|
+
*/
|
|
61
|
+
module.exports = (ctx) => {
|
|
62
|
+
for (let modelName in modelArray) {
|
|
63
|
+
ctx.model.extend(modelName, modelArray[modelName], { autoInc: true });
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports = {
|
|
2
|
+
/**
|
|
3
|
+
* 查询翻译
|
|
4
|
+
* @param db 数据源
|
|
5
|
+
* @param contentMd5 文本MD5
|
|
6
|
+
*/
|
|
7
|
+
async getTranslate(db, contentMd5) {
|
|
8
|
+
const translateCacheList = await db.get('tmp_translate_cache', {
|
|
9
|
+
content_md5: contentMd5
|
|
10
|
+
});
|
|
11
|
+
// 如果查询到了缓存,直接返回翻译文本
|
|
12
|
+
if (translateCacheList && translateCacheList.length > 0) {
|
|
13
|
+
return translateCacheList[0].translate_content;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
},
|
|
17
|
+
/**
|
|
18
|
+
* 保存翻译缓存信息
|
|
19
|
+
* @param db 数据源
|
|
20
|
+
* @param contentMd5 原文文本MD5
|
|
21
|
+
* @param content 原文文本
|
|
22
|
+
* @param translateContent 翻译文本
|
|
23
|
+
*/
|
|
24
|
+
save(db, contentMd5, content, translateContent) {
|
|
25
|
+
db.create('tmp_translate_cache', {
|
|
26
|
+
content,
|
|
27
|
+
content_md5: contentMd5,
|
|
28
|
+
translate_content: translateContent
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|