koishi-plugin-tmp-bot 1.15.1 → 1.16.1

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.
@@ -0,0 +1,13 @@
1
+ const tmpQueryText = require("./tmpQueryText");
2
+ const tmpQueryImg = require("./tmpQueryImg");
3
+
4
+ module.exports = async (ctx, cfg, session, tmpId) => {
5
+ switch (cfg.tmpQueryType) {
6
+ case 1:
7
+ return await tmpQueryText(ctx, cfg, session, tmpId)
8
+ case 2:
9
+ return await tmpQueryImg(ctx, cfg, session, tmpId)
10
+ default:
11
+ return '指令配置错误'
12
+ }
13
+ }
@@ -0,0 +1,108 @@
1
+ const dayjs = require('dayjs')
2
+ const guildBind = require('../../database/guildBind')
3
+ const truckyAppApi = require('../../api/truckyAppApi')
4
+ const evmOpenApi = require('../../api/evmOpenApi')
5
+ const baiduTranslate = require('../../util/baiduTranslate')
6
+ const {resolve} = require("path");
7
+ const common = require("../../util/common");
8
+ const {segment} = require("koishi");
9
+
10
+ /**
11
+ * 用户组
12
+ */
13
+ const userGroup = {
14
+ 'Player': '玩家',
15
+ 'Retired Legend': '退役',
16
+ 'Game Developer': '游戏开发者',
17
+ 'Retired Team Member': '退休团队成员',
18
+ 'Add-On Team': '附加组件团队',
19
+ 'Game Moderator': '游戏管理员'
20
+ }
21
+
22
+ /**
23
+ * 查询玩家信息
24
+ */
25
+ module.exports = async (ctx, cfg, session, tmpId) => {
26
+ if (!ctx.puppeteer) {
27
+ return '未启用 puppeteer 服务'
28
+ }
29
+
30
+ if (tmpId && isNaN(tmpId)) {
31
+ return `请输入正确的玩家编号`
32
+ }
33
+
34
+ // 如果没有传入tmpId,尝试从数据库查询绑定信息
35
+ if (!tmpId) {
36
+ let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId)
37
+ if (!guildBindData) {
38
+ return `请输入正确的玩家编号`
39
+ }
40
+ tmpId = guildBindData.tmp_id
41
+ }
42
+
43
+ // 查询玩家信息
44
+ let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId)
45
+ if (playerInfo.error) {
46
+ return '查询玩家信息失败,请重试'
47
+ }
48
+
49
+ // 查询线上信息
50
+ let playerMapInfo = await truckyAppApi.online(ctx.http, tmpId)
51
+
52
+ // 拼接数据
53
+ let data = {}
54
+ data.tmpId = playerInfo.data.tmpId
55
+ data.name = playerInfo.data.name
56
+ data.steamId = playerInfo.data.steamId
57
+ data.registerDate = dayjs(playerInfo.data.registerTime).format('YYYY年MM月DD日')
58
+ data.avatarUrl = playerInfo.data.avatarUrl
59
+ data.groupColor = playerInfo.data.groupColor
60
+ data.groupName = (userGroup[playerInfo.data.groupName] || playerInfo.data.groupName)
61
+ data.isJoinVtc = playerInfo.data.isJoinVtc
62
+ data.vtcName = playerInfo.data.vtcName
63
+ data.vtcRole = playerInfo.data.vtcRole
64
+ data.isSponsor = playerInfo.data.isSponsor
65
+ data.sponsorAmount = playerInfo.data.sponsorAmount
66
+ data.sponsorCumulativeAmount = playerInfo.data.sponsorCumulativeAmount
67
+ data.sponsorHide = playerInfo.data.sponsorHide
68
+ data.isOnline = false
69
+ if (playerMapInfo && !playerMapInfo.error) {
70
+ data.isOnline = playerMapInfo.data.online
71
+ if (data.isOnline) {
72
+ data.onlineServerName = playerMapInfo.data.serverDetails.name
73
+ data.onlineCountry = await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.country)
74
+ data.onlineCity = await baiduTranslate(ctx, cfg, playerMapInfo.data.location.poi.realName)
75
+ data.onlineX = playerMapInfo.data.x
76
+ data.onlineY = playerMapInfo.data.y
77
+ data.onlineMapType = playerMapInfo.data.serverDetails.id === 50 ? 'promods' : 'ets'
78
+ }
79
+ }
80
+ data.isBan = playerInfo.data.isBan
81
+ data.banUntil = playerInfo.data.banUntil
82
+ data.banReason = playerInfo.data.banReason
83
+ data.banReasonZh = playerInfo.data.banReasonZh
84
+ data.banCount = playerInfo.data.banCount
85
+ data.banHide = playerInfo.data.banHide
86
+
87
+ let page
88
+ try {
89
+ page = await ctx.puppeteer.page()
90
+ await page.setViewport({ width: 1000, height: 1000 })
91
+ await page.goto(`file:///${resolve(__dirname, '../../resource/query.html')}`)
92
+ await page.evaluate(`init(${JSON.stringify(data)})`)
93
+ await common.sleep(100)
94
+ await page.waitForNetworkIdle()
95
+ const element = await page.$("#container");
96
+ return (
97
+ segment.image(await element.screenshot({
98
+ encoding: "binary"
99
+ }), "image/jpg")
100
+ )
101
+ } catch {
102
+ return '渲染异常,请重试'
103
+ } finally {
104
+ if (page) {
105
+ await page.close()
106
+ }
107
+ }
108
+ }
@@ -1,8 +1,8 @@
1
1
  const dayjs = require('dayjs')
