koishi-plugin-tmp-bot 1.3.1 → 1.3.3

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
@@ -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
  /**
@@ -62,7 +62,6 @@ module.exports = async (ctx, cfg, session, tmpId) => {
62
62
  }), "image/jpg")
63
63
  )
64
64
  } catch (e) {
65
- console.info(e)
66
65
  return '渲染异常,请重试'
67
66
  } finally {
68
67
  if (page) {
@@ -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
 
@@ -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
@@ -10,9 +10,12 @@
10
10
  margin: 0;
11
11
  padding: 0;
12
12
  }
13
+ * {
14
+ font-family: "微软雅黑", serif;
15
+ }
13
16
  #container {
14
- width: 380px;
15
- height: 260px;
17
+ width: 500px;
18
+ height: 320px;
16
19
  position: relative;
17
20
  }
18
21
  .map {
@@ -22,7 +25,7 @@
22
25
  }
23
26
  .user-info-box {
24
27
  width: 100%;
25
- height: 58px;
28
+ height: 76px;
26
29
  position: absolute;
27
30
  bottom: 0;
28
31
  z-index: 999;
@@ -31,20 +34,23 @@
31
34
  display: flex;
32
35
  flex-direction: row;
33
36
  align-items: center;
34
- padding: 0 12px;
37
+ padding: 0 14px;
35
38
  box-sizing: border-box;
36
39
  }
37
40
  .avatar {
38
- width: 40px;
39
- height: 40px;
41
+ width: 56px;
42
+ height: 56px;
40
43
  border-radius: 4px;
41
44
  }
42
45
  .user {
43
- height: 40px;
44
- width: 180px;
46
+ height: 56px;
47
+ width: 220px;
48
+ display: flex;
49
+ flex-direction: column;
50
+ justify-content: center;
45
51
  }
46
52
  .user {
47
- font-size: 14px;
53
+ font-size: 16px;
48
54
  color: #eeeeee;
49
55
  margin-left: 10px;
50
56
  box-sizing: border-box;
@@ -52,6 +58,7 @@
52
58
  .user .server-name-box {
53
59
  display: flex;
54
60
  align-items: center;
61
+ margin-top: 4px;
55
62
  }
56
63
  .user .username {
57
64
  white-space: nowrap;
@@ -70,15 +77,18 @@
70
77
  .location-box {
71
78
  flex-grow: 1;
72
79
  color: #eeeeee;
73
- font-size: 14px;
74
- height: 40px;
80
+ font-size: 16px;
81
+ height: 56px;
75
82
  box-sizing: border-box;
76
83
  border-right: 4px solid #54d354;
77
84
  text-align: right;
78
85
  padding-right: 6px;
86
+ display: flex;
87
+ flex-direction: column;
88
+ justify-content: center;
79
89
  }
80
90
  .location-box>* {
81
- width: 116px;
91
+ width: 174px;
82
92
  white-space: nowrap;
83
93
  overflow: hidden;
84
94
  text-overflow: ellipsis;
@@ -92,25 +102,17 @@
92
102
  <img class="avatar" src="https://static.truckersmp.com/avatarsN/small/defaultavatar.png"/>
93
103
  <div class="user">
94
104
  <div class="username">...</div>
95
- <div class="server-name-box">
105
+ <div class="server-name-box" style="margin-top: 4px">
96
106
  <span class="server-name">...</span>游戏中
97
107
  </div>
98
108
  </div>
99
109
  <div class="location-box">
100
110
  <div class="country">...</div>
101
- <div class="real-name">...</div>
111
+ <div class="real-name" style="margin-top: 4px">...</div>
102
112
  </div>
103
113
  </div>
104
114
  </div>
105
115
  <script>
106
- // a: https://static.truckersmp.com/avatarsN/defaultavatar.png
107
- // sa: https://static.truckersmp.com/avatarsN/small/defaultavatar.png
108
- // name: Damien12345
109
- // x: -13426
110
- // y: -5998
111
- // serverName: Simulation 1
112
- // country: Germany
113
- // realName: Duisburg
114
116
  let multipliers = {
115
117
  x: 71292,
116
118
  y: 60412
@@ -132,7 +134,7 @@
132
134
 
133
135
  // 定义地图
134
136
  let map = L.map('map', {
135
- attributionControl: false, // 去除右下角的 leaflet 标识
137
+ attributionControl: false,
136
138
  crs: L.CRS.Simple,
137
139
  zoomControl: false
138
140
  });
@@ -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.1",
4
+ "version": "1.3.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [