koishi-plugin-minecraft-notifier 1.9.1 → 1.10.1

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.
@@ -4,5 +4,4 @@ import { Config } from './index';
4
4
  export declare const minecraftSummaryTypeMap: Record<string, string>;
5
5
  export declare function checkNewVersionArticle(ctx: Context, cfg: Config): Promise<void>;
6
6
  export declare function processNewVersionArticle(ctx: Context, cfg: Config, version: string, isSnapshot: boolean): Promise<boolean>;
7
- export declare function generateArticleUrl(version: string, isSnapshot: boolean): string;
8
7
  export declare function fetchArticleContent(ctx: Context, version: string, isSnapshot: boolean): Promise<string>;
@@ -0,0 +1 @@
1
+ export declare function generateArticleUrl(version: string, isSnapshot: boolean): string;
package/lib/index.cjs CHANGED
@@ -40,6 +40,34 @@ var import_koishi = require("koishi");
40
40
  var import_node_fs2 = require("node:fs");
41
41
  var import_node_path2 = __toESM(require("node:path"), 1);
42
42
 
43
+ // src/helper/article-helper.ts
44
+ function generateArticleUrl(version, isSnapshot) {
45
+ const cleanVersion = version.replace(/\s/g, "-").toLowerCase();
46
+ const baseUrl = "https://www.minecraft.net/zh-hans/article";
47
+ if (isSnapshot) {
48
+ return generateSnapshotUrl(baseUrl, version, cleanVersion);
49
+ }
50
+ return `${baseUrl}/minecraft-java-edition-${cleanVersion.replaceAll(".", "-")}`;
51
+ }
52
+ function generateSnapshotUrl(baseUrl, version, cleanVersion) {
53
+ if (version.includes("rc")) {
54
+ return buildReleaseUrl(baseUrl, version, "release-candidate");
55
+ }
56
+ if (version.includes("pre")) {
57
+ return buildReleaseUrl(baseUrl, version, "pre-release");
58
+ }
59
+ return `${baseUrl}/minecraft-snapshot-${cleanVersion}`;
60
+ }
61
+ function buildReleaseUrl(baseUrl, version, releaseType) {
62
+ const [mainVersion] = version.split("-");
63
+ const buildNumber = version.slice(-1);
64
+ const formattedVersion = mainVersion.replaceAll(".", "-");
65
+ return `${baseUrl}/minecraft-${formattedVersion}-${releaseType}-${buildNumber}`;
66
+ }
67
+
68
+ // src/version-checker.ts
69
+ var import_axios4 = __toESM(require("axios"), 1);
70
+
43
71
  // src/changelog-summarizer.ts
44
72
  var import_koishi_plugin_adapter_onebot = require("@pynickle/koishi-plugin-adapter-onebot");
45
73
  var import_autocorrect_node2 = require("autocorrect-node");
@@ -757,6 +785,10 @@ async function checkVersionUpdate(ctx, cfg, articleRecord, notifierRecord, versi
757
785
  }
758
786
  const currentTryTime = articleRecord[tryTimeKey];
759
787
  const newVersion = notifierRecord[versionKey];