2
- const guildBind = require('../database/guildBind')
3
- const truckyAppApi = require('../api/truckyAppApi')
4
- const evmOpenApi = require('../api/evmOpenApi')
5
- const baiduTranslate = require('../util/baiduTranslate')
2
+ const guildBind = require('../../database/guildBind')
3
+ const truckyAppApi = require('../../api/truckyAppApi')
4
+ const evmOpenApi = require('../../api/evmOpenApi')
5
+ const baiduTranslate = require('../../util/baiduTranslate')
6
6
 
7
7
  /**
8
8
  * 用户组
package/lib/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.apply = exports.Config = exports.inject = exports.name = void 0;
3
+ exports.Config = exports.inject = exports.name = void 0;
4
+ exports.apply = apply;
4
5
  const koishi_1 = require("koishi");
5
6
  const model = require('./database/model');
6
- const tmpQuery = require('./command/tmpQuery');
7
+ const tmpQuery = require('./command/tmpQuery/tmpQuery');
7
8
  const tmpServer = require('./command/tmpServer');
8
9
  const tmpBind = require('./command/tmpBind');
9
10
  const tmpTraffic = require('./command/tmpTraffic/tmpTraffic');
@@ -28,6 +29,10 @@ exports.Config = koishi_1.Schema.intersect([
28
29
  koishi_1.Schema.const(1).description('文字'),
29
30
  koishi_1.Schema.const(2).description('热力图')
30
31
  ]).default(1).description('路况信息展示方式'),
32
+ tmpQueryType: koishi_1.Schema.union([
33
+ koishi_1.Schema.const(1).description('文字'),
34
+ koishi_1.Schema.const(2).description('图片')
35
+ ]).default(1).description('玩家信息展示方式'),
31
36
  }).description('指令配置'),
32
37
  ]);
33
38
  function apply(ctx, cfg) {
@@ -42,4 +47,3 @@ function apply(ctx, cfg) {
42
47
  ctx.command('tmpversion').action(async () => await tmpVersion(ctx));
43
48
  ctx.command('tmpdlcmap').action(async ({ session }) => await tmpDlcMap(ctx, session));
44
49
  }
45
- exports.apply = apply;