koishi-plugin-tmp-bot 1.3.0 → 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.
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  const guildBind = require('../database/guildBind')
2
- const truckersMpApi = require("../api/TruckersMpApi");
2
+ const truckersMpApi = require("../api/truckersMpApi");
3
3
 
4
4
  /**
5
5
  * 绑定 TMP ID
@@ -16,7 +16,7 @@ module.exports = async (ctx, cfg, session, tmpId) => {
16
16
  }
17
17
 
18
18
  // 更新数据库
19
- guildBind.saveOrUpdate(ctx.database, session.platform, session.guildId, session.userId, session.author.username, tmpId)
19
+ guildBind.saveOrUpdate(ctx.database, session.platform, session.userId, session.author.username, tmpId)
20
20
 
21
21
  return `绑定成功 ( ${playerInfo.data.name} )`
22
22
  }
@@ -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/TruckersMpApi')
5
+ const truckersMpApi = require('../api/truckersMpApi')
6
6
  const baiduTranslate = require('../util/baiduTranslate')
7
7
 
8
8
  /**
@@ -16,7 +16,7 @@ module.exports = async (ctx, cfg, session, tmpId) => {
16
16
 
17
17
  // 如果没有传入tmpId,尝试从数据库查询绑定信息
18
18
  if (!tmpId) {
19
- let guildBindData = await guildBind.get(ctx.database, session.platform, session.guildId, session.userId)
19
+ let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId)
20
20
  if (!guildBindData) {
21
21
  return `请输入正确的玩家编号`
22
22
  }
@@ -1,6 +1,6 @@
1
1
  const dayjs = require('dayjs')
2
2
  const guildBind = require('../database/guildBind')
3
- const truckersMpApi = require('../api/TruckersMpApi')
3
+ const truckersMpApi = require('../api/truckersMpApi')
4
4
  const truckyAppApi = require('../api/truckyAppApi')
5
5
  const baiduTranslate = require('../util/baiduTranslate')
6
6
 
@@ -24,7 +24,7 @@ module.exports = async (ctx, cfg, session, tmpId) => {
24
24
 
25
25
  // 如果没有传入tmpId,尝试从数据库查询绑定信息
26
26
  if (!tmpId) {
27
- let guildBindData = await guildBind.get(ctx.database, session.platform, session.guildId, session.userId)
27
+ let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId)
28
28
  if (!guildBindData) {
29
29
  return `请输入正确的玩家编号`
30
30
  }
@@ -43,7 +43,7 @@ module.exports = async (ctx, cfg, session, tmpId) => {
43
43
  return '查询玩家信息失败,请重试'
44
44
  }
45
45
 
46
- // 拼接消息模板 正常4763167 永久5396563 暂时封号5118166
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
- message += daiyjs(playerInfo.data.bannedUntil + 'Z').format('YYYY年MM月DD日 HH:mm')
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
@@ -1,4 +1,4 @@
1
- const truckersMpApi = require('../api/TruckersMpApi')
1
+ const truckersMpApi = require('../api/truckersMpApi')
2
2
 
3
3
  module.exports = async (ctx, cfg, game) => {
4
4
  // 查询服务器信息
@@ -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
@@ -3,13 +3,11 @@ module.exports = {
3
3
  * 获取绑定信息
4
4
  * @param db 数据源
5
5
  * @param platform 平台
6
- * @param guildId 群组编号
7
6
  * @param userId 用户编号
8
7
  */
9
- async get (db, platform, guildId, userId) {
8
+ async get (db, platform, userId) {
10
9
  const guildBindList = await db.get('tmp_guild_bind', {
11
10
  platform,
12
- guild_id: guildId,
13
11
  user_id: userId
14
12
  })
15
13
 
@@ -23,13 +21,12 @@ module.exports = {
23
21
  * 新增或更新绑定信息
24
22
  * @param db 数据源
25
23
  * @param platform 平台
26
- * @param guildId 群组编号
27
24
  * @param userId 用户编号
28
25
  * @param userName 用户昵称
29
26
  * @param tmpId TMP ID
30
27
  */
31
- saveOrUpdate (db, platform, guildId, userId, userName, tmpId) {
32
- this.get(db, platform, guildId, userId).then((data) => {
28
+ saveOrUpdate (db, platform, userId, userName, tmpId) {
29
+ this.get(db, platform, userId).then((data) => {
33
30
  if (data) {
34
31
  db.set('tmp_guild_bind', data.id, {
35
32
  tmp_id: tmpId,
@@ -38,7 +35,6 @@ module.exports = {
38
35
  } else {
39
36
  db.create('tmp_guild_bind', {
40
37
  platform: platform,
41
- guild_id: guildId,
42
38
  user_id: userId,
43
39
  user_name: userName,
44
40
  tmp_id: tmpId
@@ -15,12 +15,6 @@ const modelArray = {
15
15
  nullable: false,
16
16
  comment: '所属平台'
17
17
  },
18
- guild_id: {
19
- type: 'string',
20
- length: 50,
21
- nullable: false,
22
- comment: '群组编号'
23
- },
24
18
  user_id: {
25
19
  type: 'string',
26
20
  length: 50,
@@ -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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-tmp-bot",
3
3
  "description": "欧洲卡车模拟2 TMP查询机器人",
4
- "version": "1.3.0",
4
+ "version": "1.3.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [