koishi-plugin-lutu 1.0.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.
- package/lib/api/evmOpenApi.d.ts +33 -0
- package/lib/api/evmOpenApi.js +114 -0
- package/lib/api/truckersMpApi.d.ts +34 -0
- package/lib/api/truckersMpApi.js +133 -0
- package/lib/api/truckersMpMapApi.d.ts +6 -0
- package/lib/api/truckersMpMapApi.js +25 -0
- package/lib/api/truckyAppApi.d.ts +12 -0
- package/lib/api/truckyAppApi.js +48 -0
- package/lib/command/ets-app/queryPoint.js +74 -0
- package/lib/command/ets-app/resetPassword.js +111 -0
- package/lib/command/tmpActivityService.js +603 -0
- package/lib/command/tmpBind.d.ts +2 -0
- package/lib/command/tmpBind.js +18 -0
- package/lib/command/tmpDlcMap.d.ts +3 -0
- package/lib/command/tmpDlcMap.js +33 -0
- package/lib/command/tmpMileageRanking.d.ts +3 -0
- package/lib/command/tmpMileageRanking.js +55 -0
- package/lib/command/tmpPosition.d.ts +3 -0
- package/lib/command/tmpPosition.js +107 -0
- package/lib/command/tmpQuery/tmpQuery.d.ts +2 -0
- package/lib/command/tmpQuery/tmpQuery.js +12 -0
- package/lib/command/tmpQuery/tmpQueryImg.d.ts +3 -0
- package/lib/command/tmpQuery/tmpQueryImg.js +103 -0
- package/lib/command/tmpQuery/tmpQueryText.d.ts +2 -0
- package/lib/command/tmpQuery/tmpQueryText.js +175 -0
- package/lib/command/tmpServer.d.ts +2 -0
- package/lib/command/tmpServer.js +41 -0
- package/lib/command/tmpTraffic/tmpTraffic.d.ts +2 -0
- package/lib/command/tmpTraffic/tmpTraffic.js +15 -0
- package/lib/command/tmpTraffic/tmpTrafficMap.d.ts +3 -0
- package/lib/command/tmpTraffic/tmpTrafficMap.js +163 -0
- package/lib/command/tmpTraffic/tmpTrafficText.d.ts +2 -0
- package/lib/command/tmpTraffic/tmpTrafficText.js +60 -0
- package/lib/command/tmpVersion.d.ts +2 -0
- package/lib/command/tmpVersion.js +14 -0
- package/lib/command/tmpVtc.js +29 -0
- package/lib/database/guildBind.d.ts +15 -0
- package/lib/database/guildBind.js +41 -0
- package/lib/database/model.d.ts +2 -0
- package/lib/database/model.js +65 -0
- package/lib/database/translateCache.d.ts +14 -0
- package/lib/database/translateCache.js +31 -0
- package/lib/index.d.ts +35 -0
- package/lib/index.js +276 -0
- package/lib/resource/dlc.html +115 -0
- package/lib/resource/mileage-leaderboard.html +363 -0
- package/lib/resource/package/SEGUIEMJ.TTF +0 -0
- package/lib/resource/package/leaflet/heatmap.min.js +9 -0
- package/lib/resource/package/leaflet/leaflet-heatmap.js +246 -0
- package/lib/resource/package/leaflet/leaflet.min.css +1 -0
- package/lib/resource/package/leaflet/leaflet.min.js +1 -0
- package/lib/resource/position.html +223 -0
- package/lib/resource/query.html +363 -0
- package/lib/resource/traffic.html +207 -0
- package/lib/util/baiduTranslate.d.ts +2 -0
- package/lib/util/baiduTranslate.js +30 -0
- package/lib/util/common.d.ts +1 -0
- package/lib/util/common.js +5 -0
- package/lib/util/constant.d.ts +8 -0
- package/lib/util/constant.js +16 -0
- package/package.json +41 -0
- package/readme.md +143 -0
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
switch (serverName) {
|
|
86
|
+
case 's1':
|
|
87
|
+
case 's2':
|
|
88
|
+
case 'a': {
|
|
89
|
+
let data = {
|
|
90
|
+
mapType: serverInfo.mapType,
|
|
91
|
+
trafficList: [],
|
|
92
|
+
playerCoordinateList: mapData.error && mapData.data ? [] : mapData.data.map(item => [item.axisX, item.axisY])
|
|
93
|
+
};
|
|
94
|
+
for (const traffic of trafficData.data) {
|
|
95
|
+
data.trafficList.push({
|
|
96
|
+
country: await baiduTranslate(ctx, cfg, traffic.country),
|
|
97
|
+
province: await baiduTranslate(ctx, cfg, traffic.name.substring(0, traffic.name.lastIndexOf('(') - 1)),
|
|
98
|
+
playerCount: traffic.players,
|
|
99
|
+
severity: severityToZh[traffic.newSeverity] || { text: '未知', color: '#ffffff' }
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
let page;
|
|
103
|
+
try {
|
|
104
|
+
page = await ctx.puppeteer.page();
|
|
105
|
+
await page.setViewport({ width: 1000, height: 1000 });
|
|
106
|
+
await page.goto(`file:///${resolve(__dirname, '../../resource/traffic.html')}`);
|
|
107
|
+
await page.evaluate(`setData(${JSON.stringify(data)})`);
|
|
108
|
+
await common.sleep(100);
|
|
109
|
+
await page.waitForNetworkIdle();
|
|
110
|
+
const element = await page.$("#container");
|
|
111
|
+
return (segment.image(await element.screenshot({
|
|
112
|
+
encoding: "binary"
|
|
113
|
+
}), "image/jpg"));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return '渲染异常,请重试';
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
if (page) {
|
|
120
|
+
await page.close();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case 'p': {
|
|
126
|
+
let data = {
|
|
127
|
+
mapType: serverInfo.mapType,
|
|
128
|
+
trafficList: [],
|
|
129
|
+
playerCoordinateList: mapData.error && mapData.data ? [] : mapData.data.map(item => [item.axisX, item.axisY])
|
|
130
|
+
};
|
|
131
|
+
for (const traffic of trafficData.data) {
|
|
132
|
+
data.trafficList.push({
|
|
133
|
+
country: await baiduTranslate(ctx, cfg, traffic.country),
|
|
134
|
+
province: await baiduTranslate(ctx, cfg, traffic.name.substring(0, traffic.name.lastIndexOf('(') - 1)),
|
|
135
|
+
playerCount: traffic.players,
|
|
136
|
+
severity: severityToZh[traffic.newSeverity] || { text: '未知', color: '#ffffff' }
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
let page;
|
|
140
|
+
try {
|
|
141
|
+
page = await ctx.puppeteer.page();
|
|
142
|
+
await page.setViewport({ width: 1200, height: 1200 });
|
|
143
|
+
await page.goto(`file:///${resolve(__dirname, '../../resource/traffic.html')}`);
|
|
144
|
+
await page.evaluate(`setData(${JSON.stringify(data)})`);
|
|
145
|
+
await common.sleep(100);
|
|
146
|
+
await page.waitForNetworkIdle();
|
|
147
|
+
const element = await page.$("#container");
|
|
148
|
+
return (segment.image(await element.screenshot({
|
|
149
|
+
encoding: "binary"
|
|
150
|
+
}), "image/jpg"));
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return '渲染异常,请重试';
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
if (page) {
|
|
157
|
+
await page.close();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
'S1': 'sim1',
|
|
12
|
+
'S2': 'sim2',
|
|
13
|
+
'P': 'eupromods1',
|
|
14
|
+
'A': 'arc1'
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 路况程度转中文
|
|
18
|
+
*/
|
|
19
|
+
const severityToZh = {
|
|
20
|
+
'Fluid': '🟢畅通',
|
|
21
|
+
'Moderate': '🟠正常',
|
|
22
|
+
'Congested': '🔴缓慢',
|
|
23
|
+
'Heavy': '🟣拥堵'
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 位置类型转中文
|
|
27
|
+
*/
|
|
28
|
+
const typeToZh = {
|
|
29
|
+
'City': '城市',
|
|
30
|
+
'Road': '公路',
|
|
31
|
+
'Intersection': '十字路口'
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 查询路况
|
|
35
|
+
*/
|
|
36
|
+
module.exports = async (ctx, cfg, serverName) => {
|
|
37
|
+
let serverQueryName = serverNameAlias[serverName];
|
|
38
|
+
if (!serverQueryName) {
|
|
39
|
+
return '请输入正确的服务器名称 (s1, s2, p, a)';
|
|
40
|
+
}
|
|
41
|
+
let trafficData = await truckyAppApi.trafficTop(ctx.http, serverQueryName);
|
|
42
|
+
if (trafficData.error) {
|
|
43
|
+
return '查询路况信息失败';
|
|
44
|
+
}
|
|
45
|
+
// 构建消息
|
|
46
|
+
let message = '';
|
|
47
|
+
for (const traffic of trafficData.data) {
|
|
48
|
+
if (message) {
|
|
49
|
+
message += '\n\n';
|
|
50
|
+
}
|
|
51
|
+
message += await baiduTranslate(ctx, cfg, traffic.country);
|
|
52
|
+
message += ' - ';
|
|
53
|
+
let name = traffic.name.substring(0, traffic.name.lastIndexOf('(') - 1);
|
|
54
|
+
let type = traffic.name.substring(traffic.name.lastIndexOf('(') + 1, traffic.name.lastIndexOf(')'));
|
|
55
|
+
message += await baiduTranslate(ctx, cfg, name) + ` (${typeToZh[type] || type})`;
|
|
56
|
+
message += '\n路况: ' + (severityToZh[traffic.newSeverity] || traffic.color);
|
|
57
|
+
message += ' | 人数: ' + traffic.players;
|
|
58
|
+
}
|
|
59
|
+
return message;
|
|
60
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const truckersMpApi = require('../api/truckersMpApi')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 查询玩家信息
|
|
5
|
+
*/
|
|
6
|
+
module.exports = async (ctx, cfg, session, vtcid) => {
|
|
7
|
+
if (!vtcid || isNaN(vtcid)) {
|
|
8
|
+
return `请输入正确的vtc编号`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 查询玩家信息
|
|
12
|
+
let vtcInfo = await truckersMpApi.vtc(ctx.http, vtcid)
|
|
13
|
+
if (vtcInfo.error) {
|
|
14
|
+
return '查询vtc信息失败,请重试'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 拼接消息模板
|
|
18
|
+
let message = ''
|
|
19
|
+
message += `<img src="${vtcInfo.data.logo}"/>\n`
|
|
20
|
+
message += '🆔VTC编号: ' + vtcInfo.data.id
|
|
21
|
+
message += '\n📑VTC名称: ' + vtcInfo.data.name
|
|
22
|
+
message += '\n📑VTC所有者id: ' + vtcInfo.data.owner_id
|
|
23
|
+
message += '\n📑VTC所有者名称: ' + vtcInfo.data.owner_username
|
|
24
|
+
message += '\n📑VTC创建日期: ' + vtcInfo.data.created + `(UTC)`
|
|
25
|
+
message += '\n🎮VTC人数: ' + vtcInfo.data.members_count
|
|
26
|
+
message += '\n🎮VTC前缀: ' + vtcInfo.data.tag
|
|
27
|
+
message += `\n💼VTC主页: ${vtcInfo.data.website}`
|
|
28
|
+
return message
|
|
29
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 查询翻译
|
|
3
|
+
* @param db 数据源
|
|
4
|
+
* @param contentMd5 文本MD5
|
|
5
|
+
*/
|
|
6
|
+
export function getTranslate(db: any, contentMd5: any): Promise<any>;
|
|
7
|
+
/**
|
|
8
|
+
* 保存翻译缓存信息
|
|
9
|
+
* @param db 数据源
|
|
10
|
+
* @param contentMd5 原文文本MD5
|
|
11
|
+
* @param content 原文文本
|
|
12
|
+
* @param translateContent 翻译文本
|
|
13
|
+
*/
|
|
14
|
+
export function save(db: any, contentMd5: any, content: any, translateContent: any): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "tmp-bot";
|
|
3
|
+
export declare const inject: {
|
|
4
|
+
required: string[];
|
|
5
|
+
optional: string[];
|
|
6
|
+
};
|
|
7
|
+
export interface Config {
|
|
8
|
+
baiduTranslateEnable: boolean;
|
|
9
|
+
baiduTranslateAppId: string;
|
|
10
|
+
baiduTranslateKey: string;
|
|
11
|
+
baiduTranslateCacheEnable: boolean;
|
|
12
|
+
adminUseHttps: boolean;
|
|
13
|
+
adminApiUrl: string;
|
|
14
|
+
adminApiToken: string;
|
|
15
|
+
adminVtcId: string;
|
|
16
|
+
adminCheckTimes: string[];
|
|
17
|
+
adminSendTimes: string[];
|
|
18
|
+
adminGroups: string[];
|
|
19
|
+
adminServerSource: string;
|
|
20
|
+
adminStartPointSource: string;
|
|
21
|
+
adminEndPointSource: string;
|
|
22
|
+
adminShowBanner: boolean;
|
|
23
|
+
adminProfileUploadedMessage: string;
|
|
24
|
+
adminProfileNotUploadedMessage: string;
|
|
25
|
+
mainGroups: string[];
|
|
26
|
+
mainActivityReminderMessage: string;
|
|
27
|
+
mainActivityReminderTimes: number[];
|
|
28
|
+
debugMode: boolean;
|
|
29
|
+
logApiResponses: boolean;
|
|
30
|
+
logTimingDetails: boolean;
|
|
31
|
+
logActivityMatching: boolean;
|
|
32
|
+
logMessageSending: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare const Config: Schema<Config>;
|
|
35
|
+
export declare function apply(ctx: Context, cfg: Config): void;
|