@sjtdev/koishi-plugin-dota2tracker 1.1.9 → 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 +139 -85
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1419,7 +1419,7 @@ async function apply(ctx, config) {
|
|
|
1419
1419
|
await ctx.database.upsert("dt_constants_abilities_cn", (row) => [{ id: 1, data: AbilitiesConstantsCN, gameVersionId: queryConstants.gameVersions[0].id, gameVersionName: queryConstants.gameVersions[0].name }]);
|
|
1420
1420
|
}
|
|
1421
1421
|
let hero = (await query(HERO_INFO(fhero.id))).data.constants.hero;
|
|
1422
|
-
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);
|
|
1423
1423
|
await session.send(await ctx.puppeteer.render(genImageHTML(hero, config.template_hero, "hero" /* Hero */)));
|
|
1424
1424
|
} catch (error) {
|
|
1425
1425
|
ctx.logger.error(error);
|
|
@@ -1488,95 +1488,149 @@ async function apply(ctx, config) {
|
|
|
1488
1488
|
}
|
|
1489
1489
|
__name(findingHero, "findingHero");
|
|
1490
1490
|
ctx.command("7.36 <input_data>", "查询7.36改动").option("refresh", "-r 重新获取数据").usage("可查询英雄改动并生成图片返回").example("7.36 小松许").action(async ({ session, options }, input_data) => {
|
|
1491
|
-
if (!("dt_7_36" in ctx.database.tables)
|
|
1492
|
-
session.send((!("dt_7_36" in ctx.database.tables) ? "初次使用," : "") + "正在获取数据……");
|
|
1491
|
+
if (!("dt_7_36" in ctx.database.tables))
|
|
1493
1492
|
await ctx.model.extend("dt_7_36", { id: "integer", data: "string" });
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
scripts.forEach((script) => script.remove());
|
|
1503
|
-
});
|
|
1504
|
-
const result = await page.evaluate(() => {
|
|
1505
|
-
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");
|
|
1506
|
-
const divArray = [];
|
|
1507
|
-
divs.forEach((div) => {
|
|
1508
|
-
const subDiv = div.querySelector("a > div");
|
|
1509
|
-
const match = subDiv?.style.backgroundImage.match(/url\("https:\/\/cdn\.cloudflare\.steamstatic\.com\/apps\/dota2\/images\/dota_react\/heroes\/([^"]+)\.png"\)/);
|
|
1510
|
-
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"
|
|
1511
1501
|
});
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
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("数据获取失败。");
|
|
1534
1551
|
return;
|
|
1535
1552
|
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
(
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
await
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
img.onload = resolve;
|
|
1559
|
-
img.onerror = () => {
|
|
1560
|
-
const placeholderSrc = "https://cdn.cloudflare.steamstatic.com/apps/dota2/images/dota_react/icons/innate_icon.png";
|
|
1561
|
-
img.src = placeholderSrc;
|
|
1562
|
-
img.onload = resolve;
|
|
1563
|
-
img.onerror = resolve;
|
|
1564
|
-
};
|
|
1565
|
-
});
|
|
1566
|
-
}
|
|
1567
|
-
})
|
|
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
|
|
1568
1575
|
);
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
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
|
+
}
|
|
1580
1634
|
} else
|
|
1581
1635
|
session.send("https://www.dota2.com/patches/7.36");
|
|
1582
1636
|
});
|