@sjtdev/koishi-plugin-dota2tracker 1.1.2-beta.3 → 1.1.2-beta.5

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 CHANGED
@@ -209,6 +209,11 @@ function PLAYERS_LASTMATCH(steamAccountIds) {
209
209
  id
210
210
  parsedDateTime
211
211
  startDateTime
212
+ players{
213
+ steamAccount{
214
+ id
215
+ }
216
+ }
212
217
  }
213
218
  }
214
219
  }
@@ -1201,7 +1206,7 @@ async function apply(ctx, config) {
1201
1206
  session.send(await ctx.puppeteer.render(genImageHTML(match, config.template_match, "match" /* Match */)));
1202
1207
  ctx.database.upsert("dt_previous_query_results", (row) => [{ matchId: match.id, data: match, queryTime: /* @__PURE__ */ new Date() }]);
1203
1208
  } else {
1204
- pendingMatches.push({ matchId, platform: session.event.platform, guildId: session.event.guild.id });
1209
+ pendingMatches.push({ matchId, guilds: [{ platform: session.event.platform, guildId: session.event.guild.id, players: [] }] });
1205
1210
  session.send("比赛尚未解析,将在解析完成后发布。");
1206
1211
  }
1207
1212
  } catch (error) {
@@ -1441,7 +1446,6 @@ async function apply(ctx, config) {
1441
1446
  ctx.database.remove("dt_previous_query_results", { queryTime: { $lt: oneMonthAgo } });
1442
1447
  });
1443
1448
  ctx.cron("* * * * *", async function() {
1444
- const scanningMatches = [...pendingMatches];
1445
1449
  const subscribedGuilds = await ctx.database.get("dt_subscribed_guilds", void 0);
1446
1450
  const subscribedPlayersInGuild = (await ctx.database.get("dt_subscribed_players", void 0)).filter((player) => subscribedGuilds.some((guild) => guild.guildId == player.guildId));
1447
1451
  if (subscribedPlayersInGuild.length > 0) {
@@ -1452,22 +1456,28 @@ async function apply(ctx, config) {
1452
1456
  })
1453
1457
  )
1454
1458
  );
1455
- for (let player of queryRes.data.data.players) {
1456
- let lastMatch = player.matches[0];
1457
- if ((await ctx.database.get("dt_sended_match_id", { matchId: lastMatch.id })).length)
1458
- continue;
1459
- if (import_moment.default.unix(lastMatch.startDateTime).isBefore((0, import_moment.default)().subtract(1, "days")))
1460
- continue;
1461
- for (let subscribed_player of subscribedPlayersInGuild) {
1462
- if (player.steamAccount.id == subscribed_player.steamId) {
1463
- scanningMatches.push({ matchId: lastMatch.id, platform: subscribed_player.platform, guildId: subscribed_player.guildId });
1464
- ctx.logger.info(`追踪到来自群组${subscribed_player.platform}:${subscribed_player.guildId}-用户${subscribed_player.nickName ?? ""}(${subscribed_player.steamId})的尚未播报过的最新比赛 ${lastMatch.id}。`);
1459
+ const lastMatches = queryRes.data.data.players.map((player) => player.matches[0]).filter((item, index, self) => index === self.findIndex((t) => t.id === item.id)).filter((match) => !pendingMatches.some((pendingMatch) => pendingMatch.matchId == match.id));
1460
+ const sendedMatchesIds = (await ctx.database.get("dt_sended_match_id", { matchId: lastMatches.map((match) => match.id) }, ["matchId"])).map((match) => match.matchId);
1461
+ lastMatches.filter((match) => !sendedMatchesIds.includes(match.id)).forEach((match) => {
1462
+ const tempGuilds = [];
1463
+ match.players.forEach((player) => {
1464
+ const subscribedPlayer = subscribedPlayersInGuild.find((subscribedPlayer2) => subscribedPlayer2.steamId === player.steamAccount.id);
1465
+ if (subscribedPlayer) {
1466
+ const tempGuild = tempGuilds.find((guild) => guild.guildId == subscribedPlayer.guildId && guild.platform == subscribedPlayer.platform);
1467
+ if (tempGuild)
1468
+ tempGuild.players.push(subscribedPlayer);
1469
+ else
1470
+ tempGuilds.push({ guildId: subscribedPlayer.guildId, platform: subscribedPlayer.platform, players: [subscribedPlayer] });
1465
1471
  }
1466
- }
1467
- }
1472
+ });
1473
+ pendingMatches.push({ matchId: match.id, guilds: tempGuilds });
1474
+ ctx.logger.info(
1475
+ tempGuilds.map((guild) => `追踪到来自群组${guild.platform}:${guild.guildId}的用户${guild.players.map((player) => `[${player.nickName ?? ""}(${player.steamId})]`).join("、")}的尚未播报过的最新比赛 ${match.id}。`).join("")
1476
+ );
1477
+ });
1468
1478
  }
