@wahaha216/koishi-plugin-jmcomic 0.1.1 → 0.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.
@@ -1,5 +1,5 @@
1
1
  import crypto from "crypto";
2
- import { IJMUser } from "../types/JMClient";
2
+ import { IJMSearchResult, IJMUser } from "../types/JMClient";
3
3
  import { JMPhotoAbstract } from "./JMPhotoAbstract";
4
4
  import { JMAlbumAbstract } from "./JMAlbumAbstract";
5
5
  export declare abstract class JMClientAbstract {
@@ -14,6 +14,12 @@ export declare abstract class JMClientAbstract {
14
14
  * @returns JM用户信息
15
15
  */
16
16
  abstract login(username: string, password: string): Promise<IJMUser>;
17
+ /**
18
+ * JM搜索
19
+ * @param keyword 关键词
20
+ * @returns JM搜索结果
21
+ */
22
+ abstract search(keyword: string): Promise<IJMSearchResult>;
17
23
  /**
18
24
  * 根据本子ID获取本子信息
19
25
  * @param id 本子ID
@@ -1,6 +1,6 @@
1
1
  import { Config } from "..";
2
2
  import { Logger, HTTP } from "koishi";
3
- import { IJMUser } from "../types/JMClient";
3
+ import { IJMUser, IJMSearchResult } from "../types/JMClient";
4
4
  import { JMClientAbstract } from "../abstract/JMClientAbstract";
5
5
  import { JMAppPhoto } from "./JMAppPhoto";
6
6
  import { JMAppAlbum } from "./JMAppAlbum";
@@ -30,6 +30,7 @@ export declare class JMAppClient extends JMClientAbstract {
30
30
  * @returns 用户信息
31
31
  */
32
32
  login(username: string, password: string): Promise<IJMUser>;
33
+ search(keyword: string): Promise<IJMSearchResult>;
33
34
  getAlbumById(id: string): Promise<JMAppAlbum>;
34
35
  getPhotoById(id: string): Promise<JMAppPhoto>;
35
36
  downloadByAlbum(album: JMAppAlbum): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { Config } from "..";
2
2
  import { Logger, HTTP } from "koishi";
3
3
  import { JMClientAbstract } from "../abstract/JMClientAbstract";
4
- import { IJMUser } from "../types/JMClient";
4
+ import { IJMSearchResult, IJMUser } from "../types/JMClient";
5
5
  import { JMHtmlAlbum } from "./JMHtmlAlbum";
6
6
  import { JMHtmlPhoto } from "./JMHtmlPhoto";
7
7
  export declare class JMHtmlClient extends JMClientAbstract {
@@ -19,6 +19,7 @@ export declare class JMHtmlClient extends JMClientAbstract {
19
19
  private http;
20
20
  constructor(root: string, http: HTTP, config: Config, logger: Logger);
21
21
  login(username: string, password: string): Promise<IJMUser>;
22
+ search(keyword: string): Promise<IJMSearchResult>;
22
23
  getAlbumById(id: string): Promise<JMHtmlAlbum>;
23
24
  getPhotoById(id: string): Promise<JMHtmlPhoto>;
24
25
  downloadByAlbum(album: JMHtmlAlbum): Promise<void>;
package/lib/index.js CHANGED
@@ -33,14 +33,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
  // src/locales/zh-CN.yml
34
34
  var require_zh_CN = __commonJS({
35
35
  "src/locales/zh-CN.yml"(exports2, module2) {
36
- module2.exports = { commands: { jm: { description: "下载JM漫画,无需python!", examples: "jm album 本子数字ID\njm album info 本子数字ID\njm photo 本子章节数字ID", album: { examples: "jm album 数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", queueFirst: "已将 {id} 添加到处理队列,即将开始处理", queuePosition: "已将 {id} 添加到处理队列\n前面还有 {ahead} 个任务等待或正在处理", queueProcessing: "已将 {id} 添加到处理队列\n当前任务状态:{status}", notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" }, info: { examples: "jm album info 本子数字ID", messages: { notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } } }, photo: { examples: "jm photo 本子章节数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", queueFirst: "已将 {id} 添加到处理队列,即将开始处理", queuePosition: "已将 {id} 添加到处理队列\n前面还有 {ahead} 个任务等待或正在处理", queueProcessing: "已将 {id} 添加到处理队列\n当前任务状态:{status}", notExistError: "找不到该ID对应的章节", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } }, queue: { examples: "jm queue", messages: { emptyQueue: "当前没有正在处理或者等待处理的任务", msgFormat: "ID: {id}, 类型: {type}, 状态: {status}\n", task: { pending: "等待中...", processing: "处理中...", failed: "发生未知错误", completed: "已完成", unknown: "未定义状态" }, type: { album: "本子", photo: "章节" } } } } }, _config: [{ $desc: "基础设置", sendMethod: "发送方式", fileMethod: "文件获取方式<br>`buffer`: 读取成buffer后发送给bot实现端<br>`file`: 以`file:///` 本地路径形式发送,如docker环境,请在bot实现端同时映射/koishi目录", password: "密码,留空则不加密", fileName: "文件名定义<br>`{{name}}`:标题<br>`{{id}}`:章节或者本子ID<br>`{{index}}`:多章节本子自动填充`1` 、 `2`" }, { level: "压缩级别,0~9,0为仅存储" }, { $desc: "限制相关设置", retryCount: "重试次数限制", concurrentDownloadLimit: "同时下载数量限制", concurrentDecodeLimit: "同时解密数量限制", concurrentQueueLimit: "同时处理数量限制" }, { $desc: "缓存设置", cache: "缓存文件" }, { autoDelete: "自动删除缓存,**依赖cron服务**" }, { cron: "5位cron表达式", deleteInStart: "启动时检测", keepDays: "缓存保留时间(天)" }, { $desc: "开发者选项", debug: "调试模式,输出更多信息" }] };
36
+ module2.exports = { commands: { jm: { description: "下载JM漫画,无需python!", examples: "jm album 本子数字ID\njm album info 本子数字ID\njm photo 本子章节数字ID", album: { examples: "jm album 数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", queueFirst: "已将 {id} 添加到处理队列,即将开始处理", queuePosition: "已将 {id} 添加到处理队列\n前面还有 {ahead} 个任务等待或正在处理", queueProcessing: "已将 {id} 添加到处理队列\n当前任务状态:{status}", notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" }, info: { examples: "jm album info 本子数字ID", messages: { notExistError: "找不到该ID对应的本子", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } } }, photo: { examples: "jm photo 本子章节数字ID", messages: { addedToQueue: "已将 {id} 添加到处理队列,请稍候。", queueFirst: "已将 {id} 添加到处理队列,即将开始处理", queuePosition: "已将 {id} 添加到处理队列\n前面还有 {ahead} 个任务等待或正在处理", queueProcessing: "已将 {id} 添加到处理队列\n当前任务状态:{status}", notExistError: "找不到该ID对应的章节", mysqlError: "已尝试所有备用地址,但是JM坏掉了" } }, queue: { examples: "jm queue", messages: { emptyQueue: "当前没有正在处理或者等待处理的任务", msgFormat: "ID: {id}, 类型: {type}, 状态: {status}\n", task: { pending: "等待中...", processing: "处理中...", failed: "发生未知错误", completed: "已完成", unknown: "未定义状态" }, type: { album: "本子", photo: "章节" } } }, search: { example: "jm search <关键词>", messages: { emptyKeywordError: "请输入搜索关键词", id: "JMID", name: "名称", author: "作者", category: "分类", description: "描述", pagination: "共 {total} 条, 当前第 {page} 页, 每页 {pageSize} 条" } } } }, _config: [{ $desc: "基础设置", sendMethod: "发送方式", fileMethod: "文件获取方式<br>`buffer`: 读取成buffer后发送给bot实现端<br>`file`: 以`file:///` 本地路径形式发送,如docker环境,请在bot实现端同时映射/koishi目录", password: "密码,留空则不加密", fileName: "文件名定义<br>`{{name}}`:标题<br>`{{id}}`:章节或者本子ID<br>`{{index}}`:多章节本子自动填充`1` 、 `2`" }, { level: "压缩级别,0~9,0为仅存储" }, { $desc: "限制相关设置", retryCount: "重试次数限制", concurrentDownloadLimit: "同时下载数量限制", concurrentDecodeLimit: "同时解密数量限制", concurrentQueueLimit: "同时处理数量限制" }, { $desc: "缓存设置", cache: "缓存文件" }, { autoDelete: "自动删除缓存,**依赖cron服务**" }, { cron: "5位cron表达式", deleteInStart: "启动时检测", keepDays: "缓存保留时间(天)" }, { $desc: "开发者选项", debug: "调试模式,输出更多信息" }] };
37
37
  }
38
38
  });
39
39
 
40
40
  // src/locales/en-US.yml
41
41
  var require_en_US = __commonJS({
42
42
  "src/locales/en-US.yml"(exports2, module2) {
43
- module2.exports = { commands: { jm: { description: "Download JM comics without python!", examples: "jm album albumID\njm album info albumID\njm photo photoID", album: { examples: "jm album albumID", messages: { addedToQueue: "Album {id} has been added to the processing queue. Please wait.", queueFirst: "Added {id} to the processing queue, starting shortly.", queuePosition: "Added {id} to the processing queue.\nThere are {ahead} tasks ahead or currently processing.", queueProcessing: "Added {id} to the processing queue.\nCurrent task status: {status}", notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." }, info: { examples: "jm album info albumID", messages: { notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." } } }, photo: { examples: "jm photo photoID", messages: { addedToQueue: "Photo {id} has been added to the processing queue. Please wait.", queueFirst: "Added {id} to the processing queue, starting shortly.", queuePosition: "Added {id} to the processing queue.\nThere are {ahead} tasks ahead or currently processing.", queueProcessing: "Added {id} to the processing queue.\nCurrent task status: {status}", notExistError: "photoID not found", mysqlError: "All alternate addresses have been tried. But no response." } }, queue: { examples: "jm queue", messages: { emptyQueue: "There are currently no tasks being processed or waiting.", msgFormat: "ID: {id}, type: {type}, status: {status}\n", task: { Pending: "Pending...", Processing: "Processing...", failed: "Failed (Unknown Error)", completed: "Completed", unknown: "Unknown Status" }, type: { album: "Album", photo: "Photo" } } } } }, _config: [{ $desc: "Basic settings", sendMethod: "Send method", fileMethod: "File acquisition method<br>`buffer`: Read as buffer and send it to the bot implementation.<br>`file`: Send it in the local path of `file:///`. For example, if in the docker environment, please map the `/koishi` directory at the bot implementation.", retryCount: "Retry limit", password: "Password, leave blank without encryption", fileName: "File name definition<br>`{{name}}`: Title<br>`{{id}}`: Chapter or Book ID<br>`{{index}}`: Multi-chapter book auto-filling `_1` `_2`" }, { $desc: "Limit settings", retryCount: "Retry limit", concurrentDownloadLimit: "Concurrent Download Limit", concurrentDecodeLimit: "Concurrent Decode Limit", concurrentQueueLimit: "Concurrent Queue Limit" }, { level: "Compression level, 0~9, 0 is only stores" }, { $desc: "Cache settings", cache: "Cache files" }, { autoDelete: "Automatically delete cache, **need cron services**" }, { cron: "5-bit cron expression", deleteInStart: "Detection on startup", keepDays: "Cache retention time (days)" }, { $desc: "Developer Options", debug: "Debug mode, output more information" }] };
43
+ module2.exports = { commands: { jm: { description: "Download JM comics without python!", examples: "jm album albumID\njm album info albumID\njm photo photoID", album: { examples: "jm album albumID", messages: { addedToQueue: "Album {id} has been added to the processing queue. Please wait.", queueFirst: "Added {id} to the processing queue, starting shortly.", queuePosition: "Added {id} to the processing queue.\nThere are {ahead} tasks ahead or currently processing.", queueProcessing: "Added {id} to the processing queue.\nCurrent task status: {status}", notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." }, info: { examples: "jm album info albumID", messages: { notExistError: "albumID not found", mysqlError: "All alternate addresses have been tried. But no response." } } }, photo: { examples: "jm photo photoID", messages: { addedToQueue: "Photo {id} has been added to the processing queue. Please wait.", queueFirst: "Added {id} to the processing queue, starting shortly.", queuePosition: "Added {id} to the processing queue.\nThere are {ahead} tasks ahead or currently processing.", queueProcessing: "Added {id} to the processing queue.\nCurrent task status: {status}", notExistError: "photoID not found", mysqlError: "All alternate addresses have been tried. But no response." } }, queue: { examples: "jm queue", messages: { emptyQueue: "There are currently no tasks being processed or waiting.", msgFormat: "ID: {id}, type: {type}, status: {status}\n", task: { Pending: "Pending...", Processing: "Processing...", failed: "Failed (Unknown Error)", completed: "Completed", unknown: "Unknown Status" }, type: { album: "Album", photo: "Photo" } } }, search: { example: "jm search <keyword>", messages: { emptyKeywordError: "Please enter search keywords", id: "JMID", name: "name", author: "author", category: "category", description: "description", pagination: "Total {total}, current {page} page, each page {pageSize}" } } } }, _config: [{ $desc: "Basic settings", sendMethod: "Send method", fileMethod: "File acquisition method<br>`buffer`: Read as buffer and send it to the bot implementation.<br>`file`: Send it in the local path of `file:///`. For example, if in the docker environment, please map the `/koishi` directory at the bot implementation.", retryCount: "Retry limit", password: "Password, leave blank without encryption", fileName: "File name definition<br>`{{name}}`: Title<br>`{{id}}`: Chapter or Book ID<br>`{{index}}`: Multi-chapter book auto-filling `_1` `_2`" }, { $desc: "Limit settings", retryCount: "Retry limit", concurrentDownloadLimit: "Concurrent Download Limit", concurrentDecodeLimit: "Concurrent Decode Limit", concurrentQueueLimit: "Concurrent Queue Limit" }, { level: "Compression level, 0~9, 0 is only stores" }, { $desc: "Cache settings", cache: "Cache files" }, { autoDelete: "Automatically delete cache, **need cron services**" }, { cron: "5-bit cron expression", deleteInStart: "Detection on startup", keepDays: "Cache retention time (days)" }, { $desc: "Developer Options", debug: "Debug mode, output more information" }] };
44
44
  }
45
45
  });
46
46
 
@@ -791,6 +791,24 @@ var JMAppClient = class _JMAppClient extends JMClientAbstract {
791
791
  );
792
792
  return this.decodeBase64(res.data, timestamp);
793
793
  }
794
+ async search(keyword) {
795
+ if (this.config.debug) this.logger.info(`搜索本子: ${keyword}`);
796
+ const timestamp = this.getTimeStamp();
797
+ const { token, tokenparam } = this.getTokenAndTokenParam(timestamp);
798
+ const searchRes = await requestWithUrlSwitch(
799
+ "/search",
800
+ "POST",
801
+ {
802
+ params: { search_query: keyword },
803
+ headers: { token, tokenparam },
804
+ responseType: "json"
805
+ },
806
+ this.http,
807
+ this.config,
808
+ this.logger
809
+ );
810
+ return this.decodeBase64(searchRes.data, timestamp);
811
+ }
794
812
  async getAlbumById(id) {
795
813
  if (this.config.debug) this.logger.info(`获取本子(${id})信息`);
796
814
  const timestamp = this.getTimeStamp();
@@ -1123,7 +1141,7 @@ var createJmProcessor = /* @__PURE__ */ __name((processorConfig, http, config, l
1123
1141
  debug
1124
1142
  } = processorConfig;
1125
1143
  return async (payload) => {
1126
- const { id, session, messageId } = payload;
1144
+ const { id, session, messageId, scope } = payload;
1127
1145
  try {
1128
1146
  const jmClient = new JMAppClient(root, http, config, logger);
1129
1147
  let filePath;
@@ -1229,13 +1247,13 @@ var createJmProcessor = /* @__PURE__ */ __name((processorConfig, http, config, l
1229
1247
  if (error instanceof AlbumNotExistError || error instanceof PhotoNotExistError) {
1230
1248
  await session.send([
1231
1249
  import_koishi.h.quote(messageId),
1232
- import_koishi.h.text(session.text(".notExistError"))
1250
+ import_koishi.h.text(session.text(`${scope}.notExistError`))
1233
1251
  // 假设 .notExistError 可以通用
1234
1252
  ]);
1235
1253
  } else if (error instanceof MySqlError) {
1236
1254
  await session.send([
1237
1255
  import_koishi.h.quote(messageId),
1238
- import_koishi.h.text(session.text(".mysqlError"))
1256
+ import_koishi.h.text(session.text(`${scope}.mysqlError`))
1239
1257
  ]);
1240
1258
  } else {
1241
1259
  await session.send([
@@ -1471,7 +1489,7 @@ async function apply(ctx, config) {
1471
1489
  config,
1472
1490
  logger
1473
1491
  );
1474
- const handleAlbumOrPhoto = /* @__PURE__ */ __name(async (session, id) => {
1492
+ const handleAlbumOrPhoto = /* @__PURE__ */ __name(async (session, id, type) => {
1475
1493
  const messageId = session.messageId;
1476
1494
  if (!/^\d+$/.test(id)) {
1477
1495
  await session.send([
@@ -1481,10 +1499,11 @@ async function apply(ctx, config) {
1481
1499
  return;
1482
1500
  }
1483
1501
  const { task, pendingAhead, queuePosition } = queue.add({
1484
- type: "album",
1502
+ type,
1485
1503
  id,
1486
1504
  session,
1487
- messageId
1505
+ messageId,
1506
+ scope: session.scope
1488
1507
  });
1489
1508
  const params = {
1490
1509
  id,
@@ -1503,10 +1522,10 @@ async function apply(ctx, config) {
1503
1522
  await session.send(msg);
1504
1523
  }, "handleAlbumOrPhoto");
1505
1524
  ctx.command("jm.album <albumId:string>").alias("本子").action(async ({ session, options }, albumId) => {
1506
- await handleAlbumOrPhoto(session, albumId);
1525
+ await handleAlbumOrPhoto(session, albumId, "album");
1507
1526
  });
1508
1527
  ctx.command("jm.photo <photoId:string>").alias("本子章节").action(async ({ session }, photoId) => {
1509
- await handleAlbumOrPhoto(session, photoId);
1528
+ await handleAlbumOrPhoto(session, photoId, "photo");
1510
1529
  });
1511
1530
  ctx.command("jm.album.info <albumId:string>").alias("本子信息").action(async ({ session, options }, albumId) => {
1512
1531
  const messageId = session.messageId;
@@ -1552,6 +1571,65 @@ async function apply(ctx, config) {
1552
1571
  }
1553
1572
  }
1554
1573
  });
1574
+ ctx.command("jm.search <keyword:string>").alias("本子搜索").option("page", "-p <page:number>", { fallback: 1 }).option("limit", "-l <limit:number>", { fallback: 10 }).action(async ({ session, options }, keyword) => {
1575
+ const messageId = session.messageId;
1576
+ if (!keyword) {
1577
+ await session.send([
1578
+ import_koishi2.h.quote(messageId),
1579
+ import_koishi2.h.text(session.text(".emptyKeywordError"))
1580
+ ]);
1581
+ return;
1582
+ }
1583
+ try {
1584
+ const jmClient = new JMAppClient(root, ctx.http, config, logger);
1585
+ const searchResult = await jmClient.search(keyword);
1586
+ const contents = searchResult.content;
1587
+ const fragment = [import_koishi2.h.quote(messageId)];
1588
+ const page = options.page > 0 ? options.page : 1;
1589
+ const pageSize = options.limit > 0 ? options.limit : 10;
1590
+ const startIndex = (page - 1) * pageSize;
1591
+ const endIndex = page * pageSize;
1592
+ contents.slice(startIndex, endIndex).forEach((content) => {
1593
+ fragment.push(`${session.text(".id")}: ${content.id}
1594
+ `);
1595
+ fragment.push(`${session.text(".name")}: ${content.name}
1596
+ `);
1597
+ fragment.push(`${session.text(".author")}: ${content.author}
1598
+ `);
1599
+ fragment.push(
1600
+ `${session.text(".category")}: ${content.category.title}
1601
+ `
1602
+ );
1603
+ fragment.push(
1604
+ `${session.text(".description")}: ${content.description}
1605
+
1606
+ `
1607
+ );
1608
+ });
1609
+ fragment.push(
1610
+ session.text(".pagination", {
1611
+ total: contents.length,
1612
+ page,
1613
+ pageSize
1614
+ })
1615
+ );
1616
+ await session.send(fragment);
1617
+ } catch (error) {
1618
+ if (error instanceof AlbumNotExistError) {
1619
+ await session.send([
1620
+ import_koishi2.h.quote(messageId),
1621
+ import_koishi2.h.text(session.text(".notExistError"))
1622
+ ]);
1623
+ } else if (error instanceof MySqlError) {
1624
+ await session.send([
1625
+ import_koishi2.h.quote(messageId),
1626
+ import_koishi2.h.text(session.text(".mysqlError"))
1627
+ ]);
1628
+ } else {
1629
+ throw new Error(error);
1630
+ }
1631
+ }
1632
+ });
1555
1633
  ctx.command("jm.queue").alias("本子队列").action(async ({ session, options }) => {
1556
1634
  const messageId = session.messageId;
1557
1635
  const allTasks = queue.getAllTasks();
@@ -5,6 +5,7 @@ export type JmTaskPayload = {
5
5
  id: string;
6
6
  session: Session;
7
7
  messageId: string;
8
+ scope: string;
8
9
  };
9
10
  interface ProcessorConfig {
10
11
  root: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wahaha216/koishi-plugin-jmcomic",
3
3
  "description": "下载JM本子,无需python。支持pdf、zip加密。",
4
- "version": "0.1.1",
4
+ "version": "0.2.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -17,6 +17,22 @@ jm queue
17
17
 
18
18
  ## 更新日志
19
19
 
20
+ <details>
21
+ <summary>0.2.1</summary>
22
+
23
+ 1. 搜索分页限制
24
+ 2. 搜索结果分割空行
25
+
26
+ </details>
27
+
28
+ <details>
29
+ <summary>0.2.0</summary>
30
+
31
+ 1. 简易搜索功能
32
+ 2. 修复队列丢失i18n key的问题
33
+
34
+ </details>
35
+
20
36
  <details>
21
37
  <summary>0.1.1</summary>
22
38