@sjtdev/koishi-plugin-dota2tracker 1.2.0-hotfix → 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
@@ -642,12 +642,31 @@ function getFormattedMatchData(match) {
642
642
  break;
643
643
  }
644
644
  let items_timelist = {};
645
- player.supportItemsCount = { 30: 0, 40: 0, 42: 0, 43: 0, 188: 0 };
645
+ const supportItemIds = [30, 40, 42, 43, 188];
646
+ player.supportItemsCount = supportItemIds.reduce((obj, key) => {
647
+ obj[key] = 0;
648
+ return obj;
649
+ }, {});
646
650
  if (player.playbackData) {
651
+ const getNextElement = /* @__PURE__ */ __name(function() {
652
+ let currentIndex = 0;
653
+ return function() {
654
+ if (currentIndex >= this.length) {
655
+ return null;
656
+ }
657
+ const element = this[currentIndex];
658
+ currentIndex++;
659
+ return element;
660
+ };
661
+ }, "getNextElement");
647
662
  for (let item of player.playbackData.purchaseEvents) {
648
- items_timelist[item.itemId] = item.time;
649
- if (item.itemId == 42 || item.itemId == 43)
650
- items_timelist[218] = item.time;
663
+ if (!supportItemIds.includes(item.itemId)) {
664
+ if (!items_timelist[item.itemId]) {
665
+ items_timelist[item.itemId] = [];
666
+ items_timelist[item.itemId].getNextElement = getNextElement.call(items_timelist[item.itemId]);
667
+ }
668
+ items_timelist[item.itemId].push(item.time);
669
+ }
651
670
  switch (item.itemId) {
652
671
  case 30:
653
672
  case 40:
@@ -674,7 +693,7 @@ function getFormattedMatchData(match) {
674
693
  player.items.push({
675
694
  id: itemId,
676
695
  name: cleanName,
677
- time: items_timelist[itemId],
696
+ time: items_timelist[itemId]?.getNextElement ? items_timelist[itemId].getNextElement() : void 0,
678
697
  isRecipe
679
698
  });
680
699
  } else {
@@ -1450,7 +1469,7 @@ async function apply(ctx, config) {
1450
1469
  }
1451
1470
  }
1452
1471
  });
1453
- 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) => {
1454
1473
  if (options.random)
1455
1474
  input_data = random.pick(Object.keys(HEROES_CHINESE));
1456
1475
  if (input_data) {
@@ -1459,94 +1478,81 @@ async function apply(ctx, config) {
1459
1478
  session.send("未找到输入的英雄,请确认后重新输入。");
1460
1479
  return;
1461
1480
  }
1481
+ await session.send("正在获取英雄数据,请稍后...");
1462
1482
  try {
1463
- const tempHero = await ctx.database.get("dt_hero_data_cache", hero.id);
1464
- if (tempHero.length && !options.refresh) {
1465
- const gameVersionId = (await query(CURRENT_GAMEVERSION())).data.constants.gameVersions[0].id;
1466
- if (tempHero[0].gameVersionId >= gameVersionId) {
1467
- 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
+ });
1468
1497
  }
1469
- } else {
1470
- const queryHero = await queryHeroFromValve(hero.id);
1471
- Object.assign(hero, queryHero);
1472
- hero.facet_abilities.forEach((fa, i) => {
1473
- if (fa.abilities.length) {
1474
- fa.abilities.forEach((ab) => {
1475
- if (!hero.facets[i].abilities)
1476
- hero.facets[i].abilities = [];
1477
- if (hero.facets[i].description_loc !== ab.desc_loc)
1478
- 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 */) });
1479
- else
1480
- hero.facets[i].description_loc = formatHeroDesc(hero.facets[i].description_loc, ab.special_values, "facet" /* Facet */);
1481
- hero.abilities.push(ab);
1482
- });
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: [] });
1483
1506
  }
1484
1507
  });
1485
- const all_special_values = [...hero.abilities.flatMap((ab) => ab.special_values), ...hero.facet_abilities.flatMap((fas) => fas.abilities.flatMap((fa) => fa.special_values))];
1486
- hero.abilities.forEach((ab) => {
1487
- ab.facets_loc.forEach((facet, i) => {
1488
- if (facet) {
1489
- if (!hero.facets[i].abilities)
1490
- hero.facets[i].abilities = [];
1491
- 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] });
1492
1513
  }
1493
1514
  });
