koishi-plugin-minecraft-notifier 1.0.2 → 1.1.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.
- package/lib/changelog-summarizer.d.ts +1 -0
- package/lib/index.cjs +168 -8
- package/lib/xaml-generator.d.ts +19 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import '@pynickle/koishi-plugin-adapter-onebot';
|
|
2
2
|
import { Context } from 'koishi';
|
|
3
3
|
import { Config } from './index';
|
|
4
|
+
export declare const minecraftSummaryTypeMap: Record<string, string>;
|
|
4
5
|
export declare function checkNewVersionArticle(ctx: Context, cfg: Config): Promise<void>;
|
|
5
6
|
export declare function processNewVersionArticle(ctx: Context, cfg: Config, version: string, isSnapshot: boolean): Promise<boolean>;
|
|
6
7
|
export declare function generateArticleUrl(version: string, isSnapshot: boolean): string;
|
package/lib/index.cjs
CHANGED
|
@@ -37,6 +37,8 @@ __export(index_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
var import_axios2 = __toESM(require("axios"), 1);
|
|
39
39
|
var import_koishi = require("koishi");
|
|
40
|
+
var import_node_fs2 = require("node:fs");
|
|
41
|
+
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
40
42
|
|
|
41
43
|
// src/changelog-summarizer.ts
|
|
42
44
|
var import_koishi_plugin_adapter_onebot = require("@pynickle/koishi-plugin-adapter-onebot");
|
|
@@ -114,7 +116,156 @@ function getRandomUserAgent() {
|
|
|
114
116
|
return userAgents[randomIndex];
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
// src/xaml-generator.ts
|
|
120
|
+
var import_node_fs = require("node:fs");
|
|
121
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
122
|
+
function generateXaml(summary, version) {
|
|
123
|
+
const orderedCategories = [
|
|
124
|
+
"new_features",
|
|
125
|
+
"improvements",
|
|
126
|
+
"balancing",
|
|
127
|
+
"bug_fixes",
|
|
128
|
+
"technical_changes"
|
|
129
|
+
];
|
|
130
|
+
let categoriesXaml = "";
|
|
131
|
+
for (const category of orderedCategories) {
|
|
132
|
+
const catData = summary[category];
|
|
133
|
+
const general = catData.general || [];
|
|
134
|
+
const subcategories = catData.subcategories || [];
|
|
135
|
+
if (general.length === 0 && subcategories.length === 0) continue;
|
|
136
|
+
const categoryTitle = minecraftSummaryTypeMap[category];
|
|
137
|
+
let contentXaml = "";
|
|
138
|
+
for (let i = 0; i < general.length; i++) {
|
|
139
|
+
const msg = general[i];
|
|
140
|
+
const margin = i === general.length - 1 && subcategories.length > 0 ? "0,0,0,10" : "0,0,0,2";
|
|
141
|
+
contentXaml += `
|
|
142
|
+
<TextBlock
|
|
143
|
+
Margin="${margin}"
|
|
144
|
+
Foreground="{DynamicResource ColorBrush1}"
|
|
145
|
+
Text="- ${msg}" />`;
|
|
146
|
+
}
|
|
147
|
+
for (let j = 0; j < subcategories.length; j++) {
|
|
148
|
+
const sub = subcategories[j];
|
|
149
|
+
contentXaml += `
|
|
150
|
+
<TextBlock
|
|
151
|
+
Margin="0,0,0,4"
|
|
152
|
+
FontSize="14"
|
|
153
|
+
Foreground="{DynamicResource ColorBrush3}"
|
|
154
|
+
Text="${sub.emoji} ${sub.subcategory}" />`;
|
|
155
|
+
for (let k = 0; k < sub.items.length; k++) {
|
|
156
|
+
const msg = sub.items[k];
|
|
157
|
+
const margin = k === sub.items.length - 1 && j === subcategories.length - 1 ? "" : "0,0,0,2";
|
|
158
|
+
contentXaml += `
|
|
159
|
+
<TextBlock
|
|
160
|
+
Margin="${margin}"
|
|
161
|
+
Foreground="{DynamicResource ColorBrush1}"
|
|
162
|
+
Text=" - ${msg}" />`;
|
|
163
|
+
}
|
|
164
|
+
if (j < subcategories.length - 1) {
|
|
165
|
+
contentXaml += `
|
|
166
|
+
<!-- Spacer for subcategories -->
|
|
167
|
+
<TextBlock Margin="0,0,0,10" />`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
categoriesXaml += `
|
|
171
|
+
<!-- ${categoryTitle}\u5361\u7247 -->
|
|
172
|
+
<local:MyCard
|
|
173
|
+
Title="${categoryTitle}"
|
|
174
|
+
Margin="0,5,0,10"
|
|
175
|
+
CanSwap="True"
|
|
176
|
+
IsSwaped="${general.length > 0 || subcategories.length > 1 ? "False" : "True"}"
|
|
177
|
+
Style="{StaticResource Card}">
|
|
178
|
+
<StackPanel Orientation="Vertical" Style="{StaticResource ContentStack}">
|
|
179
|
+
${contentXaml}
|
|
180
|
+
</StackPanel>
|
|
181
|
+
</local:MyCard>`;
|
|
182
|
+
}
|
|
183
|
+
return `<StackPanel
|
|
184
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
185
|
+
xmlns:local="clr-namespace:PCL2;assembly=PCL2"
|
|
186
|
+
xmlns:sys="clr-namespace:System;assembly=mscorlib">
|
|
187
|
+
<StackPanel.Resources>
|
|
188
|
+
<Style x:Key="Card" TargetType="local:MyCard">
|
|
189
|
+
<Setter Property="Margin" Value="0,5" />
|
|
190
|
+
</Style>
|
|
191
|
+
<Style x:Key="ContentStack" TargetType="StackPanel">
|
|
192
|
+
<Setter Property="Margin" Value="20,40,20,20" />
|
|
193
|
+
</Style>
|
|
194
|
+
<Style TargetType="TextBlock">
|
|
195
|
+
<Setter Property="TextWrapping" Value="Wrap" />
|
|
196
|
+
<Setter Property="HorizontalAlignment" Value="Left" />
|
|
197
|
+
<Setter Property="FontSize" Value="13" />
|
|
198
|
+
<Setter Property="Foreground" Value="{DynamicResource ColorBrush1}" />
|
|
199
|
+
</Style>
|
|
200
|
+
</StackPanel.Resources>
|
|
201
|
+
<local:MyCard
|
|
202
|
+
Title="\u{1F514} Minecraft ${version} \u66F4\u65B0\u603B\u7ED3"
|
|
203
|
+
Margin="0,0,0,0"
|
|
204
|
+
CanSwap="True"
|
|
205
|
+
IsSwaped="False"
|
|
206
|
+
Style="{StaticResource Card}">
|
|
207
|
+
<StackPanel Orientation="Vertical" Style="{StaticResource ContentStack}">
|
|
208
|
+
${categoriesXaml}
|
|
209
|
+
<!-- \u5E95\u90E8\u6309\u94AE\uFF1A\u5237\u65B0\u3001Wiki\u3001\u542F\u52A8\u6E38\u620F -->
|
|
210
|
+
<StackPanel
|
|
211
|
+
Margin="0,20,0,0"
|
|
212
|
+
HorizontalAlignment="Center"
|
|
213
|
+
Orientation="Horizontal">
|
|
214
|
+
<local:MyButton
|
|
215
|
+
Width="100"
|
|
216
|
+
Height="35"
|
|
217
|
+
Margin="5,0,5,0"
|
|
218
|
+
ColorType="Highlight"
|
|
219
|
+
EventType="\u5237\u65B0\u4E3B\u9875"
|
|
220
|
+
Text="\u{1F504} \u5237\u65B0\u66F4\u65B0"
|
|
221
|
+
ToolTip="\u4ECE API \u62C9\u53D6\u6700\u65B0\u5185\u5BB9" />
|
|
222
|
+
<local:MyButton
|
|
223
|
+
Width="100"
|
|
224
|
+
Height="35"
|
|
225
|
+
Margin="5,0,5,0"
|
|
226
|
+
ColorType="Highlight"
|
|
227
|
+
EventData="https://zh.minecraft.wiki/"
|
|
228
|
+
EventType="\u6253\u5F00\u7F51\u9875"
|
|
229
|
+
Text="\u{1F4D6} \u67E5\u770B Wiki"
|
|
230
|
+
ToolTip="\u5B98\u65B9\u4E2D\u6587 Wiki" />
|
|
231
|
+
<local:MyButton
|
|
232
|
+
Width="100"
|
|
233
|
+
Height="35"
|
|
234
|
+
Margin="5,0,5,0"
|
|
235
|
+
ColorType="Red"
|
|
236
|
+
EventData="${version}"
|
|
237
|
+
EventType="\u542F\u52A8\u6E38\u620F"
|
|
238
|
+
Text="\u25B6\uFE0F \u542F\u52A8\u6E38\u620F"
|
|
239
|
+
ToolTip="\u542F\u52A8 ${version} \u7248\u672C" />
|
|
240
|
+
</StackPanel>
|
|
241
|
+
</StackPanel>
|
|
242
|
+
</local:MyCard>
|
|
243
|
+
</StackPanel>`;
|
|
244
|
+
}
|
|
245
|
+
async function exportXaml(ctx, summary, version) {
|
|
246
|
+
const xaml = generateXaml(summary, version);
|
|
247
|
+
const xamlPath = import_node_path.default.join(
|
|
248
|
+
ctx.baseDir,
|
|
249
|
+
"data",
|
|
250
|
+
"minecraft-notifier",
|
|
251
|
+
"xaml"
|
|
252
|
+
);
|
|
253
|
+
const xamlName = `${version}.xaml`;
|
|
254
|
+
let fullXamlPath = import_node_path.default.join(xamlPath, xamlName);
|
|
255
|
+
let fullHomePagePath = import_node_path.default.join(xamlPath, "PCL.HomePage.xaml");
|
|
256
|
+
await import_node_fs.promises.writeFile(fullXamlPath, xaml);
|
|
257
|
+
await import_node_fs.promises.copyFile(fullXamlPath, fullHomePagePath);
|
|
258
|
+
return fullXamlPath;
|
|
259
|
+
}
|
|
260
|
+
|
|
117
261
|
// src/changelog-summarizer.ts
|
|
262
|
+
var minecraftSummaryTypeMap = {
|
|
263
|
+
new_features: "\u2728 \u65B0\u7279\u6027",
|
|
264
|
+
improvements: "\u{1F527} \u6539\u8FDB\u4E0E\u4F18\u5316",
|
|
265
|
+
balancing: "\u2696\uFE0F \u5E73\u8861\u8C03\u6574",
|
|
266
|
+
bug_fixes: "\u{1F41B} \u9519\u8BEF\u4FEE\u590D",
|
|
267
|
+
technical_changes: "\u2699\uFE0F \u6280\u672F\u53D8\u66F4"
|
|
268
|
+
};
|
|
118
269
|
async function checkNewVersionArticle(ctx, cfg) {
|
|
119
270
|
const [articleRecord, notifierRecord] = await Promise.all([
|
|
120
271
|
ctx.database.get("minecraft_article_version", 1).then((records) => records[0]),
|
|
@@ -193,13 +344,6 @@ async function processNewVersionArticle(ctx, cfg, version, isSnapshot) {
|
|
|
193
344
|
);
|
|
194
345
|
return await summarizeMinecraftUpdate(ctx, cfg, version, content);
|
|
195
346
|
}
|
|
196
|
-
var minecraftSummaryTypeMap = {
|
|
197
|
-
new_features: "\u2728 \u65B0\u7279\u6027",
|
|
198
|
-
improvements: "\u{1F527} \u6539\u8FDB\u4E0E\u4F18\u5316",
|
|
199
|
-
balancing: "\u2696\uFE0F \u5E73\u8861\u8C03\u6574",
|
|
200
|
-
bug_fixes: "\u{1F41B} \u9519\u8BEF\u4FEE\u590D",
|
|
201
|
-
technical_changes: "\u2699\uFE0F \u6280\u672F\u53D8\u66F4"
|
|
202
|
-
};
|
|
203
347
|
async function summarizeMinecraftUpdate(ctx, cfg, version, updateContent) {
|
|
204
348
|
const url = cfg.baseApiUrl.endsWith("/") ? `${cfg.baseApiUrl}chat/completions` : `${cfg.baseApiUrl}/chat/completions`;
|
|
205
349
|
const userPrompt = `
|
|
@@ -354,6 +498,7 @@ ${subList}`)
|
|
|
354
498
|
for (const groupId of cfg.notifyChannel) {
|
|
355
499
|
await ctx.bots[0].internal.sendGroupForwardMsg(groupId, messages);
|
|
356
500
|
}
|
|
501
|
+
await exportXaml(ctx, summary, version);
|
|
357
502
|
return true;
|
|
358
503
|
}
|
|
359
504
|
function generateArticleUrl(version, isSnapshot) {
|
|
@@ -408,7 +553,7 @@ async function fetchArticleContent(ctx, version, isSnapshot) {
|
|
|
408
553
|
|
|
409
554
|
// src/index.ts
|
|
410
555
|
var name = "minecraft-notifier";
|
|
411
|
-
var inject = ["database"];
|
|
556
|
+
var inject = ["database", "server"];
|
|
412
557
|
var Config = import_koishi.Schema.object({
|
|
413
558
|
checkInterval: import_koishi.Schema.number().default(3).description("\u5728\u7EBF\u72B6\u6001\u68C0\u67E5\u95F4\u9694\uFF08\u5206\u949F\uFF09"),
|
|
414
559
|
baseApiUrl: import_koishi.Schema.string().default("https://api.openai.com/v1").description("AI \u63A5\u53E3\u7684\u57FA\u7840 URL"),
|
|
@@ -487,6 +632,21 @@ function apply(ctx, cfg) {
|
|
|
487
632
|
}
|
|
488
633
|
}
|
|
489
634
|
};
|
|
635
|
+
ctx.server.get("/PCL", async (koaCtx) => {
|
|
636
|
+
koaCtx.set("Content-Type", "application/xml; charset=utf-8");
|
|
637
|
+
koaCtx.set(
|
|
638
|
+
"Content-Disposition",
|
|
639
|
+
'inline; filename="PCL.HomePage.xaml"'
|
|
640
|
+
);
|
|
641
|
+
const xamlPath = import_node_path2.default.join(
|
|
642
|
+
ctx.baseDir,
|
|
643
|
+
"data",
|
|
644
|
+
"minecraft-notifier",
|
|
645
|
+
"xaml"
|
|
646
|
+
);
|
|
647
|
+
let fullHomePagePath = import_node_path2.default.join(xamlPath, "PCL.HomePage.xaml");
|
|
648
|
+
koaCtx.response.body = await import_node_fs2.promises.readFile(fullHomePagePath);
|
|
649
|
+
});
|
|
490
650
|
ctx.setInterval(async () => {
|
|
491
651
|
try {
|
|
492
652
|
await loadData();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
interface Subcategory {
|
|
3
|
+
subcategory: string;
|
|
4
|
+
emoji: string;
|
|
5
|
+
items: string[];
|
|
6
|
+
}
|
|
7
|
+
interface CategoryGroup {
|
|
8
|
+
general: string[];
|
|
9
|
+
subcategories: Subcategory[];
|
|
10
|
+
}
|
|
11
|
+
interface MinecraftSummary {
|
|
12
|
+
new_features: CategoryGroup;
|
|
13
|
+
improvements: CategoryGroup;
|
|
14
|
+
balancing: CategoryGroup;
|
|
15
|
+
bug_fixes: CategoryGroup;
|
|
16
|
+
technical_changes: CategoryGroup;
|
|
17
|
+
}
|
|
18
|
+
export declare function exportXaml(ctx: Context, summary: MinecraftSummary, version: string): Promise<string>;
|
|
19
|
+
export {};
|
package/package.json
CHANGED