788
+ await updateArticleRecord(ctx, {
789
+ [versionKey]: newVersion,
790
+ latestVersion: newVersion
791
+ });
760
792
  const success = await processNewVersionArticle(
761
793
  ctx,
762
794
  cfg,
@@ -765,21 +797,19 @@ async function checkVersionUpdate(ctx, cfg, articleRecord, notifierRecord, versi
765
797
  );
766
798
  if (success) {
767
799
  await updateArticleRecord(ctx, {
768
- [versionKey]: newVersion,
769
- [tryTimeKey]: 0,
770
- latestVersion: newVersion
800
+ [tryTimeKey]: 0
771
801
  });
772
802
  return true;
773
803
  }
774
804
  const newTryTime = currentTryTime + 1;
775
805
  if (newTryTime >= 5) {
776
806
  await updateArticleRecord(ctx, {
777
- [versionKey]: newVersion,
778
- [tryTimeKey]: 0,
779
- latestVersion: newVersion
807
+ [tryTimeKey]: 0
780
808
  });
781
809
  } else {
782
810
  await updateArticleRecord(ctx, {
811
+ [versionKey]: articleRecord[versionKey],
812
+ latestVersion: articleRecord[versionKey],
783
813
  [tryTimeKey]: newTryTime
784
814
  });
785
815
  }
@@ -975,29 +1005,6 @@ ${subList}`)
975
1005
  );
976
1006
  return true;
977
1007
  }
978
- function generateArticleUrl(version, isSnapshot) {
979
- const cleanVersion = version.replace(/\s/g, "-").toLowerCase();
980
- const baseUrl = "https://www.minecraft.net/zh-hans/article";
981
- if (isSnapshot) {
982
- return generateSnapshotUrl(baseUrl, version, cleanVersion);
983
- }
984
- return `${baseUrl}/minecraft-java-edition-${cleanVersion.replaceAll(".", "-")}`;
985
- }
986
- function generateSnapshotUrl(baseUrl, version, cleanVersion) {
987
- if (version.includes("rc")) {
988
- return buildReleaseUrl(baseUrl, version, "release-candidate");
989
- }
990
- if (version.includes("pre")) {
991
- return buildReleaseUrl(baseUrl, version, "pre-release");
992
- }
993
- return `${baseUrl}/minecraft-snapshot-${cleanVersion}`;
994
- }
995
- function buildReleaseUrl(baseUrl, version, releaseType) {
996
- const [mainVersion] = version.split("-");
997
- const buildNumber = version.slice(-1);
998
- const formattedVersion = mainVersion.replaceAll(".", "-");
999
- return `${baseUrl}/minecraft-${formattedVersion}-${releaseType}-${buildNumber}`;
1000
- }
1001
1008
  var turndownService = new import_turndown.default({});
1002
1009
  async function fetchArticleContent(ctx, version, isSnapshot) {
1003
1010
  const url = generateArticleUrl(version, isSnapshot);
@@ -1008,10 +1015,15 @@ async function fetchArticleContent(ctx, version, isSnapshot) {
1008
1015
  "User-Agent": getRandomUserAgent()
1009
1016
  }
1010
1017
  });
1011
- const html = response.data;
1012
- const $ = cheerio2.load(html);
1013
- const content = $("div.article-text").html().trim();
1014
- return turndownService.turndown(content.trim());
1018
+ if (response.status === 200) {
1019
+ const html = response.data;
1020
+ const $ = cheerio2.load(html);
1021
+ const content = $("div.article-text").html().trim();
1022
+ return turndownService.turndown(content.trim());
1023
+ }
1024
+ ctx.logger("minecraft-notifier").warn(
1025
+ `Wrong response status (${response.status}) when fetching article: ${url}`
1026
+ );
1015
1027
  } catch (error) {
1016
1028
  if (error.response && error.response.status === 404) {
1017
1029
  ctx.logger("minecraft-notifier").warn(`Article not found: ${url}`);
@@ -1026,7 +1038,6 @@ async function fetchArticleContent(ctx, version, isSnapshot) {
1026
1038
  }
1027
1039
 
1028
1040
  // src/version-checker.ts
1029
- var import_axios4 = __toESM(require("axios"), 1);
1030
1041
  var loadData = async (ctx) => {
1031
1042
  const record = (await ctx.database.get("minecraft_notifier", 1))[0];
1032
1043
  if (record) {
@@ -1074,13 +1085,19 @@ var getLatestVersions = async () => {
1074
1085
  var notifyReleaseVersion = async (ctx, cfg, version) => {
1075
1086
  const bot = ctx.bots[0];
1076
1087
  for (const channel of cfg.notifyChannel) {
1077
- await bot.sendMessage(channel, `\u{1F4E2} Minecraft \u65B0\u6B63\u5F0F\u7248\u53D1\u5E03\u4E86\uFF1A${version}`);
1088
+ await bot.sendMessage(
1089
+ channel,
1090
+ `\u{1F4E2} Minecraft \u65B0\u6B63\u5F0F\u7248\u53D1\u5E03\u4E86\uFF1A${version}`
1091
+ );
1078
1092
  }
1079
1093
  };
1080
1094
  var notifySnapshotVersion = async (ctx, cfg, version) => {
1081
1095
  const bot = ctx.bots[0];
1082
1096
  for (const channel of cfg.notifyChannel) {
1083
- await bot.sendMessage(channel, `\u{1F389} Minecraft \u65B0\u5FEB\u7167\u7248\u53D1\u5E03\u4E86\uFF1A${version}`);
1097
+ await bot.sendMessage(
1098
+ channel,
1099
+ `\u{1F389} Minecraft \u65B0\u5FEB\u7167\u7248\u53D1\u5E03\u4E86\uFF1A${version}`
1100
+ );
1084
1101
  }
1085
1102
  };
1086
1103
  var checkMinecraftVersion = async (ctx, cfg) => {
@@ -1185,15 +1202,28 @@ function apply(ctx, cfg) {
1185
1202
  Title: "Minecraft \u66F4\u65B0\u6458\u8981"
1186
1203
  });
1187
1204
  });
1188
- ctx.command("mc.trigger", "\u624B\u52A8\u89E6\u53D1 AI \u66F4\u65B0\u65E5\u5FD7\u603B\u7ED3\u751F\u6210", {
1205
+ ctx.command("mc.trigger", "\u624B\u52A8\u89E6\u53D1\u68C0\u67E5 Minecraft \u7248\u672C\u66F4\u65B0", {
1189
1206
  authority: 4
1190
- }).action(async () => {
1191
- await checkNewVersionArticle(ctx, cfg);
1192
- });
1207
+ }).action(async () => await checkMinecraftVersion(ctx, cfg));
1193
1208
  ctx.setInterval(
1194
1209
  async () => await checkMinecraftVersion(ctx, cfg),
1195
1210
  6e4 * cfg.checkInterval
1196
1211
  );
1212
+ ctx.command("mc.version", "\u67E5\u8BE2\u5F53\u524D\u5DF2\u8BB0\u5F55\u7684 Minecraft \u7248\u672C\u4FE1\u606F").action(
1213
+ async () => {
1214
+ const record = (await ctx.database.get("minecraft_notifier", 1))[0];
1215
+ if (!record) {
1216
+ return "\u274C \u5F53\u524D\u6682\u65E0\u5DF2\u8BB0\u5F55\u7684\u7248\u672C\u4FE1\u606F\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002";
1217
+ }
1218
+ return `\u{1F4E2} \u5F53\u524D\u5DF2\u8BB0\u5F55\u7684\u6700\u65B0 Minecraft \u7248\u672C\u4FE1\u606F\uFF1A
1219
+
1220
+ \u{1F4E2} \u6B63\u5F0F\u7248\uFF1A${record.lastRelease}
1221
+ \u{1F31F} \u6B63\u5F0F\u7248\u66F4\u65B0\u65E5\u5FD7\uFF1A${generateArticleUrl(record.lastRelease, false)}
1222
+
1223
+ \u{1F389} \u5FEB\u7167\u7248\uFF1A${record.lastSnapshot}
1224
+ \u{1F9EA} \u5FEB\u7167\u7248\u66F4\u65B0\u65E5\u5FD7\uFF1A${generateArticleUrl(record.lastSnapshot, true)}`;
1225
+ }
1226
+ );
1197
1227
  }
1198
1228
  // Annotate the CommonJS export names for ESM import in node:
1199
1229
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-minecraft-notifier",
3
3
  "description": "A Minecraft new version notification plugin, also featuring a PCL homepage.",
4
- "version": "1.9.1",
4
+ "version": "1.10.1",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",