1494
- hero.facets.forEach((facet) => {
1495
- const svs = ab.special_values.filter((sv) => sv.facet_bonus.name === facet.name);
1496
- svs.forEach((sv) => {
1497
- if (sv.heading_loc) {
1498
- facet.abilities.find((ability) => ab.id == ability.id)?.attributes.push({ heading_loc: sv.heading_loc, values: [...sv.facet_bonus.values] });
1499
- }
1500
- });
1501
- });
1502
- ab.desc_loc = formatHeroDesc(ab.desc_loc, all_special_values);
1503
- ab.notes_loc = ab.notes_loc.map((note) => formatHeroDesc(note, all_special_values));
1504
- if (ab.ability_has_scepter)
1505
- ab.scepter_loc = formatHeroDesc(ab.scepter_loc, ab.special_values, "scepter" /* Scepter */);
1506
- if (ab.ability_has_shard)
1507
- ab.shard_loc = formatHeroDesc(ab.shard_loc, ab.special_values, "shard" /* Shard */);
1508
1515
  });
1509
- hero.talents.forEach((talent) => {
1510
- const regex = /\{s:(.*?)\}/g;
1511
- let match;
1512
- while ((match = regex.exec(talent.name_loc)) !== null) {
1513
- const specialValueName = match[1];
1514
- const target = talent.special_values?.find((sv) => sv.name === specialValueName);
1515
- if (target) {
1516
- talent.name_loc = talent.name_loc.replace(match[0], target.values_float.join("/"));
1517
- } else {
1518
- const ability = hero.abilities.find((ability2) => ability2.special_values.some((specialValue) => specialValue.bonuses.some((bonus) => bonus.name === talent.name)));
1519
- if (ability) {
1520
- const specialValues = ability.special_values.filter((specialValue) => specialValue.bonuses.some((bonus) => bonus.name === talent.name));
1521
- const regex2 = /{s:bonus_(.*?)}/g;
1522
- let match2;
1523
- const replacements = [];
1524
- while ((match2 = regex2.exec(talent.name_loc)) !== null) {
1525
- const specialValue = specialValues.find((sv) => sv.name === String(match2[1]));
1526
- const replacement = specialValue?.bonuses.find((bonus) => bonus.name === talent.name)?.value;
1527
- if (replacement !== void 0) {
1528
- replacements.push({ original: match2[0], replacement });
1529
- }
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 });
1530
1543
  }
1531
- replacements.forEach(({ original, replacement }) => {
1532
- talent.name_loc = talent.name_loc.replace(original, replacement);
1533
- });
1534
1544
  }
1545
+ replacements.forEach(({ original, replacement }) => {
1546
+ talent.name_loc = talent.name_loc.replace(original, replacement);
1547
+ });
1535
1548
  }
1536
1549
  }
1537
- });
1538
- try {
1539
- const gameVersionId = (await query(CURRENT_GAMEVERSION())).data.constants.gameVersions[0].id;
1540
- await ctx.database.upsert("dt_hero_data_cache", (row) => [{ id: hero.id, hero, gameVersionId }]);
1541
- } catch (error) {
1542
- ctx.logger.error(error);
1543
- await session.send("数据缓存失败。");
1544
1550
  }
1545
- }
1551
+ });
1546
1552
  await session.send(await ctx.puppeteer.render(genImageHTML(hero, config.template_hero, "hero" /* Hero */)));
1547
1553
  } catch (error) {
1548
1554
  ctx.logger.error(error);
1549
- await session.send("获取数据失败");
1555
+ session.send("获取数据失败");
1550
1556
  }
1551
1557
  } else {
1552
1558
  session.send("请输入参数。");
@@ -1622,9 +1628,6 @@ async function apply(ctx, config) {
1622
1628
  if (!("dt_previous_query_results" in tables)) {
1623
1629
  ctx.model.extend("dt_previous_query_results", { matchId: "unsigned", data: "json", queryTime: "timestamp" }, { primary: "matchId" });
1624
1630
  }
1625
- if (!("dt_hero_data_cache" in tables)) {
1626
- ctx.model.extend("dt_hero_data_cache", { id: "unsigned", gameVersionId: "unsigned", hero: "json" });
1627
- }
1628
1631
  ctx.cron("0 */6 * * *", () => {
1629
1632
  const oneMonthAgo = (0, import_moment.default)().subtract(1, "months").toDate();
1630
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.0-hotfix",
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
 
@@ -756,7 +756,7 @@
756
756
  <div class="titles">
757
757
  ${player.titles.map((item) => `<span style="color: ${item.color};">${item.name}</span>`).join("&nbsp;")}
758
758
  </div>
759
- ${player.hero.id != 80 ? `
759
+ ${player.hero.id != 80 ? `
760
760
  <div class="items">
761
761
  <div class="items_normal">
762
762
  ${player.items