koishi-plugin-minecraft-notifier 1.1.1 → 1.2.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.
@@ -0,0 +1,18 @@
1
+ import { AxiosResponse } from 'axios';
2
+ /**
3
+ * 更新 Gitee 仓库中的文本文件
4
+ * @param owner - 仓库所有者用户名
5
+ * @param repo - 仓库名称
6
+ * @param path - 文件路径(例如 'docs/update.txt')
7
+ * @param content - 文件内容(纯文本字符串,会自动 Base64 编码)
8
+ * @param sha - 文件的当前 SHA 值(通过 GET contents API 获取,用于更新)
9
+ * @param message - Commit 消息
10
+ * @param token - Gitee Personal Access Token
11
+ * @param branch - 分支名(默认 'master')
12
+ * @returns Promise<{ success: boolean; data?: AxiosResponse; error?: string }>
13
+ */
14
+ export declare function updateFileOnGitee(owner: string, repo: string, path: string, content: string, sha: string, message: string, token: string, branch?: string): Promise<{
15
+ success: boolean;
16
+ data?: AxiosResponse;
17
+ error?: string;
18
+ }>;
package/lib/index.cjs CHANGED
@@ -35,14 +35,15 @@ __export(index_exports, {
35
35
  name: () => name
36
36
  });
37
37
  module.exports = __toCommonJS(index_exports);
38
- var import_axios2 = __toESM(require("axios"), 1);
38
+ var import_axios3 = __toESM(require("axios"), 1);
39
+ var import_fs = __toESM(require("fs"), 1);
39
40
  var import_koishi = require("koishi");
40
41
  var import_node_fs2 = require("node:fs");
41
42
  var import_node_path2 = __toESM(require("node:path"), 1);
42
43
 
43
44
  // src/changelog-summarizer.ts
44
45
  var import_koishi_plugin_adapter_onebot = require("@pynickle/koishi-plugin-adapter-onebot");
45
- var import_axios = __toESM(require("axios"), 1);
46
+ var import_axios2 = __toESM(require("axios"), 1);
46
47
  var cheerio = __toESM(require("cheerio"), 1);
47
48
  var import_turndown = __toESM(require("turndown"), 1);
48
49
 
