koishi-plugin-tmp-bot 1.16.3 → 1.16.4

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.
Files changed (46) hide show
  1. package/lib/api/evmOpenApi.d.ts +18 -0
  2. package/lib/api/evmOpenApi.js +67 -69
  3. package/lib/api/truckersMpApi.d.ts +34 -0
  4. package/lib/api/truckersMpApi.js +108 -113
  5. package/lib/api/truckersMpMapApi.d.ts +6 -0
  6. package/lib/api/truckersMpMapApi.js +23 -24
  7. package/lib/api/truckyAppApi.d.ts +12 -0
  8. package/lib/api/truckyAppApi.js +46 -47
  9. package/lib/command/tmpBind.d.ts +2 -0
  10. package/lib/command/tmpBind.js +13 -17
  11. package/lib/command/tmpDlcMap.d.ts +3 -0
  12. package/lib/command/tmpDlcMap.js +27 -29
  13. package/lib/command/tmpPosition.d.ts +3 -0
  14. package/lib/command/tmpPosition.js +90 -101
  15. package/lib/command/tmpQuery/tmpQuery.d.ts +2 -0
  16. package/lib/command/tmpQuery/tmpQuery.js +9 -10
  17. package/lib/command/tmpQuery/tmpQueryImg.d.ts +3 -0
  18. package/lib/command/tmpQuery/tmpQueryImg.js +88 -96
  19. package/lib/command/tmpQuery/tmpQueryText.d.ts +2 -0
  20. package/lib/command/tmpQuery/tmpQueryText.js +78 -82
  21. package/lib/command/tmpServer.d.ts +2 -0
  22. package/lib/command/tmpServer.js +31 -34
  23. package/lib/command/tmpTraffic/tmpTraffic.d.ts +2 -0
  24. package/lib/command/tmpTraffic/tmpTraffic.js +9 -10
  25. package/lib/command/tmpTraffic/tmpTrafficMap.d.ts +3 -0
  26. package/lib/command/tmpTraffic/tmpTrafficMap.js +101 -110
  27. package/lib/command/tmpTraffic/tmpTrafficText.d.ts +2 -0
  28. package/lib/command/tmpTraffic/tmpTrafficText.js +41 -49
  29. package/lib/command/tmpVersion.d.ts +2 -0
  30. package/lib/command/tmpVersion.js +12 -14
  31. package/lib/database/guildBind.d.ts +15 -0
  32. package/lib/database/guildBind.js +39 -40
  33. package/lib/database/model.d.ts +2 -0
  34. package/lib/database/model.js +55 -56
  35. package/lib/database/translateCache.d.ts +14 -0
  36. package/lib/database/translateCache.js +29 -31
  37. package/lib/resource/package/leaflet/heatmap.min.js +9 -0
  38. package/lib/resource/package/leaflet/leaflet-heatmap.js +246 -0
  39. package/lib/resource/package/leaflet/leaflet.min.js +1 -0
  40. package/lib/util/baiduTranslate.d.ts +2 -0
  41. package/lib/util/baiduTranslate.js +28 -35
  42. package/lib/util/common.d.ts +1 -0
  43. package/lib/util/common.js +4 -4
  44. package/lib/util/constant.d.ts +4 -0
  45. package/lib/util/constant.js +8 -8
  46. package/package.json +1 -1
