koishi-plugin-tmp-bot 1.3.1 → 1.3.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/{TruckersMpApi.js → truckersMpApi.js} +23 -0
- package/lib/command/tmpBind.js +1 -1
- package/lib/command/tmpPosition.js +1 -1
- package/lib/command/tmpQuery.js +14 -5
- package/lib/command/tmpServer.js +1 -1
- package/lib/command/tmpTraffic.js +0 -1
- package/lib/util/baiduTranslate.js +3 -3
- package/package.json +1 -1
|
@@ -45,6 +45,29 @@ module.exports = {
|
|
|
45
45
|
data.data = result.response
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
return data
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* 查询玩家封禁信息
|
|
52
|
+
*/
|
|
53
|
+
async bans (http, tmpId) {
|
|
54
|
+
let result = null
|
|
55
|
+
try {
|
|
56
|
+
result = await http.get(`${BASE_API}/bans/${tmpId}`)
|
|
57
|
+
} catch {
|
|
58
|
+
return {
|
|
59
|
+
error: true
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 拼接返回数据
|
|
64
|
+
let data = {
|
|
65
|
+
error: JSON.parse(result.error)
|
|
66
|
+
}
|
|
67
|
+
if (!data.error) {
|
|
68
|
+
data.data = result.response
|
|
69
|
+
}
|
|
70
|
+
|
|
48
71
|
return data
|
|
49
72
|
}
|
|
50
73
|
}
|
package/lib/command/tmpBind.js
CHANGED
|
@@ -2,7 +2,7 @@ const { segment } = require('koishi')
|
|
|
2
2
|
const { resolve } = require('path')
|
|
3
3
|
const guildBind = require('../database/guildBind')
|
|
4
4
|
const truckyAppApi = require('../api/truckyAppApi')
|
|
5
|
-
const truckersMpApi = require('../api/
|
|
5
|
+
const truckersMpApi = require('../api/truckersMpApi')
|
|
6
6
|
const baiduTranslate = require('../util/baiduTranslate')
|
|
7
7
|
|
|
8
8
|
/**
|
package/lib/command/tmpQuery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const dayjs = require('dayjs')
|
|
2
2
|
const guildBind = require('../database/guildBind')
|
|
3
|
-
const truckersMpApi = require('../api/
|
|
3
|
+
const truckersMpApi = require('../api/truckersMpApi')
|
|
4
4
|
const truckyAppApi = require('../api/truckyAppApi')
|
|
5
5
|
const baiduTranslate = require('../util/baiduTranslate')
|
|
6
6
|
|
|
@@ -43,7 +43,7 @@ module.exports = async (ctx, cfg, session, tmpId) => {
|
|
|
43
43
|
return '查询玩家信息失败,请重试'
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
// 拼接消息模板
|
|
46
|
+
// 拼接消息模板
|
|
47
47
|
let message = `<img src="${playerInfo.data.avatar}"/>`
|
|
48
48
|
message += '\n😀玩家名称: ' + playerInfo.data.name
|
|
49
49
|
message += '\n📑注册日期: ' + dayjs(playerInfo.data.joinDate + 'Z').format('YYYY年MM月DD日')
|
|
@@ -56,10 +56,19 @@ module.exports = async (ctx, cfg, session, tmpId) => {
|
|
|
56
56
|
message += '\n🚫封禁截止: '
|
|
57
57
|
if (!playerInfo.data.displayBans) {
|
|
58
58
|
message += '隐藏'
|
|
59
|
-
} else if (!playerInfo.data.bannedUntil) {
|
|
60
|
-
message += '永久'
|
|
61
59
|
} else {
|
|
62
|
-
|
|
60
|
+
let banData = await truckersMpApi.bans(ctx.http, tmpId)
|
|
61
|
+
if (!banData.error) {
|
|
62
|
+
let ban = banData.data[0]
|
|
63
|
+
if (!ban.expiration) {
|
|
64
|
+
message += '永久'
|
|
65
|
+
} else {
|
|
66
|
+
message += dayjs(ban.expiration + 'Z').format('YYYY年MM月DD日 HH:mm')
|
|
67
|
+
}
|
|
68
|
+
message += "\n🚫封禁原因: " + await baiduTranslate(ctx, cfg, ban.reason.replace(/((http|ftp|https|file):[^'"\s]+)/, ''), false)
|
|
69
|
+
} else {
|
|
70
|
+
message += '查询失败'
|
|
71
|
+
}
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
message += '\n🚫封禁次数: ' + playerInfo.data.bansCount || 0
|
package/lib/command/tmpServer.js
CHANGED
|
@@ -60,7 +60,6 @@ module.exports = async (ctx, cfg, serverName) => {
|
|
|
60
60
|
message += await baiduTranslate(ctx, cfg, name) + ` (${typeToZh[type] || type})`
|
|
61
61
|
message += '\n路况: ' + (severityToZh[traffic.newSeverity] || traffic.color)
|
|
62
62
|
message += ' | 人数: ' + traffic.players
|
|
63
|
-
console.info(traffic)
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
return message
|
|
@@ -2,14 +2,14 @@ const md5 = require('js-md5')
|
|
|
2
2
|
const translateCache = require('../database/translateCache')
|
|
3
3
|
const TRANSLATE_API = 'https://fanyi-api.baidu.com/api/trans/vip/translate'
|
|
4
4
|
|
|
5
|
-
module.exports = async (ctx, cfg, content) => {
|
|
5
|
+
module.exports = async (ctx, cfg, content, cache = true) => {
|
|
6
6
|
// 没有开启百度翻译功能,直接返回文本
|
|
7
7
|
if (!cfg.baiduTranslateEnable) {
|
|
8
8
|
return content
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// 如果开启了缓存,尝试从缓存中查询翻译
|
|
12
|
-
if (cfg.baiduTranslateCacheEnable) {
|
|
12
|
+
if (cfg.baiduTranslateCacheEnable && cache) {
|
|
13
13
|
let translateContent = await translateCache.getTranslate(ctx.database, md5(content))
|
|
14
14
|
if (translateContent) {
|
|
15
15
|
return translateContent
|
|
@@ -29,7 +29,7 @@ module.exports = async (ctx, cfg, content) => {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// 如果开启了缓存,将翻译内容缓存到数据库
|
|
32
|
-
if (cfg.baiduTranslateCacheEnable) {
|
|
32
|
+
if (cfg.baiduTranslateCacheEnable && cache) {
|
|
33
33
|
translateCache.save(ctx.database, md5(content), content, result.trans_result[0].dst)
|
|
34
34
|
}
|
|
35
35
|
|