@sjtdev/koishi-plugin-dota2tracker 1.2.1 → 1.2.2

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
@@ -1469,7 +1469,7 @@ async function apply(ctx, config) {
1469
1469
  }
1470
1470
  }
1471
1471
  });
1472
- ctx.command("查询英雄 <input_data>", "查询英雄技能/面板信息").usage("查询英雄的技能说明与各项数据,生成图片发布。\n参数可输入英雄ID、英雄名、英雄常用别名").option("random", "-r 随机选择英雄").option("refresh", "-f 忽略缓存刷新数据").example("-查询英雄 15").example("-查询英雄 雷泽").example("-查询英雄 电魂").action(async ({ session, options }, input_data) => {
1472
+ ctx.command("查询英雄 <input_data>", "查询英雄技能/面板信息").usage("查询英雄的技能说明与各项数据,生成图片发布。\n参数可输入英雄ID、英雄名、英雄常用别名").option("random", "-r 随机选择英雄").example("-查询英雄 15").example("-查询英雄 雷泽").example("-查询英雄 电魂").action(async ({ session, options }, input_data) => {
1473
1473
  if (options.random)
1474
1474
  input_data = random.pick(Object.keys(HEROES_CHINESE));
1475
1475
  if (input_data) {
@@ -1478,94 +1478,81 @@ async function apply(ctx, config) {
1478
1478
  session.send("未找到输入的英雄,请确认后重新输入。");
1479
1479
  return;
1480
1480
  }
1481
+ await session.send("正在获取英雄数据,请稍后...");
1481
1482
  try {
1482
- const tempHero = await ctx.database.get("dt_hero_data_cache", hero.id);
1483
- if (tempHero.length && !options.refresh) {
1484
- const gameVersionId = (await query(CURRENT_GAMEVERSION())).data.constants.gameVersions[0].id;
1485
- if (tempHero[0].gameVersionId >= gameVersionId) {
1486
- hero = tempHero[0].hero;
1483
+ const queryHero = await queryHeroFromValve(hero.id);
1484
+ Object.assign(hero, queryHero);
1485
+ hero.facet_abilities.forEach((fa, i) => {
1486
+ if (fa.abilities.length) {
1487
+ fa.abilities.forEach((ab) => {
1488
+ if (!hero.facets[i].abilities)
1489
+ hero.facets[i].abilities = [];
1490
+ if (hero.facets[i].description_loc !== ab.desc_loc)
1491
+ hero.facets[i].abilities.push({ id: ab.id, name: ab.name, name_loc: ab.name_loc, description_ability_loc: formatHeroDesc(ab.desc_loc, ab.special_values, "facet" /* Facet */) });
1492
+ else
1493
+ hero.facets[i].description_loc = formatHeroDesc(hero.facets[i].description_loc, ab.special_values, "facet" /* Facet */);
1494
+ ab.ability_is_facet = true;
1495
+ hero.abilities.push(ab);
1496
+ });
1487
1497
  }
1488
- } else {
1489
- const queryHero = await queryHeroFromValve(hero.id);
1490
- Object.assign(hero, queryHero);
1491
- hero.facet_abilities.forEach((fa, i) => {
1492
- if (fa.abilities.length) {
1493
- fa.abilities.forEach((ab) => {
1494
- if (!hero.facets[i].abilities)
1495
- hero.facets[i].abilities = [];
1496
- if (hero.facets[i].description_loc !== ab.desc_loc)
1497
- hero.facets[i].abilities.push({ id: ab.id, name: ab.name, name_loc: ab.name_loc, description_ability_loc: formatHeroDesc(ab.desc_loc, ab.special_values, "facet" /* Facet */) });
1498
- else
1499
- hero.facets[i].description_loc = formatHeroDesc(hero.facets[i].description_loc, ab.special_values, "facet" /* Facet */);
1500
- hero.abilities.push(ab);
1501
- });
1498
+ });
1499
+ const all_special_values = [...hero.abilities.flatMap((ab) => ab.special_values), ...hero.facet_abilities.flatMap((fas) => fas.abilities.flatMap((fa) => fa.special_values))];
1500
+ hero.abilities.forEach((ab) => {
1501
+ ab.facets_loc.forEach((facet, i) => {
1502
+ if (facet) {
1503
+ if (!hero.facets[i].abilities)
1504
+ hero.facets[i].abilities = [];
1505
+ hero.facets[i].abilities.push({ id: ab.id, name: ab.name, name_loc: ab.name_loc, description_ability_loc: formatHeroDesc(facet, all_special_values, "facet" /* Facet */), attributes: [] });
1502
1506
  }
1503
1507
  });
1504
- const all_special_values = [...hero.abilities.flatMap((ab) => ab.special_values), ...hero.facet_abilities.flatMap((fas) => fas.abilities.flatMap((fa) => fa.special_values))];
1505
- hero.abilities.forEach((ab) => {
1506
- ab.facets_loc.forEach((facet, i) => {
1507
- if (facet) {
1508
- if (!hero.facets[i].abilities)
1509
- hero.facets[i].abilities = [];
1510
- hero.facets[i].abilities.push({ id: ab.id, name: ab.name, name_loc: ab.name_loc, description_ability_loc: formatHeroDesc(facet, all_special_values, "facet" /* Facet */), attributes: [] });
1508
+ hero.facets.forEach((facet) => {
1509
+ const svs = ab.special_values.filter((sv) => sv.facet_bonus.name === facet.name);
1510
+ svs.forEach((sv) => {
1511
+ if (sv.heading_loc) {
1512
+ facet.abilities.find((ability) => ab.id == ability.id)?.attributes.push({ heading_loc: sv.heading_loc, values: [...sv.facet_bonus.values] });
1511
1513
  }
1512
1514
  });
1513
- hero.facets.forEach((facet) => {
1514
- const svs = ab.special_values.filter((sv) => sv.facet_bonus.name === facet.name);
1515
- svs.forEach((sv) => {
1516
- if (sv.heading_loc) {
1517
- facet.abilities.find((ability) => ab.id == ability.id)?.attributes.push({ heading_loc: sv.heading_loc, values: [...sv.facet_bonus.values] });
1518
- }
1519
- });
1520
- });
1521
- ab.desc_loc = formatHeroDesc(ab.desc_loc, all_special_values);
1522
- ab.notes_loc = ab.notes_loc.map((note) => formatHeroDesc(note, all_special_values));
1523
- if (ab.ability_has_scepter)
1524
- ab.scepter_loc = formatHeroDesc(ab.scepter_loc, ab.special_values, "scepter" /* Scepter */);
1525
- if (ab.ability_has_shard)
1526
- ab.shard_loc = formatHeroDesc(ab.shard_loc, ab.special_values, "shard" /* Shard */);
1527
1515
  });
1528
- hero.talents.forEach((talent) => {
1529
- const regex = /\{s:(.*?)\}/g;
1530
- let match;
1531
- while ((match = regex.exec(talent.name_loc)) !== null) {
1532
- const specialValueName = match[1];
1533
- const target = talent.special_values?.find((sv) => sv.name === specialValueName);
1534
- if (target) {
1535
- talent.name_loc = talent.name_loc.replace(match[0], target.values_float.join("/"));
1536
- } else {
1537
- const ability = hero.abilities.find((ability2) => ability2.special_values.some((specialValue) => specialValue.bonuses.some((bonus) => bonus.name === talent.name)));
1538
- if (ability) {
1539
- const specialValues = ability.special_values.filter((specialValue) => specialValue.bonuses.some((bonus) => bonus.name === talent.name));
1540
- const regex2 = /{s:bonus_(.*?)}/g;
1541
- let match2;
1542
- const replacements = [];
1543
- while ((match2 = regex2.exec(talent.name_loc)) !== null) {
1544
- const specialValue = specialValues.find((sv) => sv.name === String(match2[1]));
1545
- const replacement = specialValue?.bonuses.find((bonus) => bonus.name === talent.name)?.value;
1546
- if (replacement !== void 0) {
1547
- replacements.push({ original: match2[0], replacement });
1548
- }
1516
+ ab.desc_loc = formatHeroDesc(ab.desc_loc, all_special_values);
1517
+ ab.notes_loc = ab.notes_loc.map((note) => formatHeroDesc(note, all_special_values));
1518
+ if (ab.ability_has_scepter)
1519
+ ab.scepter_loc = formatHeroDesc(ab.scepter_loc, ab.special_values, "scepter" /* Scepter */);
1520
+ if (ab.ability_has_shard)
1521
+ ab.shard_loc = formatHeroDesc(ab.shard_loc, ab.special_values, "shard" /* Shard */);
1522
+ });
1523
+ hero.talents.forEach((talent) => {
1524
+ const regex = /\{s:(.*?)\}/g;
1525
+ let match;
1526
+ while ((match = regex.exec(talent.name_loc)) !== null) {
1527
+ const specialValueName = match[1];
1528
+ const target = talent.special_values?.find((sv) => sv.name === specialValueName);
1529
+ if (target) {
1530
+ talent.name_loc = talent.name_loc.replace(match[0], target.values_float.join("/"));
1531
+ } else {
1532
+ const ability = hero.abilities.find((ability2) => ability2.special_values.some((specialValue) => specialValue.bonuses.some((bonus) => bonus.name === talent.name)));
1533
+ if (ability) {
1534
+ const specialValues = ability.special_values.filter((specialValue) => specialValue.bonuses.some((bonus) => bonus.name === talent.name));
1535
+ const regex2 = /{s:bonus_(.*?)}/g;
1536
+ let match2;
1537
+ const replacements = [];
1538
+ while ((match2 = regex2.exec(talent.name_loc)) !== null) {
1539
+ const specialValue = specialValues.find((sv) => sv.name === String(match2[1]));
1540
+ const replacement = specialValue?.bonuses.find((bonus) => bonus.name === talent.name)?.value;
1541
+ if (replacement !== void 0) {
1542
+ replacements.push({ original: match2[0], replacement });
1549
1543
  }
1550
- replacements.forEach(({ original, replacement }) => {
1551
- talent.name_loc = talent.name_loc.replace(original, replacement);
1552
- });
1553
1544
  }
1545
+ replacements.forEach(({ original, replacement }) => {
1546
+ talent.name_loc = talent.name_loc.replace(original, replacement);
1547
+ });
1554
1548
  }
1555
1549
  }
1556
- });
1557
- try {
1558
- const gameVersionId = (await query(CURRENT_GAMEVERSION())).data.constants.gameVersions[0].id;
1559
- await ctx.database.upsert("dt_hero_data_cache", (row) => [{ id: hero.id, hero, gameVersionId }]);
1560
- } catch (error) {
1561
- ctx.logger.error(error);
1562
- await session.send("数据缓存失败。");
1563
1550
  }
1564
- }
1551
+ });
1565
1552
  await session.send(await ctx.puppeteer.render(genImageHTML(hero, config.template_hero, "hero" /* Hero */)));
1566
1553
  } catch (error) {
1567
1554
  ctx.logger.error(error);
1568
- await session.send("获取数据失败");
1555
+ session.send("获取数据失败");
1569
1556
  }
1570
1557
  } else {
1571
1558
  session.send("请输入参数。");
@@ -1641,9 +1628,6 @@ async function apply(ctx, config) {
1641
1628
  if (!("dt_previous_query_results" in tables)) {
1642
1629
  ctx.model.extend("dt_previous_query_results", { matchId: "unsigned", data: "json", queryTime: "timestamp" }, { primary: "matchId" });
1643
1630
  }
1644
- if (!("dt_hero_data_cache" in tables)) {
1645
- ctx.model.extend("dt_hero_data_cache", { id: "unsigned", gameVersionId: "unsigned", hero: "json" });
1646
- }
1647
1631
  ctx.cron("0 */6 * * *", () => {
1648
1632
  const oneMonthAgo = (0, import_moment.default)().subtract(1, "months").toDate();
1649
1633
  ctx.database.remove("dt_sended_match_id", { sendTime: { $lt: oneMonthAgo } });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sjtdev/koishi-plugin-dota2tracker",
3
3
  "description": "koishi插件-追踪群友的DOTA2对局",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -31,7 +31,7 @@
31
31
  "moment": "^2.30.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "koishi": "^4.17.3"
34
+ "koishi": "^4.17.8"
35
35
  },
36
36
  "koishi": {
37
37
  "preview": "true",
package/readme.md CHANGED
@@ -4,7 +4,8 @@
4
4
 
5
5
  DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑定),以及一系列查询功能。
6
6
  ### 安装
7
- 在koishi插件市场搜索安装
7
+ 在koishi插件市场搜索安装
8
+ 有关koishi的使用说明:([koishi官方文档](https://koishi.chat/))
8
9
 
9
10
  ### 使用
10
11
  需在插件配置页填入STRATZ API TOKEN,否则无法使用。(配置中提供了API的获取链接)
@@ -36,10 +37,11 @@ DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑
36
37
  返回一张图片,包含英雄属性与技能详情。(此处英雄名为中文名)
37
38
  * <del>`查询英雄对战 <英雄ID|英雄名|英雄常用别名>`</del>
38
39
  好像不是很实用
39
- * `7.36 [英雄ID|英雄名|英雄常用别名] [--refresh|-r]`
40
- 查询官网7.36更新日志中指定英雄的改动信息
40
+ * <del>`7.36 [英雄ID|英雄名|英雄常用别名] [--refresh|-r]`</del>
41
+ <del>查询官网7.36更新日志中指定英雄的改动信息
41
42
  无英雄参数时直接返回官网7.36更新日志网址
42
- 首次使用时将缓存更新日志网页,若读取失败或出错,可添加`--refresh`或`-r`指令重新缓存
43
+ 首次使用时将缓存更新日志网页,若读取失败或出错,可添加`--refresh`或`-r`指令重新缓存</del>
44
+ `查询英雄`指令已适配7.36改动,所以此指令已废弃
43
45
 
44
46
  ### 英雄ID|英雄名|英雄常用别名 列表
45
47
  [dotaconstants_add.json](https://github.com/sjtdev/koishi-plugin-dota2tracker/blob/master/src/dotaconstants_add.json#L102-L226)
@@ -189,9 +189,6 @@
189
189
  background-color: #444;
190
190
  }
191
191
 
192
- .details .list {
193
- }
194
-
195
192
  .details .list td {
196
193
  width: 50%;
197
194
  text-align: center;
@@ -648,10 +645,10 @@
648
645
  <div class="skills">
649
646
  ${hero.abilities//.filter((item) => dotaconstants.abilities[item.name].behavior != "Hidden")
650
647
  .map((item) => `
651
- <div class="skill" data-ability="${item.ability_is_innate}">
648
+ <div class="skill" data-innate="${item.ability_is_innate&&!item.ability_is_facet}">
652
649
  <p class="title">
653
650
  <span class="name">${item.name_loc}</span>
654
- ${item.ability_is_innate?`<span class="is_innate">先天技能</span>`:""}
651
+ ${item.ability_is_innate&&!item.ability_is_facet?`<span class="is_innate">先天技能</span>`:""}
655
652
  ${item.ability_is_granted_by_scepter ?`<img src="${utils.getImageUrl("scepter")}" class="scepter">`:""}
656
653
  ${item.ability_is_granted_by_shard ?`<img src="${utils.getImageUrl("shard")}" class="shard">`:""}
657
654
  </p>
@@ -736,7 +733,7 @@
736
733
  const items = document.querySelectorAll('.skills > .skill');
737
734
  items.forEach(item => {
738
735
  // const name = item.getAttribute('data-name');
739
- const abilityIsInnate = item.getAttribute('data-ability') === 'true';
736
+ const abilityIsInnate = item.getAttribute('data-innate') === 'true';
740
737
  const img = item.querySelector('.img_stats > img');
741
738
  const imageUrl = img.src;
742
739