koishi-plugin-booth-get 5.2.6 → 5.2.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.js +59 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -34,9 +34,40 @@ var Config = import_koishi.Schema.object({
|
|
|
34
34
|
loadTimeout: import_koishi.Schema.natural().role("ms").description("加载页面的最长时间").default(import_koishi.Time.second * 10),
|
|
35
35
|
idleTimeout: import_koishi.Schema.natural().role("ms").description("等待页面空闲的最长时间").default(import_koishi.Time.second * 30),
|
|
36
36
|
proxyServer: import_koishi.Schema.string().description("代理服务器地址").default("61.216.156.222:60808"),
|
|
37
|
+
enableR18Check: import_koishi.Schema.boolean().description("启用R18内容检测").default(true),
|
|
38
|
+
r18Tags: import_koishi.Schema.array(import_koishi.Schema.string()).description("R18标签").default(["r18", "18禁", "R-18", "R18+", "R-18+", "R18G", "R-18G", "R18G+", "R-18G+", "R18G++", "R-18G++", "R18G+++", "R-18G+++", "R18G++++", "R-18G++++",])
|
|
37
39
|
|
|
38
40
|
}).description("booth-get");
|
|
39
41
|
|
|
42
|
+
function checkR18(item, config) {
|
|
43
|
+
if (!config.enableR18Check) return false;
|
|
44
|
+
|
|
45
|
+
if (item.tags && Array.isArray(item.tags)) {
|
|
46
|
+
const hasR18Tag = item.tags.some(tag =>
|
|
47
|
+
config.r18Tags.some(r18Tag =>
|
|
48
|
+
tag.name && tag.name.toLowerCase().includes(r18Tag.toLowerCase())
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
if (hasR18Tag) return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (item.title) {
|
|
55
|
+
const hasR18InTitle = config.r18Tags.some(r18Tag =>
|
|
56
|
+
item.title.toLowerCase().includes(r18Tag.toLowerCase())
|
|
57
|
+
);
|
|
58
|
+
if (hasR18InTitle) return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (item.description) {
|
|
62
|
+
const hasR18InDesc = config.r18Tags.some(r18Tag =>
|
|
63
|
+
item.description.toLowerCase().includes(r18Tag.toLowerCase())
|
|
64
|
+
);
|
|
65
|
+
if (hasR18InDesc) return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
40
71
|
function generateCardHTML(item, relatedItems = []) {
|
|
41
72
|
return `
|
|
42
73
|
<html>
|
|
@@ -387,11 +418,17 @@ async function fetchRelatedItems(author) {
|
|
|
387
418
|
}
|
|
388
419
|
}
|
|
389
420
|
|
|
390
|
-
async function captureCard(ctx, id) {
|
|
421
|
+
async function captureCard(ctx, id, config) {
|
|
391
422
|
const logger = ctx.logger("booth-get");
|
|
392
423
|
const item = await getBoothItem(id);
|
|
393
424
|
if (!item) return null;
|
|
394
425
|
|
|
426
|
+
// R18内容检测
|
|
427
|
+
if (checkR18(item, config)) {
|
|
428
|
+
logger.warn(`检测到R18内容,已跳过商品: ${id}`);
|
|
429
|
+
return "R18_CONTENT";
|
|
430
|
+
}
|
|
431
|
+
|
|
395
432
|
const relatedItems = await fetchRelatedItems(item.author);
|
|
396
433
|
|
|
397
434
|
const html = generateCardHTML(item, relatedItems);
|
|
@@ -403,7 +440,7 @@ async function captureCard(ctx, id) {
|
|
|
403
440
|
|
|
404
441
|
await page.setContent(html, {
|
|
405
442
|
waitUntil: 'domcontentloaded',
|
|
406
|
-
timeout:
|
|
443
|
+
timeout: config.loadTimeout || import_koishi.Time.second * 10
|
|
407
444
|
});
|
|
408
445
|
|
|
409
446
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
@@ -430,7 +467,8 @@ function apply(ctx, config) {
|
|
|
430
467
|
.action(async ({ session }, id) => {
|
|
431
468
|
if (!id) return "请输入商品ID";
|
|
432
469
|
try {
|
|
433
|
-
const buffer = await captureCard(ctx, id);
|
|
470
|
+
const buffer = await captureCard(ctx, id, config);
|
|
471
|
+
if (buffer === "R18_CONTENT") return "该商品可能包含R18内容,已跳过";
|
|
434
472
|
return buffer ? import_koishi.h.image(buffer, "image/png") : "商品获取失败";
|
|
435
473
|
} catch (error) {
|
|
436
474
|
logger.warn(error);
|
|
@@ -476,7 +514,7 @@ function apply(ctx, config) {
|
|
|
476
514
|
let retries = 3;
|
|
477
515
|
while (retries > 0) {
|
|
478
516
|
try {
|
|
479
|
-
await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout:
|
|
517
|
+
await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout: config.loadTimeout || import_koishi.Time.second * 10 });
|
|
480
518
|
break;
|
|
481
519
|
} catch (error) {
|
|
482
520
|
retries--;
|
|
@@ -543,7 +581,10 @@ function apply(ctx, config) {
|
|
|
543
581
|
}
|
|
544
582
|
|
|
545
583
|
try {
|
|
546
|
-
const buffer = await captureCard(ctx, selectedItemId);
|
|
584
|
+
const buffer = await captureCard(ctx, selectedItemId, config);
|
|
585
|
+
if (buffer === "R18_CONTENT") {
|
|
586
|
+
return "搜索到的商品可能包含R18内容,已跳过";
|
|
587
|
+
}
|
|
547
588
|
if (!buffer) {
|
|
548
589
|
return "卡片生成失败";
|
|
549
590
|
}
|
|
@@ -597,7 +638,7 @@ async function fetchAuthorItems(ctx, authorName, limit = 6) {
|
|
|
597
638
|
|
|
598
639
|
await page.goto(`https://${authorName}.booth.pm/items`, {
|
|
599
640
|
waitUntil: 'networkidle0',
|
|
600
|
-
timeout:
|
|
641
|
+
timeout: config.loadTimeout || import_koishi.Time.second * 10
|
|
601
642
|
});
|
|
602
643
|
await page.waitForSelector('.item-list', { timeout: 5000 });
|
|
603
644
|
|
|
@@ -868,7 +909,7 @@ async function captureAuthorShopCard(ctx, authorName) {
|
|
|
868
909
|
|
|
869
910
|
await page.setContent(html, {
|
|
870
911
|
waitUntil: 'domcontentloaded',
|
|
871
|
-
timeout:
|
|
912
|
+
timeout: config.loadTimeout || import_koishi.Time.second * 10
|
|
872
913
|
});
|
|
873
914
|
|
|
874
915
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
@@ -896,7 +937,11 @@ async function captureAuthorShopCard(ctx, authorName) {
|
|
|
896
937
|
if (match) {
|
|
897
938
|
const itemId = match[1];
|
|
898
939
|
try {
|
|
899
|
-
const buffer = await captureCard(ctx, itemId);
|
|
940
|
+
const buffer = await captureCard(ctx, itemId, config);
|
|
941
|
+
if (buffer === "R18_CONTENT") {
|
|
942
|
+
await session.send("该商品可能包含R18内容,已跳过");
|
|
943
|
+
return "";
|
|
944
|
+
}
|
|
900
945
|
if (buffer) {
|
|
901
946
|
await session.send(import_koishi.h.image(buffer, "image/png"));
|
|
902
947
|
return "";
|
|
@@ -913,7 +958,11 @@ async function captureAuthorShopCard(ctx, authorName) {
|
|
|
913
958
|
|
|
914
959
|
try {
|
|
915
960
|
if (itemId) {
|
|
916
|
-
const buffer = await captureCard(ctx, itemId);
|
|
961
|
+
const buffer = await captureCard(ctx, itemId, config);
|
|
962
|
+
if (buffer === "R18_CONTENT") {
|
|
963
|
+
await session.send("该商品可能包含R18内容,已跳过");
|
|
964
|
+
return "";
|
|
965
|
+
}
|
|
917
966
|
if (buffer) {
|
|
918
967
|
await session.send(import_koishi.h.image(buffer, "image/png"));
|
|
919
968
|
return "";
|
|
@@ -956,7 +1005,7 @@ async function captureAuthorShopCard(ctx, authorName) {
|
|
|
956
1005
|
});
|
|
957
1006
|
|
|
958
1007
|
try {
|
|
959
|
-
await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout:
|
|
1008
|
+
await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout: config.loadTimeout || import_koishi.Time.second * 10 });
|
|
960
1009
|
|
|
961
1010
|
const content = await page.content();
|
|
962
1011
|
|