@@ -1,37 +1,34 @@
1
- const truckersMpApi = require('../api/truckersMpApi')
2
- const evmOpenApi = require('../api/evmOpenApi')
3
-
1
+ const truckersMpApi = require('../api/truckersMpApi');
2
+ const evmOpenApi = require('../api/evmOpenApi');
4
3
  module.exports = async (ctx) => {
5
- // 查询服务器信息
6
- let serverData = await evmOpenApi.serverList(ctx.http)
7
- if (serverData.error) {
8
- return '查询服务器失败,请稍后重试'
9
- }
10
-
11
- // 构建消息
12
- let message = ''
13
- for (let server of serverData.data) {
14
- // 如果前面有内容,换行
15
- if (message) {
16
- message += '\n\n'
4
+ // 查询服务器信息
5
+ let serverData = await evmOpenApi.serverList(ctx.http);
6
+ if (serverData.error) {
7
+ return '查询服务器失败,请稍后重试';
17
8
  }
18
-
19
- message += '服务器: ' + ( server.isOnline === 1 ? '🟢' : '⚫' ) + server.serverName
20
- message += `\n玩家人数: ${server.playerCount}/${server.maxPlayer}`
21
- if (server.queue) {
22
- message += ` (队列: ${server.queueCount})`
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
+ }
23
32
  }
24
- // 服务器特性
25
- let characteristicList = []
26
- if (!(server.afkEnable === 1)) {
27
- characteristicList.push('⏱挂机')
28
- }
29
- if (server.collisionsEnable === 1) {
30
- characteristicList.push('💥碰撞')
31
- }
32
- if (characteristicList && characteristicList.length > 0) {
33
- message += '\n服务器特性: ' + characteristicList.join(' ')
34
- }
35
- }
36
- return message
37
- }
33
+ return message;
34
+ };
@@ -0,0 +1,2 @@
1
+ declare function _exports(ctx: any, cfg: any, serverName: any): Promise<string | import("koishi").Element>;
2
+ export = _exports;
@@ -1,16 +1,15 @@
1
1
  const tmpTrafficMap = require("./tmpTrafficMap");
2
2
  const tmpTrafficText = require("./tmpTrafficText");
3
-
4
3
  /**
5
4
  * 查询路况
6
5
  */
7
6
  module.exports = async (ctx, cfg, serverName) => {
8
- switch (cfg.tmpTrafficType) {
9
- case 1:
10
- return await tmpTrafficText(ctx, cfg, serverName)
11
- case 2:
12
- return await tmpTrafficMap(ctx, cfg, serverName)
13
- default:
14
- return '指令配置错误'
15
- }
16
- }
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
+ };
@@ -0,0 +1,3 @@
1
+ declare function _exports(ctx: any, cfg: any, serverName: any): Promise<segment | "渲染异常,请重试" | "未启用 puppeteer 服务" | "请输入正确的服务器名称 (s1, s2, p, a)" | "查询路况信息失败">;
2
+ export = _exports;
3
+ import { segment } from "@koishijs/core";
@@ -1,128 +1,119 @@
1
- const truckyAppApi = require('../../api/truckyAppApi')
2
- const evmOpenApi = require('../../api/evmOpenApi')
3
- const baiduTranslate = require('../../util/baiduTranslate')
4
- const {resolve} = require("path");
1
+ const truckyAppApi = require('../../api/truckyAppApi');
2
+ const evmOpenApi = require('../../api/evmOpenApi');
3
+ const baiduTranslate = require('../../util/baiduTranslate');
4
+ const { resolve } = require("path");
5
5
  const common = require("../../util/common");
6
- const {segment} = require("koishi");
7
-
6
+ const { segment } = require("koishi");
8
7
  /**
9
8
  * 服务器别名
10
9
  */
11
10
  const serverAlias = {
12
- 's1': {
13
- name: 'sim1',
14
- mapType: 'ets',
15
- serverId: 2,
16
- bounds: [[-94189, 93775], [79264, -78999]]
17
- },
18
- 's2': {
19
- name: 'sim2',
20
- mapType: 'ets',
21
- serverId: 41,
22
- bounds: [[-94189, 93775], [79264, -78999]]
23
- },
24
- 'p': {
25
- name: 'eupromods1',
26
- mapType: 'promods',
27
- serverId: 50,
28
- bounds: [[-96355, 16381], [205581, -70750]]
29
- },
30
- 'a': {
31
- name: 'arc1',
32
- mapType: 'ets',
33
- serverId: 7,
34
- bounds: [[-94189, 93775], [79264, -78999]]
35
- }
36
- }
37
-
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
+ };
38
36
  /**
39
37
  * 路况程度转中文
40
38
  */
41
39
  const severityToZh = {
42
- 'Fluid': {
43
- text: '畅通',
44
- color: '#00d26a'
45
- },
46
- 'Moderate': {
47
- text: '正常',
48
- color: '#ff6723'
49
- },
50
- 'Congested': {
51
- text: '缓慢',
52
- color: '#f8312f'
53
- },
54
- 'Heavy': {
55
- text: '拥堵',
56
- color: '#8d67c5'
57
- }
58
- }
59
-
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
+ };
60
57
  /**
61
58
  * 位置类型转中文
62
59
  */
