@sjtdev/koishi-plugin-dota2tracker 1.1.8 → 1.1.10-hotfix
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 +167 -110
- package/package.json +2 -2
- package/readme.md +3 -2
package/lib/index.js
CHANGED
|
@@ -828,12 +828,10 @@ __name(winRateColor, "winRateColor");
|
|
|
828
828
|
async function playerisValid(steamAccountId) {
|
|
829
829
|
try {
|
|
830
830
|
let queryRes = await query(VERIFYING_PLAYER(steamAccountId));
|
|
831
|
-
if (queryRes.
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
return { isValid: false, reason: "SteamID无效或无任何场次。" };
|
|
836
|
-
}
|
|
831
|
+
if (queryRes.data.player.matchCount != null)
|
|
832
|
+
return { isValid: true };
|
|
833
|
+
else
|
|
834
|
+
return { isValid: false, reason: "SteamID无效或无任何场次。" };
|
|
837
835
|
} catch (error) {
|
|
838
836
|
console.error(error);
|
|
839
837
|
return { isValid: false, reason: "网络状况不佳SteamID验证失败,请稍后重试。" };
|
|
@@ -1128,7 +1126,8 @@ DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑
|
|
|
1128
1126
|
var inject = ["http", "database", "cron", "puppeteer"];
|
|
1129
1127
|
var Config = import_koishi.Schema.intersect([
|
|
1130
1128
|
import_koishi.Schema.object({
|
|
1131
|
-
STRATZ_API_TOKEN: import_koishi.Schema.string().required().description("※必须。stratz.com的API TOKEN,可在 https://stratz.com/api
|
|
1129
|
+
STRATZ_API_TOKEN: import_koishi.Schema.string().required().description("※必须。stratz.com的API TOKEN,可在 https://stratz.com/api 获取。"),
|
|
1130
|
+
dataParsingTimeoutMinutes: import_koishi.Schema.number().default(60).min(0).max(1440).description("等待比赛数据解析的时间(单位:分钟)。如果数据解析时间超过等待时间,将直接生成战报而不再等待解析完成。")
|
|
1132
1131
|
}).description("基础设置"),
|
|
1133
1132
|
import_koishi.Schema.object({
|
|
1134
1133
|
dailyReportSwitch: import_koishi.Schema.boolean().default(false).description("日报功能").experimental()
|
|
@@ -1153,20 +1152,20 @@ async function apply(ctx, config) {
|
|
|
1153
1152
|
setHttp(ctx.http);
|
|
1154
1153
|
ctx.command("订阅本群", "订阅后还需玩家在本群绑定SteamID").usage("订阅后还需玩家在本群绑定SteamID,BOT将订阅本群中已绑定玩家的新比赛数据,在STRATZ比赛解析完成后将比赛数据生成为图片战报发布至本群中。").action(async ({ session }) => {
|
|
1155
1154
|
if (session.guild) {
|
|
1156
|
-
let currentGuild = (await ctx.database.get("dt_subscribed_guilds", { guildId: session.event.
|
|
1155
|
+
let currentGuild = (await ctx.database.get("dt_subscribed_guilds", { guildId: session.event.channel.id, platform: session.event.platform }))[0];
|
|
1157
1156
|
if (currentGuild)
|
|
1158
1157
|
session.send("本群已订阅,无需重复订阅。");
|
|
1159
1158
|
else {
|
|
1160
|
-
ctx.database.create("dt_subscribed_guilds", { guildId: session.event.
|
|
1159
|
+
ctx.database.create("dt_subscribed_guilds", { guildId: session.event.channel.id, platform: session.event.platform });
|
|
1161
1160
|
session.send("订阅成功。");
|
|
1162
1161
|
}
|
|
1163
1162
|
}
|
|
1164
1163
|
});
|
|
1165
1164
|
ctx.command("取消订阅", "取消订阅本群").action(async ({ session }) => {
|
|
1166
1165
|
if (session.guild) {
|
|
1167
|
-
let cancelingGuild = (await ctx.database.get("dt_subscribed_guilds", { guildId: session.event.
|
|
1166
|
+
let cancelingGuild = (await ctx.database.get("dt_subscribed_guilds", { guildId: session.event.channel.id, platform: session.event.platform }))[0];
|
|
1168
1167
|
if (cancelingGuild) {
|
|
1169
|
-
ctx.database.remove("dt_subscribed_guilds", session.event.
|
|
1168
|
+
ctx.database.remove("dt_subscribed_guilds", session.event.channel.id);
|
|
1170
1169
|
session.send("取消订阅成功。");
|
|
1171
1170
|
return;
|
|
1172
1171
|
}
|
|
@@ -1179,7 +1178,7 @@ async function apply(ctx, config) {
|
|
|
1179
1178
|
session.send("SteamID无效。");
|
|
1180
1179
|
return;
|
|
1181
1180
|
}
|
|
1182
|
-
let sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1181
|
+
let sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.event.platform, userId: session.event.user.id }))[0];
|
|
1183
1182
|
if (sessionPlayer) {
|
|
1184
1183
|
session.send(
|
|
1185
1184
|
`
|
|
@@ -1207,12 +1206,12 @@ async function apply(ctx, config) {
|
|
|
1207
1206
|
别名:${nick_name || ""}
|
|
1208
1207
|
SteamID:${steam_id}`.replace(/\n\s+/g, " ")
|
|
1209
1208
|
);
|
|
1210
|
-
ctx.database.create("dt_subscribed_players", { userId: session.event.user.id, guildId: session.event.
|
|
1209
|
+
ctx.database.create("dt_subscribed_players", { userId: session.event.user.id, guildId: session.event.channel.id, platform: session.event.platform, steamId: parseInt(steam_id), nickName: nick_name || null });
|
|
1211
1210
|
}
|
|
1212
1211
|
});
|
|
1213
1212
|
ctx.command("取消绑定", "取消绑定你的个人信息").action(async ({ session }) => {
|
|
1214
1213
|
if (session.guild) {
|
|
1215
|
-
let sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1214
|
+
let sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.event.platform, userId: session.event.user.id }))[0];
|
|
1216
1215
|
if (sessionPlayer) {
|
|
1217
1216
|
await ctx.database.remove("dt_subscribed_players", sessionPlayer.id);
|
|
1218
1217
|
session.send("取消绑定成功。");
|
|
@@ -1222,7 +1221,7 @@ async function apply(ctx, config) {
|
|
|
1222
1221
|
});
|
|
1223
1222
|
ctx.command("改名 <nick_name>", "修改绑定时设定的别名").example("-改名 李四").action(async ({ session }, nick_name) => {
|
|
1224
1223
|
if (session.guild) {
|
|
1225
|
-
let sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1224
|
+
let sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.event.platform, userId: session.event.user.id }))[0];
|
|
1226
1225
|
if (sessionPlayer) {
|
|
1227
1226
|
if (!nick_name) {
|
|
1228
1227
|
session.send("请输入你的别名。");
|
|
@@ -1242,14 +1241,14 @@ async function apply(ctx, config) {
|
|
|
1242
1241
|
});
|
|
1243
1242
|
ctx.command("查询群友", "查询本群已绑定的玩家").action(async ({ session }) => {
|
|
1244
1243
|
if (session.guild) {
|
|
1245
|
-
const subscribedPlayers = await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1244
|
+
const subscribedPlayers = await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.platform });
|
|
1246
1245
|
if (!subscribedPlayers.length) {
|
|
1247
1246
|
session.send("本群尚无绑定玩家。");
|
|
1248
1247
|
return;
|
|
1249
1248
|
}
|
|
1250
1249
|
if (subscribedPlayers.length <= 20) {
|
|
1251
1250
|
try {
|
|
1252
|
-
const memberList = await session.bot.getGuildMemberList(session.event.
|
|
1251
|
+
const memberList = await session.bot.getGuildMemberList(session.event.channel.id);
|
|
1253
1252
|
async function getUsers(subscribedPlayers2, utils, queries, memberList2) {
|
|
1254
1253
|
const playerSteamIds = subscribedPlayers2.map((player) => player.steamId);
|
|
1255
1254
|
const queryResult = await utils.query(queries.PLAYERS_INFO_WITH_10_MATCHES_FOR_GUILD(playerSteamIds));
|
|
@@ -1282,12 +1281,12 @@ async function apply(ctx, config) {
|
|
|
1282
1281
|
} else {
|
|
1283
1282
|
match = getFormattedMatchData((await query(MATCH_INFO(matchId))).data.match);
|
|
1284
1283
|
}
|
|
1285
|
-
if (match && (match.parsedDateTime || import_moment.default.unix(match.endDateTime).isBefore((0, import_moment.default)().subtract(
|
|
1284
|
+
if (match && (match.parsedDateTime || import_moment.default.unix(match.endDateTime).isBefore((0, import_moment.default)().subtract(config.dataParsingTimeoutMinutes, "minutes")))) {
|
|
1286
1285
|
session.send(await ctx.puppeteer.render(genImageHTML(match, config.template_match, "match" /* Match */)));
|
|
1287
1286
|
if (match.parsedDateTime)
|
|
1288
1287
|
ctx.database.upsert("dt_previous_query_results", (row) => [{ matchId: match.id, data: match, queryTime: /* @__PURE__ */ new Date() }]);
|
|
1289
1288
|
} else {
|
|
1290
|
-
pendingMatches.push({ matchId, guilds: [{ platform: session.event.platform, guildId: session.event.
|
|
1289
|
+
pendingMatches.push({ matchId, guilds: [{ platform: session.event.platform, guildId: session.event.channel.id, players: [] }] });
|
|
1291
1290
|
session.send("比赛尚未解析,将在解析完成后发布。");
|
|
1292
1291
|
}
|
|
1293
1292
|
} catch (error) {
|
|
@@ -1314,13 +1313,13 @@ async function apply(ctx, config) {
|
|
|
1314
1313
|
if (session.guild) {
|
|
1315
1314
|
let sessionPlayer;
|
|
1316
1315
|
if (!input_data) {
|
|
1317
|
-
sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1316
|
+
sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.event.platform, userId: session.event.user.id }))[0];
|
|
1318
1317
|
if (!sessionPlayer) {
|
|
1319
1318
|
session.send("无参数时默认从已绑定SteamID玩家中寻找你的信息,但你似乎并没有绑定。\n请在本群绑定SteamID。(可输入【-绑定 -h】获取帮助)\n或在指令后跟上希望查询的SteamID或已绑定玩家的别名。");
|
|
1320
1319
|
return;
|
|
1321
1320
|
}
|
|
1322
1321
|
}
|
|
1323
|
-
let flagBindedPlayer = sessionPlayer || (await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1322
|
+
let flagBindedPlayer = sessionPlayer || (await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.event.platform, nickName: input_data }))[0];
|
|
1324
1323
|
if (!(flagBindedPlayer || /^\d{1,11}$/.test(input_data))) {
|
|
1325
1324
|
session.send("SteamID不合法并且未在本群找到此玩家。");
|
|
1326
1325
|
return;
|
|
@@ -1340,13 +1339,13 @@ async function apply(ctx, config) {
|
|
|
1340
1339
|
if (session.guild) {
|
|
1341
1340
|
let sessionPlayer;
|
|
1342
1341
|
if (!input_data) {
|
|
1343
|
-
sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1342
|
+
sessionPlayer = (await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.event.platform, userId: session.event.user.id }))[0];
|
|
1344
1343
|
if (!sessionPlayer) {
|
|
1345
1344
|
session.send("无参数时默认从已绑定SteamID玩家中寻找你的信息,但你似乎并没有绑定。\n请在本群绑定SteamID。(可输入【-绑定 -h】获取帮助)\n或在指令后跟上希望查询的SteamID或已绑定玩家的别名。");
|
|
1346
1345
|
return;
|
|
1347
1346
|
}
|
|
1348
1347
|
}
|
|
1349
|
-
let flagBindedPlayer = sessionPlayer || (await ctx.database.get("dt_subscribed_players", { guildId: session.event.
|
|
1348
|
+
let flagBindedPlayer = sessionPlayer || (await ctx.database.get("dt_subscribed_players", { guildId: session.event.channel.id, platform: session.event.platform, nickName: input_data }))[0];
|
|
1350
1349
|
if (!(flagBindedPlayer || /^\d{1,11}$/.test(input_data))) {
|
|
1351
1350
|
session.send("SteamID不合法并且未在本群找到此玩家。");
|
|
1352
1351
|
return;
|
|
@@ -1414,13 +1413,13 @@ async function apply(ctx, config) {
|
|
|
1414
1413
|
let AbilitiesConstantsCN;
|
|
1415
1414
|
let queryConstants = (await query(CURRENT_GAMEVERSION())).data.constants;
|
|
1416
1415
|
AbilitiesConstantsCN = (await ctx.database.get("dt_constants_abilities_cn", [1]))[0];
|
|
1417
|
-
if (!AbilitiesConstantsCN || AbilitiesConstantsCN.
|
|
1416
|
+
if (!AbilitiesConstantsCN || AbilitiesConstantsCN.gameVersionId < queryConstants.gameVersions[0].id) {
|
|
1418
1417
|
session.send("初次使用或版本更新,正在更新英雄技能数据中……");
|
|
1419
1418
|
AbilitiesConstantsCN = { data: (await query(ALL_ABILITIES_CHINESE_NAME())).data.constants };
|
|
1420
1419
|
await ctx.database.upsert("dt_constants_abilities_cn", (row) => [{ id: 1, data: AbilitiesConstantsCN, gameVersionId: queryConstants.gameVersions[0].id, gameVersionName: queryConstants.gameVersions[0].name }]);
|
|
1421
1420
|
}
|
|
1422
1421
|
let hero = (await query(HERO_INFO(fhero.id))).data.constants.hero;
|
|
1423
|
-
hero.talents.forEach((talent) => talent.name_cn = AbilitiesConstantsCN.data.abilities
|
|
1422
|
+
hero.talents.forEach((talent) => talent.name_cn = AbilitiesConstantsCN.data.abilities?.find((item) => item.id == talent.abilityId)?.language?.displayName);
|
|
1424
1423
|
await session.send(await ctx.puppeteer.render(genImageHTML(hero, config.template_hero, "hero" /* Hero */)));
|
|
1425
1424
|
} catch (error) {
|
|
1426
1425
|
ctx.logger.error(error);
|
|
@@ -1489,98 +1488,156 @@ async function apply(ctx, config) {
|
|
|
1489
1488
|
}
|
|
1490
1489
|
__name(findingHero, "findingHero");
|
|
1491
1490
|
ctx.command("7.36 <input_data>", "查询7.36改动").option("refresh", "-r 重新获取数据").usage("可查询英雄改动并生成图片返回").example("7.36 小松许").action(async ({ session, options }, input_data) => {
|
|
1492
|
-
if (!("dt_7_36" in ctx.database.tables)
|
|
1493
|
-
session.send((!("dt_7_36" in ctx.database.tables) ? "初次使用," : "") + "正在获取数据……");
|
|
1491
|
+
if (!("dt_7_36" in ctx.database.tables))
|
|
1494
1492
|
await ctx.model.extend("dt_7_36", { id: "integer", data: "string" });
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
scripts.forEach((script) => script.remove());
|
|
1504
|
-
});
|
|
1505
|
-
const result = await page.evaluate(() => {
|
|
1506
|
-
const divs = document.querySelectorAll("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(3) > div:nth-of-type(5) > div:nth-of-type(2) > div");
|
|
1507
|
-
const divArray = [];
|
|
1508
|
-
divs.forEach((div) => {
|
|
1509
|
-
const subDiv = div.querySelector("a > div");
|
|
1510
|
-
const match = subDiv?.style.backgroundImage.match(/url\("https:\/\/cdn\.cloudflare\.steamstatic\.com\/apps\/dota2\/images\/dota_react\/heroes\/([^"]+)\.png"\)/);
|
|
1511
|
-
divArray.push({ heroName: match[1], div: div.outerHTML });
|
|
1493
|
+
const tem = await ctx.database.get("dt_7_36", void 0, ["id"]);
|
|
1494
|
+
if (!tem.length || options.refresh) {
|
|
1495
|
+
try {
|
|
1496
|
+
session.send((!tem.length ? "初次使用," : "") + "正在获取数据……");
|
|
1497
|
+
await ctx.model.extend("dt_7_36", { id: "integer", data: "string" });
|
|
1498
|
+
const page = await ctx.puppeteer.page();
|
|
1499
|
+
await page.setExtraHTTPHeaders({
|
|
1500
|
+
"Accept-Language": "zh-CN,zh;q=0.9"
|
|
1512
1501
|
});
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1502
|
+
await page.goto("https://www.dota2.com/patches/7.36");
|
|
1503
|
+
await page.waitForSelector("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(3) > div:nth-of-type(5) > div:nth-of-type(2) > div:nth-of-type(1)");
|
|
1504
|
+
await page.evaluate(() => {
|
|
1505
|
+
const scripts = document.querySelectorAll("script");
|
|
1506
|
+
scripts.forEach((script) => script.remove());
|
|
1507
|
+
});
|
|
1508
|
+
const result = await page.evaluate(() => {
|
|
1509
|
+
try {
|
|
1510
|
+
const divs = document.querySelectorAll("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(3) > div:nth-of-type(5) > div:nth-of-type(2) > div");
|
|
1511
|
+
const divArray = [];
|
|
1512
|
+
divs.forEach((div) => {
|
|
1513
|
+
const subDiv = div.querySelector("a > div");
|
|
1514
|
+
console.log(subDiv);
|
|
1515
|
+
const match = subDiv?.style.backgroundImage.match(/\/apps\/dota2\/images\/dota_react\/heroes\/([^"]+)\.png"\)/);
|
|
1516
|
+
console.log(match);
|
|
1517
|
+
divArray.push({ heroName: match[1], div: div.outerHTML });
|
|
1518
|
+
});
|
|
1519
|
+
document.querySelectorAll("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(3) > div:nth-of-type(5) > div:nth-of-type(2) > div:not(:first-of-type)").forEach((node) => node.remove());
|
|
1520
|
+
document.querySelector("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(3) > div:nth-of-type(5) > div:nth-of-type(2) > div").classList.add("placeholder");
|
|
1521
|
+
const prepareToRemovesNodes = [
|
|
1522
|
+
document.querySelector("body > div:first-of-type"),
|
|
1523
|
+
document.querySelector("body > div:nth-of-type(2) > div:first-of-type > div:first-of-type"),
|
|
1524
|
+
document.querySelector("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(1)"),
|
|
1525
|
+
document.querySelector("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(2)"),
|
|
1526
|
+
document.querySelector("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(3) > div:nth-of-type(5) > div:nth-of-type(1)"),
|
|
1527
|
+
...document.querySelectorAll("body > div:nth-of-type(2) > div:first-of-type > div:nth-of-type(2) > div:nth-of-type(3) > div:not(:last-of-type)")
|
|
1528
|
+
];
|
|
1529
|
+
prepareToRemovesNodes.forEach((node) => node?.remove());
|
|
1530
|
+
const remainingContent = document.documentElement.outerHTML;
|
|
1531
|
+
return {
|
|
1532
|
+
divArray,
|
|
1533
|
+
remainingContent
|
|
1534
|
+
};
|
|
1535
|
+
} catch (error) {
|
|
1536
|
+
console.error(error);
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
page.close();
|
|
1540
|
+
const heroes3 = [];
|
|
1541
|
+
result.divArray.forEach((hero) => {
|
|
1542
|
+
const res = Object.values(dotaconstants3.heroes).find((Chero) => Chero.name.match(/^npc_dota_hero_(.+)$/)[1] == hero.heroName);
|
|
1543
|
+
heroes3.push({ id: res.id, data: hero.div });
|
|
1544
|
+
});
|
|
1545
|
+
heroes3.push({ id: 0, data: result.remainingContent });
|
|
1546
|
+
await ctx.database.upsert("dt_7_36", (row) => heroes3);
|
|
1547
|
+
await session.send("数据获取完成。");
|
|
1548
|
+
} catch (error) {
|
|
1549
|
+
ctx.logger.error(error);
|
|
1550
|
+
session.send("数据获取失败。");
|
|
1535
1551
|
return;
|
|
1536
1552
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
(
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
await
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
img.onload = resolve;
|
|
1560
|
-
img.onerror = () => {
|
|
1561
|
-
const placeholderSrc = "https://cdn.cloudflare.steamstatic.com/apps/dota2/images/dota_react/icons/innate_icon.png";
|
|
1562
|
-
img.src = placeholderSrc;
|
|
1563
|
-
img.onload = resolve;
|
|
1564
|
-
img.onerror = resolve;
|
|
1565
|
-
};
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
|
-
})
|
|
1553
|
+
}
|
|
1554
|
+
if (input_data) {
|
|
1555
|
+
try {
|
|
1556
|
+
const hero = findingHero(input_data);
|
|
1557
|
+
if (!hero) {
|
|
1558
|
+
session.send("英雄参数输入有误,请检查后重试。");
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
session.send("正在查询,请耐心等待……");
|
|
1562
|
+
const page = await ctx.puppeteer.page();
|
|
1563
|
+
await page.setRequestInterception(false);
|
|
1564
|
+
const [wrapperHTML, newHeroHTML] = (await ctx.database.get("dt_7_36", [0, hero.id])).map((data) => data.data);
|
|
1565
|
+
await page.setContent(wrapperHTML);
|
|
1566
|
+
await page.waitForSelector("div.placeholder");
|
|
1567
|
+
const placeholder = await page.$("div.placeholder");
|
|
1568
|
+
await page.waitForSelector("div.placeholder");
|
|
1569
|
+
await page.evaluate(
|
|
1570
|
+
(element, html) => {
|
|
1571
|
+
element.outerHTML = html;
|
|
1572
|
+
},
|
|
1573
|
+
placeholder,
|
|
1574
|
+
newHeroHTML
|
|
1569
1575
|
);
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1576
|
+
await page.evaluate(async () => {
|
|
1577
|
+
const images = Array.from(document.querySelectorAll("img"));
|
|
1578
|
+
const backgroundImages = Array.from(document.querySelectorAll("*")).filter((element) => {
|
|
1579
|
+
const bg = window.getComputedStyle(element).backgroundImage;
|
|
1580
|
+
return bg && bg !== "none";
|
|
1581
|
+
});
|
|
1582
|
+
await Promise.all([
|
|
1583
|
+
...images.map((img) => {
|
|
1584
|
+
if (img.complete)
|
|
1585
|
+
return Promise.resolve();
|
|
1586
|
+
else {
|
|
1587
|
+
return new Promise((resolve) => {
|
|
1588
|
+
img.onload = resolve;
|
|
1589
|
+
img.onerror = () => {
|
|
1590
|
+
const placeholderSrc = "https://cdn.cloudflare.steamstatic.com/apps/dota2/images/dota_react/icons/innate_icon.png";
|
|
1591
|
+
img.src = placeholderSrc;
|
|
1592
|
+
img.onload = resolve;
|
|
1593
|
+
img.onerror = resolve;
|
|
1594
|
+
};
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
}),
|
|
1598
|
+
...backgroundImages.map((element) => {
|
|
1599
|
+
const bg = window.getComputedStyle(element).backgroundImage;
|
|
1600
|
+
const urlMatch = bg.match(/url\(["']?([^"')]+)["']?\)/);
|
|
1601
|
+
if (urlMatch && urlMatch[1]) {
|
|
1602
|
+
const src = urlMatch[1];
|
|
1603
|
+
return new Promise((resolve) => {
|
|
1604
|
+
const img = new Image();
|
|
1605
|
+
img.onload = resolve;
|
|
1606
|
+
img.onerror = () => {
|
|
1607
|
+
const placeholderSrc = "https://cdn.cloudflare.steamstatic.com/apps/dota2/images/dota_react/icons/innate_icon.png";
|
|
1608
|
+
img.src = placeholderSrc;
|
|
1609
|
+
img.onload = resolve;
|
|
1610
|
+
img.onerror = resolve;
|
|
1611
|
+
};
|
|
1612
|
+
img.src = src;
|
|
1613
|
+
});
|
|
1614
|
+
} else
|
|
1615
|
+
return Promise.resolve();
|
|
1616
|
+
})
|
|
1617
|
+
]);
|
|
1618
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1619
|
+
});
|
|
1620
|
+
const testE = await page.$("body > div > div > div > div > div > div > div");
|
|
1621
|
+
const res = await testE.screenshot();
|
|
1622
|
+
const base64String = Buffer.from(res).toString("base64");
|
|
1623
|
+
const imgTag = `<img src="data:image/png;base64,${base64String}" alt="Image" />`;
|
|
1624
|
+
if (process.env.NODE_ENV === "development")
|
|
1625
|
+
import_fs2.default.writeFileSync("./node_modules/@sjtdev/koishi-plugin-dota2tracker/temp.png", res);
|
|
1626
|
+
if (process.env.NODE_ENV === "development")
|
|
1627
|
+
import_fs2.default.writeFileSync("./node_modules/@sjtdev/koishi-plugin-dota2tracker/temp.html", await page.content());
|
|
1628
|
+
session.send(imgTag);
|
|
1629
|
+
page.close();
|
|
1630
|
+
} catch (error) {
|
|
1631
|
+
ctx.logger.error(error);
|
|
1632
|
+
session.send("查询改动失败。");
|
|
1633
|
+
}
|
|
1581
1634
|
} else
|
|
1582
1635
|
session.send("https://www.dota2.com/patches/7.36");
|
|
1583
1636
|
});
|
|
1637
|
+
ctx.command("test <input_data>").option("a", "a").action(async ({ session, options }, input_data) => {
|
|
1638
|
+
console.log(session);
|
|
1639
|
+
ctx.broadcast(["kook:9510442027074966"], "test");
|
|
1640
|
+
});
|
|
1584
1641
|
ctx.on("ready", async () => {
|
|
1585
1642
|
const tables = await ctx.database.tables;
|
|
1586
1643
|
if (!("dt_subscribed_guilds" in tables)) {
|
|
@@ -1711,7 +1768,7 @@ async function apply(ctx, config) {
|
|
|
1711
1768
|
ctx.database.set("dt_previous_query_results", match.id, { queryTime: /* @__PURE__ */ new Date() });
|
|
1712
1769
|
} else
|
|
1713
1770
|
match = getFormattedMatchData((await query(MATCH_INFO(pendingMatch.matchId))).data.match);
|
|
1714
|
-
if (match.parsedDateTime || import_moment.default.unix(match.endDateTime).isBefore((0, import_moment.default)().subtract(
|
|
1771
|
+
if (match.parsedDateTime || import_moment.default.unix(match.endDateTime).isBefore((0, import_moment.default)().subtract(config.dataParsingTimeoutMinutes, "minutes"))) {
|
|
1715
1772
|
pendingMatches = pendingMatches.filter((item) => item.matchId != match.id);
|
|
1716
1773
|
const img = await ctx.puppeteer.render(genImageHTML(match, config.template_match, "match" /* Match */));
|
|
1717
1774
|
for (let commingGuild of pendingMatch.guilds) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -8,7 +8,7 @@ DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑
|
|
|
8
8
|
|
|
9
9
|
### 使用
|
|
10
10
|
需在插件配置页填入STRATZ API TOKEN,否则无法使用。(配置中提供了API的获取链接)
|
|
11
|
-
|
|
11
|
+
在希望推送战报信息的群组(或频道)使用指令`订阅本群`,玩家可使用指令`绑定`来将自身账号与Steam账号绑定,bot会尝试追踪已订阅群组(或频道)中的绑定玩家的最新对局信息。
|
|
12
12
|
其他查询功能见下方指令说明。
|
|
13
13
|
**直接调用help指令可获取更详细的说明,调用【指令 -h】还会有用法示例。(例如:订阅本群 -h)**
|
|
14
14
|
**更新日志见[changelog](changelog.md)**
|
|
@@ -16,7 +16,8 @@ DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑
|
|
|
16
16
|
### 指令
|
|
17
17
|
指令 <必填参数> [可选参数]
|
|
18
18
|
##### 订阅
|
|
19
|
-
(bot
|
|
19
|
+
(bot仅向已订阅群组/频道推送信息)
|
|
20
|
+
(若是使用Discord、KOOK频道类平台,订阅与绑定信息仅对单个频道生效,频道间相互独立)
|
|
20
21
|
* `订阅本群`
|
|
21
22
|
* `取消订阅`
|
|
22
23
|
##### 绑定
|