koishi-plugin-luogu-saver-bot 0.1.6 → 0.1.8
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/index.d.ts +1 -0
- package/lib/index.js +31 -22
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -54,9 +54,8 @@ __name(statusToString, "statusToString");
|
|
|
54
54
|
|
|
55
55
|
// src/index.ts
|
|
56
56
|
var import_markdown_it = __toESM(require("markdown-it"));
|
|
57
|
-
var import_plugin_katex = require("@mdit/plugin-katex");
|
|
58
57
|
var name = "luogu-saver-bot";
|
|
59
|
-
var inject = ["puppeteer"];
|
|
58
|
+
var inject = ["puppeteer", "censor"];
|
|
60
59
|
var Config = import_koishi.Schema.object({
|
|
61
60
|
endpoint: import_koishi.Schema.string().description("自定义 API endpoint,结尾无需斜杠").role("input").default(""),
|
|
62
61
|
userAgent: import_koishi.Schema.string().description("自定义 User-Agent").role("input").default("Uptime-Kuma")
|
|
@@ -130,16 +129,23 @@ var LuoguSaverClient = class {
|
|
|
130
129
|
return res.data;
|
|
131
130
|
}
|
|
132
131
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
async function censoring(ctx, text) {
|
|
133
|
+
if (!ctx.censor) return text;
|
|
134
|
+
console.log(await ctx.censor.transform(text));
|
|
135
|
+
return await ctx.censor.transform(text);
|
|
136
|
+
}
|
|
137
|
+
__name(censoring, "censoring");
|
|
138
|
+
async function generateHtml(title, authorInfo, markdownContent) {
|
|
139
|
+
const { katex } = await import("@mdit/plugin-katex");
|
|
140
|
+
const md = new import_markdown_it.default({
|
|
141
|
+
html: true,
|
|
142
|
+
breaks: true
|
|
143
|
+
}).use(katex, {
|
|
144
|
+
allowFunctionInTextMode: true,
|
|
145
|
+
// 允许在文本模式下使用函数
|
|
146
|
+
strict: false
|
|
147
|
+
// 禁用严格模式,防止因不标准语法报错
|
|
148
|
+
});
|
|
143
149
|
const renderedBody = md.render(markdownContent);
|
|
144
150
|
return `<!doctype html>
|
|
145
151
|
<html>
|
|
@@ -307,7 +313,7 @@ function apply(ctx, config = {}) {
|
|
|
307
313
|
const art = await ctx.luogu_saver.getArticle(id);
|
|
308
314
|
console.log(art);
|
|
309
315
|
if (!art) return "未找到文章";
|
|
310
|
-
return `${art.title} by ${art.authorId}
|
|
316
|
+
return await censoring(ctx, `${art.title} by ${art.authorId}`);
|
|
311
317
|
});
|
|
312
318
|
ctx.command("创建保存任务 <target> <targetId>", "创建类型为 save 的任务").action(async (_, target, targetId) => {
|
|
313
319
|
const body = { type: "save", payload: { target, targetId } };
|
|
@@ -320,16 +326,16 @@ function apply(ctx, config = {}) {
|
|
|
320
326
|
const task = await ctx.luogu_saver.getTask(id);
|
|
321
327
|
if (task == null) return "任务不存在或返回为空";
|
|
322
328
|
if (typeof task === "object" && "status" in task) return `任务 ${id} 状态: ${statusToString(task.status)}`;
|
|
323
|
-
return JSON.stringify(task);
|
|
329
|
+
return await censoring(ctx, JSON.stringify(task));
|
|
324
330
|
});
|
|
325
331
|
ctx.command("获取文章 <id>", "获取文章并截取长图").option("width", "-w <width:number>", { fallback: 960 }).action(async ({ session, options }, id) => {
|
|
326
332
|
if (!id) return "请提供文章 ID";
|
|
327
333
|
const art = await ctx.luogu_saver.getArticle(id);
|
|
328
334
|
if (!art) return "未找到文章";
|
|
329
|
-
const rawContent = art.content ?? art.renderedContent ?? "";
|
|
330
|
-
const title = art.title ?? "";
|
|
331
|
-
const authorInfo = `作者 UID: ${art.authorId}
|
|
332
|
-
const html = generateHtml(title, authorInfo, rawContent);
|
|
335
|
+
const rawContent = await censoring(ctx, art.content ?? art.renderedContent ?? "");
|
|
336
|
+
const title = await censoring(ctx, art.title ?? "");
|
|
337
|
+
const authorInfo = await censoring(ctx, `作者 UID: ${art.authorId}`);
|
|
338
|
+
const html = await generateHtml(title, authorInfo, rawContent);
|
|
333
339
|
if (!ctx.puppeteer) return "当前没有可用的 puppeteer 服务。";
|
|
334
340
|
const page = await ctx.puppeteer.page();
|
|
335
341
|
try {
|
|
@@ -382,10 +388,13 @@ function apply(ctx, config = {}) {
|
|
|
382
388
|
if (!id) return "请提供剪贴板 ID";
|
|
383
389
|
const paste = await ctx.luogu_saver.getPaste(id);
|
|
384
390
|
if (!paste) return "未找到剪贴板内容";
|
|
385
|
-
const rawContent = paste.content ?? paste.renderedContent ?? "";
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
391
|
+
const rawContent = await censoring(ctx, paste.content ?? paste.renderedContent ?? "");
|
|
392
|
+
console.log(rawContent);
|
|
393
|
+
const title = await censoring(ctx, `剪贴板: ${paste.id}`);
|
|
394
|
+
console.log(title);
|
|
395
|
+
const authorInfo = await censoring(ctx, paste.author ? `创建者: ${paste.author.name} (UID: ${paste.author.id})` : `创建者 UID: ${paste.authorId}`);
|
|
396
|
+
console.log(authorInfo);
|
|
397
|
+
const html = await generateHtml(title, authorInfo, rawContent);
|
|
389
398
|
if (!ctx.puppeteer) return "当前没有可用的 puppeteer 服务。";
|
|
390
399
|
const page = await ctx.puppeteer.page();
|
|
391
400
|
try {
|