@wahaha216/koishi-plugin-jmcomic 0.1.1 → 0.2.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.
|
@@ -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: "描述" } } } }, _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" } } } }, _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(
|
|
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(
|
|
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
|
|
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,52 @@ async function apply(ctx, config) {
|
|
|
1552
1571
|
}
|
|
1553
1572
|
}
|
|
1554
1573
|
});
|
|
1574
|
+
ctx.command("jm.search <keyword:string>").alias("本子搜索").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
|
+
console.log(JSON.stringify(searchResult));
|
|
1587
|
+
const contents = searchResult.content;
|
|
1588
|
+
const fragment = [import_koishi2.h.quote(messageId)];
|
|
1589
|
+
contents.forEach((content) => {
|
|
1590
|
+
fragment.push(`${session.text(".id")}: ${content.id}
|
|
1591
|
+
`);
|
|
1592
|
+
fragment.push(`${session.text(".name")}: ${content.name}
|
|
1593
|
+
`);
|
|
1594
|
+
fragment.push(`${session.text(".author")}: ${content.author}
|
|
1595
|
+
`);
|
|
1596
|
+
fragment.push(`${session.text(".category")}: ${content.category.title}
|
|
1597
|
+
`);
|
|
1598
|
+
fragment.push(
|
|
1599
|
+
`${session.text(".description")}: ${content.description}
|
|
1600
|
+
`
|
|
1601
|
+
);
|
|
1602
|
+
});
|
|
1603
|
+
await session.send(fragment);
|
|
1604
|
+
} catch (error) {
|
|
1605
|
+
if (error instanceof AlbumNotExistError) {
|
|
1606
|
+
await session.send([
|
|
1607
|
+
import_koishi2.h.quote(messageId),
|
|
1608
|
+
import_koishi2.h.text(session.text(".notExistError"))
|
|
1609
|
+
]);
|
|
1610
|
+
} else if (error instanceof MySqlError) {
|
|
1611
|
+
await session.send([
|
|
1612
|
+
import_koishi2.h.quote(messageId),
|
|
1613
|
+
import_koishi2.h.text(session.text(".mysqlError"))
|
|
1614
|
+
]);
|
|
1615
|
+
} else {
|
|
1616
|
+
throw new Error(error);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1555
1620
|
ctx.command("jm.queue").alias("本子队列").action(async ({ session, options }) => {
|
|
1556
1621
|
const messageId = session.messageId;
|
|
1557
1622
|
const allTasks = queue.getAllTasks();
|
package/package.json
CHANGED