koishi-plugin-luogu-saver-bot 0.1.7 → 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 CHANGED
@@ -114,6 +114,7 @@ declare module 'koishi' {
114
114
  interface Context {
115
115
  luogu_saver: LuoguSaverClient;
116
116
  puppeteer?: any;
117
+ censor: any;
117
118
  }
118
119
  }
119
120
  export declare function apply(ctx: Context, config?: Config): void;
package/lib/index.js CHANGED
@@ -55,7 +55,7 @@ __name(statusToString, "statusToString");
55
55
  // src/index.ts
56
56
  var import_markdown_it = __toESM(require("markdown-it"));
57
57
  var name = "luogu-saver-bot";
58
- var inject = ["puppeteer"];
58
+ var inject = ["puppeteer", "censor"];
59
59
  var Config = import_koishi.Schema.object({
60
60
  endpoint: import_koishi.Schema.string().description("自定义 API endpoint,结尾无需斜杠").role("input").default(""),
61
61
  userAgent: import_koishi.Schema.string().description("自定义 User-Agent").role("input").default("Uptime-Kuma")
@@ -129,6 +129,12 @@ var LuoguSaverClient = class {
129
129
  return res.data;
130
130
  }
131
131
  };
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");
132
138
  async function generateHtml(title, authorInfo, markdownContent) {
133
139
  const { katex } = await import("@mdit/plugin-katex");
134
140
  const md = new import_markdown_it.default({
@@ -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,15 +326,15 @@ 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}`;
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}`);
332
338
  const html = await generateHtml(title, authorInfo, rawContent);
333
339
  if (!ctx.puppeteer) return "当前没有可用的 puppeteer 服务。";
334
340
  const page = await ctx.puppeteer.page();
@@ -382,9 +388,12 @@ 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
- const title = `剪贴板: ${paste.id}`;
387
- const authorInfo = paste.author ? `创建者: ${paste.author.name} (UID: ${paste.author.id})` : `创建者 UID: ${paste.authorId}`;
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);
388
397
  const html = await generateHtml(title, authorInfo, rawContent);
389
398
  if (!ctx.puppeteer) return "当前没有可用的 puppeteer 服务。";
390
399
  const page = await ctx.puppeteer.page();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-luogu-saver-bot",
3
3
  "description": "洛谷保存站机器人",
4
- "version": "0.1.7",
4
+ "version": "0.1.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [