@sjtdev/koishi-plugin-dota2tracker 1.1.8 → 1.1.9

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.
Files changed (3) hide show
  1. package/lib/index.js +28 -25
  2. package/package.json +2 -2
  3. 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.status == 200) {
832
- if (queryRes.data.data.player.matchCount != null)
833
- return { isValid: true };
834
- else
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.guild.id, platform: session.event.platform }))[0];
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.guild.id, platform: session.event.platform });
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.guild.id, platform: session.event.platform }))[0];
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.guild.id);
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.guild.id, platform: session.event.platform, userId: session.event.user.id }))[0];
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.guild.id, platform: session.event.platform, steamId: parseInt(steam_id), nickName: nick_name || null });
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.guild.id, platform: session.event.platform, userId: session.event.user.id }))[0];
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.guild.id, platform: session.event.platform, userId: session.event.user.id }))[0];
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.guild.id, platform: session.platform });
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.guild.id);
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(1, "hours")))) {
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.guild.id, players: [] }] });
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.guild.id, platform: session.event.platform, userId: session.event.user.id }))[0];
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.guild.id, platform: session.event.platform, nickName: input_data }))[0];
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.guild.id, platform: session.event.platform, userId: session.event.user.id }))[0];
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.guild.id, platform: session.event.platform, nickName: input_data }))[0];
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,7 +1413,7 @@ 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.gameVersionsId < queryConstants.gameVersions[0].id) {
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 }]);
@@ -1581,6 +1580,10 @@ async function apply(ctx, config) {
1581
1580
  } else
1582
1581
  session.send("https://www.dota2.com/patches/7.36");
1583
1582
  });
1583
+ ctx.command("test <input_data>").option("a", "a").action(async ({ session, options }, input_data) => {
1584
+ console.log(session);
1585
+ ctx.broadcast(["kook:9510442027074966"], "test");
1586
+ });
1584
1587
  ctx.on("ready", async () => {
1585
1588
  const tables = await ctx.database.tables;
1586
1589
  if (!("dt_subscribed_guilds" in tables)) {
@@ -1711,7 +1714,7 @@ async function apply(ctx, config) {
1711
1714
  ctx.database.set("dt_previous_query_results", match.id, { queryTime: /* @__PURE__ */ new Date() });
1712
1715
  } else
1713
1716
  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(1, "hours"))) {
1717
+ if (match.parsedDateTime || import_moment.default.unix(match.endDateTime).isBefore((0, import_moment.default)().subtract(config.dataParsingTimeoutMinutes, "minutes"))) {
1715
1718
  pendingMatches = pendingMatches.filter((item) => item.matchId != match.id);
1716
1719
  const img = await ctx.puppeteer.render(genImageHTML(match, config.template_match, "match" /* Match */));
1717
1720
  for (let commingGuild of pendingMatch.guilds) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sjtdev/koishi-plugin-dota2tracker",
3
- "description": "",
4
- "version": "1.1.8",
3
+ "description": "koishi插件-追踪群友的DOTA2对局",
4
+ "version": "1.1.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -8,7 +8,7 @@ DOTA2Bot插件-提供自动追踪群友的最新对局的功能(需群友绑
8
8
 
9
9
  ### 使用
10
10
  需在插件配置页填入STRATZ API TOKEN,否则无法使用。(配置中提供了API的获取链接)
11
- 在希望推送战报信息的群组使用指令`订阅本群`,玩家可使用指令`绑定`来将自身账号与Steam账号绑定,bot会尝试追踪已订阅群组中的绑定玩家的最新对局信息。
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
  ##### 绑定