@sjtdev/koishi-plugin-dota2tracker 1.1.1 → 1.1.2-beta.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.
- package/lib/index.js +66 -4
- package/package.json +1 -2
- package/readme.md +1 -1
- package/template/guild_member/guild_member.ejs +131 -0
- package/template/player/player_1.ejs +2 -2
package/lib/index.js
CHANGED
|
@@ -251,7 +251,7 @@ function PLAYER_INFO_WITH_25_MATCHES(steamAccountId) {
|
|
|
251
251
|
rank
|
|
252
252
|
lobbyType
|
|
253
253
|
gameMode
|
|
254
|
-
|
|
254
|
+
startDateTime
|
|
255
255
|
durationSeconds
|
|
256
256
|
didRadiantWin
|
|
257
257
|
topLaneOutcome
|
|
@@ -302,6 +302,37 @@ function PLAYER_EXTRA_INFO(steamAccountId, matchCount, totalHeroCount) {
|
|
|
302
302
|
`;
|
|
303
303
|
}
|
|
304
304
|
__name(PLAYER_EXTRA_INFO, "PLAYER_EXTRA_INFO");
|
|
305
|
+
function PLAYERS_INFO_WITH_10_MATCHES_FOR_GUILD(steamAccountIds) {
|
|
306
|
+
return `{
|
|
307
|
+
players(steamAccountIds: [${steamAccountIds.join()}]) {
|
|
308
|
+
steamAccount {
|
|
309
|
+
id
|
|
310
|
+
avatar
|
|
311
|
+
name
|
|
312
|
+
seasonRank
|
|
313
|
+
}
|
|
314
|
+
matches(request: {take: 10}) {
|
|
315
|
+
didRadiantWin
|
|
316
|
+
startDateTime
|
|
317
|
+
players {
|
|
318
|
+
isRadiant
|
|
319
|
+
kills
|
|
320
|
+
deaths
|
|
321
|
+
assists
|
|
322
|
+
steamAccount {
|
|
323
|
+
id
|
|
324
|
+
}
|
|
325
|
+
hero {
|
|
326
|
+
shortName
|
|
327
|
+
}
|
|
328
|
+
imp
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
`;
|
|
334
|
+
}
|
|
335
|
+
__name(PLAYERS_INFO_WITH_10_MATCHES_FOR_GUILD, "PLAYERS_INFO_WITH_10_MATCHES_FOR_GUILD");
|
|
305
336
|
function CURRENT_GAMEVERSION() {
|
|
306
337
|
return `
|
|
307
338
|
{
|
|
@@ -745,6 +776,7 @@ __name(playerisValid, "playerisValid");
|
|
|
745
776
|
|
|
746
777
|
// src/index.ts
|
|
747
778
|
var import_fs2 = __toESM(require("fs"));
|
|
779
|
+
var import_path2 = __toESM(require("path"));
|
|
748
780
|
var import_moment = __toESM(require("moment"));
|
|
749
781
|
var dotaconstants3 = __toESM(require("dotaconstants"));
|
|
750
782
|
|
|
@@ -1017,7 +1049,6 @@ var dotaconstants_add_default = {
|
|
|
1017
1049
|
// src/index.ts
|
|
1018
1050
|
var import_koishi2 = require("koishi");
|
|
1019
1051
|
var ejs = __toESM(require("ejs"));
|
|
1020
|
-
var import_path2 = __toESM(require("path"));
|
|
1021
1052
|
var name = "dota2tracker";
|
|
1022
1053
|
var usage = "DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑定),以及一系列查询功能。";
|
|
1023
1054
|
var inject = ["database", "puppeteer", "cron"];
|
|
@@ -1080,6 +1111,10 @@ async function apply(ctx, config) {
|
|
|
1080
1111
|
session.send(`绑定失败,${verifyRes.reason}`);
|
|
1081
1112
|
return;
|
|
1082
1113
|
}
|
|
1114
|
+
if (!/^(?:.{1,20})?$/.test(nick_name ?? "")) {
|
|
1115
|
+
session.send("别名过长,请限制在20个字符以内。(也可以留空)");
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1083
1118
|
session.send(
|
|
1084
1119
|
`
|
|
1085
1120
|
绑定成功,
|
|
@@ -1108,6 +1143,10 @@ async function apply(ctx, config) {
|
|
|
1108
1143
|
session.send("请输入你的别名。");
|
|
1109
1144
|
return;
|
|
1110
1145
|
}
|
|
1146
|
+
if (!/^.{1,20}$/.test(nick_name ?? "")) {
|
|
1147
|
+
session.send("别名过长,请限制在20个字符以内。");
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1111
1150
|
sessionPlayer.nickName = nick_name;
|
|
1112
1151
|
await ctx.database.set("dt_subscribed_players", sessionPlayer.id, { nickName: sessionPlayer.nickName });
|
|
1113
1152
|
session.send(`改名成功,现在你叫${nick_name}了。`);
|
|
@@ -1118,8 +1157,31 @@ async function apply(ctx, config) {
|
|
|
1118
1157
|
});
|
|
1119
1158
|
ctx.command("查询群友", "查询本群已绑定的玩家").action(async ({ session }) => {
|
|
1120
1159
|
if (session.guild) {
|
|
1121
|
-
|
|
1122
|
-
|
|
1160
|
+
const subscribedPlayers = await ctx.database.get("dt_subscribed_players", { guildId: session.event.guild.id, platform: session.platform });
|
|
1161
|
+
if (!subscribedPlayers.length) {
|
|
1162
|
+
session.send("本群尚无绑定玩家。");
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
if (subscribedPlayers.length <= 20) {
|
|
1166
|
+
try {
|
|
1167
|
+
const memberList = await session.bot.getGuildMemberList(session.event.guild.id);
|
|
1168
|
+
ctx.logger.info(JSON.stringify(memberList.data));
|
|
1169
|
+
let queryRes = await query(PLAYERS_INFO_WITH_10_MATCHES_FOR_GUILD(subscribedPlayers.map((player) => player.steamId)));
|
|
1170
|
+
if (queryRes.status == 200) {
|
|
1171
|
+
const users = subscribedPlayers.map((subscribedPlayer) => {
|
|
1172
|
+
const queryPlayer = queryRes.data.data.players.find((player) => player.steamAccount.id == subscribedPlayer.steamId);
|
|
1173
|
+
const queryMember = memberList.data.find((member) => member.user?.id == subscribedPlayer.userId);
|
|
1174
|
+
return { ...subscribedPlayer, ...queryPlayer, ...queryMember };
|
|
1175
|
+
});
|
|
1176
|
+
console.log(users);
|
|
1177
|
+
session.send(await ctx.puppeteer.render(genImageHTML(users, "guild_member" /* GuildMember */, "guild_member" /* GuildMember */)));
|
|
1178
|
+
} else
|
|
1179
|
+
throw 0;
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
console.error(error);
|
|
1182
|
+
session.send("查询群友失败。");
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1123
1185
|
}
|
|
1124
1186
|
});
|
|
1125
1187
|
async function queryAndDisplayMatch(session, matchId) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sjtdev/koishi-plugin-dota2tracker",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "1.1.1",
|
|
4
|
+
"version": "1.1.2-beta.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"axios": "^1.6.8",
|
|
30
|
-
"cheerio": "^1.0.0-rc.12",
|
|
31
30
|
"dotaconstants": "^8.5.0",
|
|
32
31
|
"ejs": "^3.1.10",
|
|
33
32
|
"moment": "^2.30.1"
|
package/readme.md
CHANGED
|
@@ -41,7 +41,7 @@ DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑
|
|
|
41
41
|
|
|
42
42
|
### 其他问题
|
|
43
43
|
已知问题:当本插件更新版本后,查询已经查询过的比赛数据可能查询失败。
|
|
44
|
-
* 原因:插件的缓存功能,查询过的比赛数据会缓存至本地以节省API
|
|
44
|
+
* 原因:插件的缓存功能,查询过的比赛数据会缓存至本地以节省API调用次数与服务器流量,再次查询时优先调用本地数据也会提高处理速度。当插件更新后若新增数据的处理或API查询字段,会导致旧的缓存内缺失部分数据引发生成时报错。(播报比赛战报应该不会有这个问题)
|
|
45
45
|
* 解决:目前在生成失败时会清除缓存,再查询一次就好了。
|
|
46
46
|
|
|
47
47
|
## 灵感来源&鸣谢
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" />
|
|
7
|
+
<title>Document</title>
|
|
8
|
+
<style>
|
|
9
|
+
html,
|
|
10
|
+
body {
|
|
11
|
+
background-color: black;
|
|
12
|
+
color: white;
|
|
13
|
+
width: 800px;
|
|
14
|
+
}
|
|
15
|
+
p {
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
18
|
+
img {
|
|
19
|
+
width: 100%;
|
|
20
|
+
vertical-align: middle;
|
|
21
|
+
}
|
|
22
|
+
.player.full {
|
|
23
|
+
width: 100%;
|
|
24
|
+
border: 1px #fff solid;
|
|
25
|
+
border-radius: 5px;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.player.full .info {
|
|
30
|
+
display: grid;
|
|
31
|
+
grid-template-columns: repeat(2, 64px) auto 64px;
|
|
32
|
+
align-items: center;
|
|
33
|
+
/* border-bottom: #fff 1px solid; */
|
|
34
|
+
position: relative;
|
|
35
|
+
padding-bottom: 1px;
|
|
36
|
+
}
|
|
37
|
+
.player.full .info > .name {
|
|
38
|
+
line-height: 20px;
|
|
39
|
+
display: grid;
|
|
40
|
+
grid-template-rows: 24px repeat(2, 20px);
|
|
41
|
+
text-align: center;
|
|
42
|
+
}
|
|
43
|
+
.player.full .info > .name > .nick_name {
|
|
44
|
+
font-size: 18px;
|
|
45
|
+
line-height: 24px;
|
|
46
|
+
}.player.full .info > .name >p{display: flex;}
|
|
47
|
+
.player.full .last_match_date {
|
|
48
|
+
position: relative;
|
|
49
|
+
padding-top: 1px;
|
|
50
|
+
}
|
|
51
|
+
.player.full .last_match_date::before {
|
|
52
|
+
content: "";
|
|
53
|
+
position: absolute;
|
|
54
|
+
left: 50%;
|
|
55
|
+
transform: translateX(-50%);
|
|
56
|
+
top: 0;
|
|
57
|
+
width: 80%;
|
|
58
|
+
height: 1px;
|
|
59
|
+
background-color: #666;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.player.full .last10match {
|
|
63
|
+
display: grid;
|
|
64
|
+
gap: 5px;
|
|
65
|
+
grid-template-columns: repeat(5, 1fr);
|
|
66
|
+
grid-template-rows: repeat(2, 1fr);
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-items: center;
|
|
69
|
+
margin: 4px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.player.full .last10match .match {
|
|
73
|
+
width: 150px;
|
|
74
|
+
height: 36px;
|
|
75
|
+
border-radius: 36px;
|
|
76
|
+
padding: 2px;
|
|
77
|
+
display: flex;
|
|
78
|
+
box-sizing: border-box;
|
|
79
|
+
align-items: center;
|
|
80
|
+
flex-direction: row;
|
|
81
|
+
justify-content: space-around;
|
|
82
|
+
}
|
|
83
|
+
.player.full .last10match .match.win {
|
|
84
|
+
background-color: #006400;
|
|
85
|
+
}
|
|
86
|
+
.player.full .last10match .match.lose {
|
|
87
|
+
background-color: #8b0000;
|
|
88
|
+
}
|
|
89
|
+
.player.full .last10match img {
|
|
90
|
+
width: 32px;
|
|
91
|
+
}
|
|
92
|
+
</style>
|
|
93
|
+
</head>
|
|
94
|
+
<body>
|
|
95
|
+
<%- const users = data;
|
|
96
|
+
users.map(user=>`
|
|
97
|
+
<div class="player full">
|
|
98
|
+
<div class="info">
|
|
99
|
+
<img class="avatar user" src="${user.user.avatar}" alt="" />
|
|
100
|
+
<img class="avatar steam" src="${user.steamAccount.avatar}" alt="" />
|
|
101
|
+
<div class="name">
|
|
102
|
+
<p class="nick_name">
|
|
103
|
+
<span>${user.nickName}</span>
|
|
104
|
+
</p>
|
|
105
|
+
<p class="user">
|
|
106
|
+
<span>账号:${user.userId}</span>
|
|
107
|
+
<span>用户名:${user.user.name}</span>
|
|
108
|
+
</p>
|
|
109
|
+
<p class="steam">
|
|
110
|
+
<span>SteamID:${user.steamId}</span>
|
|
111
|
+
<span>Steam用户名:${user.steamAccount.name}</span>
|
|
112
|
+
</p>
|
|
113
|
+
</div>
|
|
114
|
+
<img class="rank" src="${utils.getImageUrl("medal_"+((!user.steamAccount.seasonRank)?0:Math.floor(user.steamAccount.seasonRank/10)))}" alt="" />
|
|
115
|
+
</div>
|
|
116
|
+
${users.length<10?
|
|
117
|
+
`<div class="last10match">
|
|
118
|
+
${user.matches.map(match=>{
|
|
119
|
+
let playerInMatch = match.players.find(player=>player.steamAccount.id==user.steamId)
|
|
120
|
+
return `
|
|
121
|
+
<div class="match ${match.didRadiantWin==playerInMatch.isRadiant?"win":"lose"}">
|
|
122
|
+
<img src="${utils.getImageUrl(playerInMatch.hero.shortName),ImageType.HeroIcons}" alt="" />
|
|
123
|
+
<span>${playerInMatch.kills}/${playerInMatch.deaths}/${playerInMatch.assists}</span>
|
|
124
|
+
<span>${(playerInMatch.imp > 0 ? "+" : "") + playerInMatch.imp}</span>
|
|
125
|
+
</div>`}).join("")}
|
|
126
|
+
</div>`:0;}
|
|
127
|
+
<div class="last_match_date">最近游戏: ${user.matches[0].startDateTime}</div>
|
|
128
|
+
</div>`).join("")
|
|
129
|
+
%>
|
|
130
|
+
</body>
|
|
131
|
+
</html>
|
|
@@ -501,7 +501,7 @@
|
|
|
501
501
|
<th>英雄</th>
|
|
502
502
|
<th>KDA(参战率)</th>
|
|
503
503
|
<th>对线</th>
|
|
504
|
-
<th
|
|
504
|
+
<th>时间</th>
|
|
505
505
|
<th>时长</th>
|
|
506
506
|
<th>表现</th>
|
|
507
507
|
<th>段位</th>
|
|
@@ -522,7 +522,7 @@
|
|
|
522
522
|
<p>${match.players[0].kills}/${match.players[0].deaths}/${match.players[0].assists}</p>
|
|
523
523
|
</td>
|
|
524
524
|
<td><div class="player_lane ${match.laneResult}">${laneSVG[match.laneResult]}</div></td>
|
|
525
|
-
<td style="line-height: 20px">${moment(new Date(match.
|
|
525
|
+
<td style="line-height: 20px">${moment(new Date(match.startDateTime * 1000)).format("YYYY-MM-DD HH:mm:ss").slice(2)}</td>
|
|
526
526
|
<td>${utils.sec2time(match.durationSeconds)}</td>
|
|
527
527
|
<td>${(match.players[0].imp > 0 ? "+" : "") + match.players[0].imp}</td>
|
|
528
528
|
<td><img class="medal" src="${utils.getImageUrl("medal_" + match.rank.toString().split("")[0])}" style="width: 100%" /></td>
|