@@ -119,6 +120,42 @@ function getRandomUserAgent() {
119
120
  // src/xaml-generator.ts
120
121
  var import_node_fs = require("node:fs");
121
122
  var import_node_path = __toESM(require("node:path"), 1);
123
+
124
+ // src/gitee-helper.ts
125
+ var import_axios = __toESM(require("axios"), 1);
126
+ async function updateFileOnGitee(owner, repo, path3, content, sha, message, token, branch = "master") {
127
+ const base64Content = Buffer.from(content, "utf-8").toString("base64");
128
+ const url = `https://gitee.com/api/v5/repos/${owner}/${repo}/contents/${path3}`;
129
+ try {
130
+ const response = await import_axios.default.put(
131
+ url,
132
+ {
133
+ content: base64Content,
134
+ sha,
135
+ message,
136
+ branch
137
+ },
138
+ {
139
+ headers: {
140
+ Authorization: `token ${token}`,
141
+ "Content-Type": "application/json"
142
+ }
143
+ }
144
+ );
145
+ return { success: true, data: response };
146
+ } catch (error) {
147
+ console.error(
148
+ "Gitee Update Error:",
149
+ error.response?.data || error.message
150
+ );
151
+ return {
152
+ success: false,
153
+ error: error.response?.data?.message || error.message
154
+ };
155
+ }
156
+ }
157
+
158
+ // src/xaml-generator.ts
122
159
  function generateXaml(summary, version) {
123
160
  const orderedCategories = [
124
161
  "new_features",
@@ -154,10 +191,10 @@ function generateXaml(summary, version) {
154
191
  Text="${sub.emoji} ${sub.subcategory}" />`;
155
192
  for (let k = 0; k < sub.items.length; k++) {
156
193
  const msg = sub.items[k];
157
- const margin = k === sub.items.length - 1 && j === subcategories.length - 1 ? "" : "0,0,0,2";
194
+ const margin = k === sub.items.length - 1 && j === subcategories.length - 1 ? "" : 'Margin="0,0,0,2"';
158
195
  contentXaml += `
159
196
  <TextBlock
160
- Margin="${margin}"
197
+ ${margin}
161
198
  Foreground="{DynamicResource ColorBrush1}"
162
199
  Text=" - ${msg}" />`;
163
200
  }
@@ -242,7 +279,7 @@ ${categoriesXaml}
242
279
  </local:MyCard>
243
280
  </StackPanel>`;
244
281
  }
245
- async function exportXaml(ctx, summary, version) {
282
+ async function exportXaml(ctx, cfg, summary, version) {
246
283
  const xaml = generateXaml(summary, version);
247
284
  const xamlPath = import_node_path.default.join(
248
285
  ctx.baseDir,
@@ -255,6 +292,17 @@ async function exportXaml(ctx, summary, version) {
255
292
  let fullHomePagePath = import_node_path.default.join(xamlPath, "PCL.HomePage.xaml");
256
293
  await import_node_fs.promises.writeFile(fullXamlPath, xaml);
257
294
  await import_node_fs.promises.copyFile(fullXamlPath, fullHomePagePath);
295
+ if (cfg.giteeApiToken && cfg.giteeOwner && cfg.giteeRepo) {
296
+ await updateFileOnGitee(
297
+ cfg.giteeOwner,
298
+ cfg.giteeRepo,
299
+ "Custom.xaml",
300
+ xaml,
301
+ `feat: update PCL HomePage XAML for version ${version}`,
302
+ cfg.giteeApiToken,
303
+ "master"
304
+ );
305
+ }
258
306
  return fullXamlPath;
259
307
  }
260
308
 
@@ -353,7 +401,7 @@ ${updateContent}
353
401
  `;
354
402
  let response;
355
403
  try {
356
- response = await import_axios.default.post(
404
+ response = await import_axios2.default.post(
357
405
  url,
358
406
  {
359
407
  model: cfg.model,
@@ -464,6 +512,9 @@ ${updateContent}
464
512
  }
465
513
  const content = response.data.choices[0].message.content;
466
514
  const summary = JSON.parse(content);
515
+ ctx.logger("minecraft-notifier").info(
516
+ `Summarization completed for version ${version}. Preparing to send notifications...`
517
+ );
467
518
  const messages = [
468
519
  createBotTextMsgNode(ctx.bots[0], `=== ${version} \u66F4\u65B0\u603B\u7ED3 ===`)
469
520
  ];
@@ -498,7 +549,13 @@ ${subList}`)
498
549
  for (const groupId of cfg.notifyChannel) {
499
550
  await ctx.bots[0].internal.sendGroupForwardMsg(groupId, messages);
500
551
  }
501
- await exportXaml(ctx, summary, version);
552
+ ctx.logger("minecraft-notifier").info(
553
+ `Notifications sent for version ${version}. Generating XAML...`
554
+ );
555
+ await exportXaml(ctx, cfg, summary, version);
556
+ ctx.logger("minecraft-notifier").info(
557
+ `XAML generation completed for version ${version}.`
558
+ );
502
559
  return true;
503
560
  }
504
561
  function generateArticleUrl(version, isSnapshot) {
@@ -528,7 +585,7 @@ var turndownService = new import_turndown.default({});
528
585
  async function fetchArticleContent(ctx, version, isSnapshot) {
529
586
  const url = generateArticleUrl(version, isSnapshot);
530
587
  try {
531
- const response = await import_axios.default.get(url, {
588
+ const response = await import_axios2.default.get(url, {
532
589
  timeout: 1e4,
533
590
  headers: {
534
591
  "User-Agent": getRandomUserAgent()
@@ -552,15 +609,17 @@ async function fetchArticleContent(ctx, version, isSnapshot) {
552
609
  }
553
610
 
554
611
  // src/index.ts
555
- var import_fs = __toESM(require("fs"), 1);
556
612
  var name = "minecraft-notifier";
557
613
  var inject = ["database", "server"];
558
614
  var Config = import_koishi.Schema.object({
559
615
  checkInterval: import_koishi.Schema.number().default(3).description("\u5728\u7EBF\u72B6\u6001\u68C0\u67E5\u95F4\u9694\uFF08\u5206\u949F\uFF09"),
560
616
  baseApiUrl: import_koishi.Schema.string().default("https://api.openai.com/v1").description("AI \u63A5\u53E3\u7684\u57FA\u7840 URL"),
561
617
  model: import_koishi.Schema.string().default("gpt-5").description("\u4F7F\u7528\u7684 AI \u6A21\u578B"),
562
- apiKey: import_koishi.Schema.string().default("").description("AI \u63A5\u53E3\u7684 API \u5BC6\u94A5").required(),
563
- notifyChannel: import_koishi.Schema.array(String).default([]).description("\u7528\u4E8E\u63A5\u6536\u66F4\u65B0\u901A\u77E5\u7684\u9891\u9053 ID \u5217\u8868")
618
+ apiKey: import_koishi.Schema.string().default("").description("AI \u63A5\u53E3\u7684 API \u5BC6\u94A5").hidden().required(),
619
+ notifyChannel: import_koishi.Schema.array(String).default([]).description("\u7528\u4E8E\u63A5\u6536\u66F4\u65B0\u901A\u77E5\u7684\u9891\u9053 ID \u5217\u8868"),
620
+ giteeApiToken: import_koishi.Schema.string().default("").description("Gitee API \u8BBF\u95EE\u4EE4\u724C\uFF0C\u7528\u4E8E\u4E0A\u4F20 XAML \u6587\u4EF6"),
621
+ giteeOwner: import_koishi.Schema.string().default("").description("Gitee \u4ED3\u5E93\u6240\u6709\u8005\u7528\u6237\u540D"),
622
+ giteeRepo: import_koishi.Schema.string().default("").description("Gitee \u4ED3\u5E93\u540D\u79F0")
564
623
  });
565
624
  function apply(ctx, cfg) {
566
625
  ctx.database.extend(
@@ -612,7 +671,7 @@ function apply(ctx, cfg) {
612
671
  let retries = 0;
613
672
  while (retries <= 3) {
614
673
  try {
615
- const response = await import_axios2.default.get(
674
+ const response = await import_axios3.default.get(
616
675
  "https://launchermeta.mojang.com/mc/game/version_manifest.json",
617
676
  {
618
677
  timeout: 1e4
@@ -633,7 +692,12 @@ function apply(ctx, cfg) {
633
692
  }
634
693
  }
635
694
  };
636
- const xamlPath = import_node_path2.default.join(ctx.baseDir, "data", "minecraft-notifier", "xaml");
695
+ const xamlPath = import_node_path2.default.join(
696
+ ctx.baseDir,
697
+ "data",
698
+ "minecraft-notifier",
699
+ "xaml"
700
+ );
637
701
  if (!import_fs.default.existsSync(xamlPath)) {
638
702
  import_fs.default.mkdirSync(xamlPath, { recursive: true });
639
703
  }
package/lib/index.d.ts CHANGED
@@ -33,6 +33,9 @@ export interface Config {
33
33
  model: string;
34
34
  apiKey: string;
35
35
  notifyChannel: string[];
36
+ giteeApiToken?: string;
37
+ giteeOwner?: string;
38
+ giteeRepo?: string;
36
39
  }
37
40
  export declare const Config: Schema<Config>;
38
41
  export declare function apply(ctx: Context, cfg: Config & {
@@ -1,4 +1,5 @@
1
1
  import { Context } from 'koishi';
2
+ import { Config } from './index';
2
3
  interface Subcategory {
3
4
  subcategory: string;
4
5
  emoji: string;
@@ -15,5 +16,5 @@ interface MinecraftSummary {
15
16
  bug_fixes: CategoryGroup;
16
17
  technical_changes: CategoryGroup;
17
18
  }
18
- export declare function exportXaml(ctx: Context, summary: MinecraftSummary, version: string): Promise<string>;
19
+ export declare function exportXaml(ctx: Context, cfg: Config, summary: MinecraftSummary, version: string): Promise<string>;
19
20
  export {};
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.1.1",
4
+ "version": "1.2.1",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",