1469
- if (scanningMatches.length > 0) {
1470
- const pendingMatch = scanningMatches[0];
1479
+ if (pendingMatches.length > 0) {
1480
+ const pendingMatch = pendingMatches[0];
1471
1481
  try {
1472
1482
  let match;
1473
1483
  let queryLocal = await ctx.database.get("dt_previous_query_results", pendingMatch.matchId, ["data"]);
@@ -1481,13 +1491,11 @@ async function apply(ctx, config) {
1481
1491
  }
1482
1492
  }
1483
1493
  if (match.parsedDateTime || import_moment.default.unix(match.startDateTime).isBefore((0, import_moment.default)().subtract(1, "years"))) {
1484
- const commingMatches = scanningMatches.filter((item) => item.matchId == match.id);
1485
- const realCommingMatches = commingMatches.filter((commingMatch, index, self) => index === self.findIndex((t) => t.guildId === commingMatch.guildId && t.platform === commingMatch.platform));
1486
- let broadMatchMessage = "";
1494
+ pendingMatches = pendingMatches.filter((item) => item.matchId != match.id);
1487
1495
  const img = await ctx.puppeteer.render(genImageHTML(match, config.template_match, "match" /* Match */));
1488
- for (let comming of realCommingMatches) {
1489
- let commingSubscribedPlayers = subscribedPlayersInGuild.filter((item) => item.platform == comming.platform && item.guildId == comming.guildId);
1490
- let idsToFind = commingSubscribedPlayers.map((item) => item.steamId);
1496
+ for (let commingGuild of pendingMatch.guilds) {
1497
+ let broadMatchMessage = "";
1498
+ let idsToFind = commingGuild.players.map((player) => player.steamId);
1491
1499
  let broadPlayers = match.players.filter((item) => idsToFind.includes(item.steamAccountId));
1492
1500
  for (let player of broadPlayers) {
1493
1501
  let broadPlayerMessage = `${player.steamAccount.name}的${random.pick(HEROES_CHINESE[player.hero.id])}`;
@@ -1506,7 +1514,7 @@ async function apply(ctx, config) {
1506
1514
  KDA:${((player.kills + player.assists) / (player.deaths || 1)).toFixed(2)} [${player.kills}/${player.deaths}/${player.assists}],GPM/XPM:${player.goldPerMinute}/${player.experiencePerMinute},补刀数:${player.numLastHits}/${player.numDenies},伤害/塔伤:${player.heroDamage}/${player.towerDamage},参战/参葬率:${(player.killContribution * 100).toFixed(2)}%/${(player.deathContribution * 100).toFixed(2)}%`;
1507
1515
  broadMatchMessage += broadPlayerMessage + "\n";
1508
1516
  }
1509
- await ctx.broadcast([`${comming.platform}:${comming.guildId}`], broadMatchMessage + img);
1517
+ await ctx.broadcast([`${commingGuild.platform}:${commingGuild.guildId}`], broadMatchMessage + img);
1510
1518
  }
1511
1519
  ctx.database.upsert("dt_previous_query_results", (row) => [{ matchId: match.id, data: match, queryTime: /* @__PURE__ */ new Date() }]);
1512
1520
  ctx.database.create("dt_sended_match_id", { matchId: match.id, sendTime: /* @__PURE__ */ new Date() });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sjtdev/koishi-plugin-dota2tracker",
3
3
  "description": "",
4
- "version": "1.1.2-beta.3",
4
+ "version": "1.1.2-beta.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -28,7 +28,7 @@
28
28
 
29
29
  .player.full .info {
30
30
  display: grid;
31
- grid-template-columns: repeat(2, 64px) auto 64px;
31
+ grid-template-columns: 64px auto 64px;
32
32
  align-items: center;
33
33
  /* border-bottom: #fff 1px solid; */
34
34
  position: relative;
@@ -37,15 +37,46 @@
37
37
  .player.full .info > .name {
38
38
  line-height: 20px;
39
39
  display: grid;
40
- grid-template-rows: 24px repeat(2, 20px);
40
+ grid-template-rows: 24px 18px 14px;
41
+ grid-template-columns: repeat(2, 1fr);
42
+ gap: 2px;
41
43
  text-align: center;
44
+ padding: 2px 0;
42
45
  }
43
46
  .player.full .info > .name > .nick_name {
44
- font-size: 18px;
47
+ font-size: 20px;
45
48
  line-height: 24px;
49
+ grid-column: 1/-1;
46
50
  }
47
- .player.full .info > .name >p{
48
- display: flex;justify-content: space-around;
51
+ .player.full .info > .name > .name {
52
+ line-height: 18px;
53
+ }
54
+ .player.full .info > .name > .id {
55
+ font-size: 12px;
56
+ line-height: 14px;
57
+ color: #888;
58
+ }
59
+ .player.full .info > .name > p {
60
+ display: flex;
61
+ justify-content: space-around;
62
+ }
63
+ .player.full .info > .avatar.steam {
64
+ position: relative;
65
+ }
66
+ .player.full .info > .avatar.steam > .rank {
67
+ top: 0;
68
+ right: 0;
69
+ width: 32px;
70
+ position: absolute;
71
+ }
72
+ .player.full .info > .avatar.steam > p {
73
+ z-index: 1;
74
+ position: absolute;
75
+ bottom: 35px;
76
+ left: 50%;
77
+ width: 32px;
78
+ text-align: center;
79
+ font-size: 4px;
49
80
  }
50
81
  .player.full .last_match_date {
51
82
  position: relative;
@@ -95,26 +126,31 @@
95
126
  </style>
96
127
  </head>
97
128
  <body>
98
- <% const users = data; %>
129
+ <% const users = data;
130
+ users.forEach(player=>{
131
+ player.rank = {
132
+ medal: parseInt(player.steamAccount.seasonRank?.toString().split("")[0] ?? 0),
133
+ star: parseInt(player.steamAccount.seasonRank?.toString().split("")[1] ?? 0),
134
+ leaderboard: player.steamAccount.seasonLeaderboardRank,
135
+ inTop100: player.steamAccount.seasonLeaderboardRank ? (player.steamAccount.seasonLeaderboardRank <= 10 ? "8c" : player.steamAccount.seasonLeaderboardRank <= 100 ? "8b" : undefined) : undefined,
136
+ }});%>
99
137
  <%-users.map(user=>`
100
138
  <div class="player full">
101
139
  <div class="info">
102
140
  <img class="avatar user" src="${user?.user?.avatar}" alt="" />
103
- <img class="avatar steam" src="${user.steamAccount.avatar}" alt="" />
104
141
  <div class="name">
105
- <p class="nick_name">
106
- <span>${user.nickName}</span>
107
- </p>
108
- <p class="user">
109
- <span>账号:${user.userId}</span>
110
- <span>用户名:${user?.user?.name}</span>
111
- </p>
112
- <p class="steam">
113
- <span>SteamID:${user.steamId}</span>
114
- <span>Steam用户名:${user.steamAccount.name}</span>
115
- </p>
142
+ <span class="nick_name">${user.nickName}</span>
143
+ <span class="user name">${user.nick || user.user?.name}</span>
144
+ <span class="steam name">${user.steamAccount.name}</span>
145
+ <span class="user id">${user.userId}</span>
146
+ <span class="steam id">${user.steamId}</span>
147
+ </div>
148
+ <div class="avatar steam">
149
+ <p>${user.steamAccount.seasonLeaderboardRank??""}</p>
150
+ <img class="rank" src="${utils.getImageUrl('star_' + player.rank.star)}" alt="" />
151
+ <img class="rank" src="${utils.getImageUrl('medal_' +(player.inTop100??player.rank.medal))}" alt="" />
152
+ <img class="avatar" src="${user.steamAccount.avatar}" alt="" />
116
153
  </div>
117
- <img class="rank" src="${utils.getImageUrl("medal_"+((!user.steamAccount.seasonRank)?0:Math.floor(user.steamAccount.seasonRank/10)))}" alt="" />
118
154
  </div>
119
155
  ${users.length<10?
120
156
  `<div class="last10match">