63
60
  const typeToZh = {
64
- 'City': '城市',
65
- 'Road': '公路',
66
- 'Intersection': '十字路口'
67
- }
68
-
61
+ 'City': '城市',
62
+ 'Road': '公路',
63
+ 'Intersection': '十字路口'
64
+ };
69
65
  /**
70
66
  * 查询路况
71
67
  */
72
68
  module.exports = async (ctx, cfg, serverName) => {
73
- if (!ctx.puppeteer) {
74
- return '未启用 puppeteer 服务'
75
- }
76
-
77
- // 根据别名获取服务器信息
78
- let serverInfo = serverAlias[serverName]
79
- if (!serverInfo) {
80
- return '请输入正确的服务器名称 (s1, s2, p, a)'
81
- }
82
-
83
- // 查询路况信息
84
- let trafficData = await truckyAppApi.trafficTop(ctx.http, serverInfo.name)
85
- if (trafficData.error) {
86
- return '查询路况信息失败'
87
- }
88
-
89
- // 查询地图玩家数据
90
- 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])
91
-
92
- // 构建路况数据
93
- let data = {
94
- mapType: serverInfo.mapType,
95
- trafficList: [],
96
- playerCoordinateList: mapData.error && mapData.data ? [] : mapData.data.map(item => [item.axisX, item.axisY])
97
- }
98
- for (const traffic of trafficData.data) {
99
- data.trafficList.push({
100
- country: await baiduTranslate(ctx, cfg, traffic.country),
101
- province: await baiduTranslate(ctx, cfg, traffic.name.substring(0, traffic.name.lastIndexOf('(') - 1)),
102
- playerCount: traffic.players,
103
- severity: severityToZh[traffic.newSeverity] || { text: '未知', color: '#ffffff' }
104
- })
105
- }
106
-
107
- let page
108
- try {
109
- page = await ctx.puppeteer.page()
110
- await page.setViewport({ width: 1000, height: 1000 })
111
- await page.goto(`file:///${resolve(__dirname, '../../resource/traffic.html')}`)
112
- await page.evaluate(`setData(${JSON.stringify(data)})`)
113
- await common.sleep(100)
114
- await page.waitForNetworkIdle()
115
- const element = await page.$("#container");
116
- return (
117
- segment.image(await element.screenshot({
118
- encoding: "binary"
119
- }), "image/jpg")
120
- )
121
- } catch {
122
- return '渲染异常,请重试'
123
- } finally {
124
- if (page) {
125
- await page.close()
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
+ }
126
118
  }
127
- }
128
- }
119
+ };
@@ -0,0 +1,2 @@
1
+ declare function _exports(ctx: any, cfg: any, serverName: any): Promise<string>;
2
+ export = _exports;
@@ -1,66 +1,58 @@
1
- const truckyAppApi = require('../../api/truckyAppApi')
2
- const baiduTranslate = require('../../util/baiduTranslate')
3
-
1
+ const truckyAppApi = require('../../api/truckyAppApi');
2
+ const baiduTranslate = require('../../util/baiduTranslate');
4
3
  /**
5
4
  * 服务器别名
6
5
  */
7
6
  const serverNameAlias = {
8
- 's1': 'sim1',
9
- 's2': 'sim2',
10
- 'p': 'eupromods1',
11
- 'a': 'arc1'
12
- }
13
-
7
+ 's1': 'sim1',
8
+ 's2': 'sim2',
9
+ 'p': 'eupromods1',
10
+ 'a': 'arc1'
11
+ };
14
12
  /**
15
13
  * 路况程度转中文
16
14
  */
17
15
  const severityToZh = {
18
- 'Fluid': '🟢畅通',
19
- 'Moderate': '🟠正常',
20
- 'Congested': '🔴缓慢',
21
- 'Heavy': '🟣拥堵'
22
- }
23
-
16
+ 'Fluid': '🟢畅通',
17
+ 'Moderate': '🟠正常',
18
+ 'Congested': '🔴缓慢',
19
+ 'Heavy': '🟣拥堵'
20
+ };
24
21
  /**
25
22
  * 位置类型转中文
26
23
  */
