koishi-plugin-minecraft-notifier 1.9.1 → 1.10.0

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");
@@ -975,29 +1003,6 @@ ${subList}`)
975
1003
  );
976
1004
  return true;
977
1005
  }
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
1006
  var turndownService = new import_turndown.default({});
1002
1007
  async function fetchArticleContent(ctx, version, isSnapshot) {
1003
1008
  const url = generateArticleUrl(version, isSnapshot);
@@ -1008,10 +1013,15 @@ async function fetchArticleContent(ctx, version, isSnapshot) {
1008
1013
  "User-Agent": getRandomUserAgent()
1009
1014
  }
1010
1015
  });
1011
- const html = response.data;
1012
- const $ = cheerio2.load(html);
1013
- const content = $("div.article-text").html().trim();
1014
- return turndownService.turndown(content.trim());
1016
+ if (response.status === 200) {
1017
+ const html = response.data;
1018
+ const $ = cheerio2.load(html);
1019
+ const content = $("div.article-text").html().trim();
1020
+ return turndownService.turndown(content.trim());
1021
+ }
1022
+ ctx.logger("minecraft-notifier").warn(
1023
+ `Wrong response status (${response.status}) when fetching article: ${url}`
1024
+ );
1015
1025
  } catch (error) {
1016
1026
  if (error.response && error.response.status === 404) {
1017
1027
  ctx.logger("minecraft-notifier").warn(`Article not found: ${url}`);
@@ -1026,7 +1036,6 @@ async function fetchArticleContent(ctx, version, isSnapshot) {
1026
1036
  }
1027
1037
 
1028
1038
  // src/version-checker.ts
1029
- var import_axios4 = __toESM(require("axios"), 1);
1030
1039
  var loadData = async (ctx) => {
1031
1040
  const record = (await ctx.database.get("minecraft_notifier", 1))[0];
1032
1041
  if (record) {
@@ -1074,13 +1083,19 @@ var getLatestVersions = async () => {
1074
1083
  var notifyReleaseVersion = async (ctx, cfg, version) => {
1075
1084
  const bot = ctx.bots[0];
1076
1085
  for (const channel of cfg.notifyChannel) {
1077
- await bot.sendMessage(channel, `\u{1F4E2} Minecraft \u65B0\u6B63\u5F0F\u7248\u53D1\u5E03\u4E86\uFF1A${version}`);
1086
+ await bot.sendMessage(
1087
+ channel,
1088
+ `\u{1F4E2} Minecraft \u65B0\u6B63\u5F0F\u7248\u53D1\u5E03\u4E86\uFF1A${version}`
1089
+ );
1078
1090
  }
1079
1091
  };
1080
1092
  var notifySnapshotVersion = async (ctx, cfg, version) => {
1081
1093
  const bot = ctx.bots[0];
1082
1094
  for (const channel of cfg.notifyChannel) {
1083
- await bot.sendMessage(channel, `\u{1F389} Minecraft \u65B0\u5FEB\u7167\u7248\u53D1\u5E03\u4E86\uFF1A${version}`);
1095
+ await bot.sendMessage(
1096
+ channel,
1097
+ `\u{1F389} Minecraft \u65B0\u5FEB\u7167\u7248\u53D1\u5E03\u4E86\uFF1A${version}`
1098
+ );
1084
1099
  }
1085
1100
  };
1086
1101
  var checkMinecraftVersion = async (ctx, cfg) => {
@@ -1185,15 +1200,28 @@ function apply(ctx, cfg) {
1185
1200
  Title: "Minecraft \u66F4\u65B0\u6458\u8981"
1186
1201
  });
1187
1202
  });
1188
- ctx.command("mc.trigger", "\u624B\u52A8\u89E6\u53D1 AI \u66F4\u65B0\u65E5\u5FD7\u603B\u7ED3\u751F\u6210", {
1203
+ ctx.command("mc.trigger", "\u624B\u52A8\u89E6\u53D1\u68C0\u67E5 Minecraft \u7248\u672C\u66F4\u65B0", {
1189
1204
  authority: 4
1190
- }).action(async () => {
1191
- await checkNewVersionArticle(ctx, cfg);
1192
- });
1205
+ }).action(async () => await checkMinecraftVersion(ctx, cfg));
1193
1206
  ctx.setInterval(
1194
1207
  async () => await checkMinecraftVersion(ctx, cfg),
1195
1208
  6e4 * cfg.checkInterval
1196
1209
  );
1210
+ ctx.command("mc.version", "\u67E5\u8BE2\u5F53\u524D\u5DF2\u8BB0\u5F55\u7684 Minecraft \u7248\u672C\u4FE1\u606F").action(
1211
+ async () => {
1212
+ const record = (await ctx.database.get("minecraft_notifier", 1))[0];
1213
+ if (!record) {
1214
+ return "\u274C \u5F53\u524D\u6682\u65E0\u5DF2\u8BB0\u5F55\u7684\u7248\u672C\u4FE1\u606F\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5\u3002";
1215
+ }
1216
+ return `\u{1F4E2} \u5F53\u524D\u5DF2\u8BB0\u5F55\u7684\u6700\u65B0 Minecraft \u7248\u672C\u4FE1\u606F\uFF1A
1217
+
1218
+ \u{1F4E2} \u6B63\u5F0F\u7248\uFF1A${record.lastRelease}
1219
+ \u{1F31F} \u6B63\u5F0F\u7248\u66F4\u65B0\u65E5\u5FD7\uFF1A${generateArticleUrl(record.lastRelease, false)}
1220
+
1221
+ \u{1F389} \u5FEB\u7167\u7248\uFF1A${record.lastSnapshot}
1222
+ \u{1F9EA} \u5FEB\u7167\u7248\u66F4\u65B0\u65E5\u5FD7\uFF1A${generateArticleUrl(record.lastSnapshot, true)}`;
1223
+ }
1224
+ );
1197
1225
  }
1198
1226
  // Annotate the CommonJS export names for ESM import in node:
1199
1227
  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.0",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",