27
24
  const typeToZh = {
28
- 'City': '城市',
29
- 'Road': '公路',
30
- 'Intersection': '十字路口'
31
- }
32
-
25
+ 'City': '城市',
26
+ 'Road': '公路',
27
+ 'Intersection': '十字路口'
28
+ };
33
29
  /**
34
30
  * 查询路况
35
31
  */
36
32
  module.exports = async (ctx, cfg, serverName) => {
37
- // 转换服务器别名
38
- let serverQueryName = serverNameAlias[serverName]
39
- if (!serverQueryName) {
40
- return '请输入正确的服务器名称 (s1, s2, p, a)'
41
- }
42
-
43
- let trafficData = await truckyAppApi.trafficTop(ctx.http, serverQueryName)
44
- if (trafficData.error) {
45
- return '查询路况信息失败'
46
- }
47
-
48
- // 构建消息
49
- let message = ''
50
- for (const traffic of trafficData.data) {
51
- // 如果已有内容,换行
52
- if (message) {
53
- message += '\n\n'
33
+ // 转换服务器别名
34
+ let serverQueryName = serverNameAlias[serverName];
35
+ if (!serverQueryName) {
36
+ return '请输入正确的服务器名称 (s1, s2, p, a)';
54
37
  }
55
-
56
- message += await baiduTranslate(ctx, cfg, traffic.country)
57
- message += ' - '
58
- let name = traffic.name.substring(0, traffic.name.lastIndexOf('(') - 1)
59
- let type = traffic.name.substring(traffic.name.lastIndexOf('(') + 1, traffic.name.lastIndexOf(')'))
60
- message += await baiduTranslate(ctx, cfg, name) + ` (${typeToZh[type] || type})`
61
- message += '\n路况: ' + (severityToZh[traffic.newSeverity] || traffic.color)
62
- message += ' | 人数: ' + traffic.players
63
- }
64
-
65
- return message
66
- }
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
+ };
@@ -0,0 +1,2 @@
1
+ declare function _exports(ctx: any): Promise<string>;
2
+ export = _exports;
@@ -1,16 +1,14 @@
1
1
  const truckersMpApi = require("../api/truckersMpApi");
2
-
3
2
  module.exports = async (ctx) => {
4
- // 查询版本信息
5
- let result = await truckersMpApi.version(ctx.http)
6
- if (result.error) {
7
- return '查询失败,请稍后再试'
8
- }
9
-
10
- // 构建消息返回
11
- let message = ''
12
- message += `TMP版本:${result.data.name}\n`;
13
- message += `欧卡支持版本: ${result.data.supported_game_version}\n`;
14
- message += `美卡支持版本: ${result.data.supported_ats_game_version}`;
15
- return message
16
- }
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
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 获取绑定信息
3
+ * @param db 数据源
4
+ * @param platform 平台
5
+ * @param userId 用户编号
6
+ */
7
+ export function get(db: any, platform: any, userId: any): Promise<any>;
8
+ /**
9
+ * 新增或更新绑定信息
10
+ * @param db 数据源
11
+ * @param platform 平台
12
+ * @param userId 用户编号
13
+ * @param tmpId TMP ID
14
+ */
15
+ export function saveOrUpdate(db: any, platform: any, userId: any, tmpId: any): void;
@@ -1,42 +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
-
14
- if (guildBindList && guildBindList.length > 0) {
15
- return guildBindList[0]
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
+ });
16
40
  }
17
-
18
- return null
19
- },
20
- /**
21
- * 新增或更新绑定信息
22
- * @param db 数据源
23
- * @param platform 平台
24
- * @param userId 用户编号
25
- * @param tmpId TMP ID
26
- */
27
- saveOrUpdate (db, platform, userId, tmpId) {
28
- this.get(db, platform, userId).then((data) => {
29
- if (data) {
30
- db.set('tmp_guild_bind', data.id, {
31
- tmp_id: tmpId
32
- })
33
- } else {
34
- db.create('tmp_guild_bind', {
35
- platform: platform,
36
- user_id: userId,
37
- tmp_id: tmpId
38
- })
39
- }
40
- })
41
- }
42
- }
41
+ };
@@ -0,0 +1,2 @@
1
+ declare function _exports(ctx: any): void;
2
+ export = _exports;