koishi-plugin-booth-get 5.2.3 → 5.2.4
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 +74 -21
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -440,31 +440,70 @@ function apply(ctx, config) {
|
|
|
440
440
|
|
|
441
441
|
ctx.command("摊位名称 <query>")
|
|
442
442
|
.action(async ({ session }, query) => {
|
|
443
|
-
if (!query) return "
|
|
443
|
+
if (!query) return "请输入搜索关键词";
|
|
444
444
|
|
|
445
|
-
const tags = ['Vrchat'];
|
|
445
|
+
const tags = ['3Dモデル', 'Vrchat'];
|
|
446
446
|
const tagsParams = tags.map(tag => `tags[]=${encodeURIComponent(tag)}`).join('&');
|
|
447
|
-
const searchUrl = `https://booth.pm/zh-cn/search/${encodeURIComponent(query)}?${tagsParams}&min_price=
|
|
447
|
+
const searchUrl = `https://booth.pm/zh-cn/search/${encodeURIComponent(query)}?${tagsParams}&min_price=4500`;
|
|
448
448
|
|
|
449
449
|
const page = await ctx.puppeteer.page();
|
|
450
|
-
|
|
450
|
+
|
|
451
|
+
await page.setRequestInterception(true);
|
|
452
|
+
page.on('request', (request) => {
|
|
453
|
+
const resourceType = request.resourceType();
|
|
454
|
+
if (['image', 'stylesheet', 'font'].includes(resourceType)) {
|
|
455
|
+
request.abort();
|
|
456
|
+
} else {
|
|
457
|
+
request.continue();
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
|
|
451
461
|
try {
|
|
452
|
-
|
|
462
|
+
let retries = 3;
|
|
463
|
+
while (retries > 0) {
|
|
464
|
+
try {
|
|
465
|
+
await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout: ctx.config.loadTimeout || import_koishi.Time.second * 10 });
|
|
466
|
+
break;
|
|
467
|
+
} catch (error) {
|
|
468
|
+
retries--;
|
|
469
|
+
if (retries === 0) throw error;
|
|
470
|
+
logger.warn(`页面加载失败,重试中... (剩余重试次数: ${retries})`);
|
|
471
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
453
475
|
const content = await page.content();
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
476
|
+
const regex = /item-card__wrap"[\s\S]*?id="item_(\d+)"/;
|
|
477
|
+
const match = content.match(regex);
|
|
478
|
+
|
|
479
|
+
if (!match) {
|
|
480
|
+
if (content.includes('検索結果はありません') ||
|
|
481
|
+
content.includes('没有找到') ||
|
|
482
|
+
content.includes('検索条件に合致する作品は見つかりませんでした') ||
|
|
483
|
+
content.includes('該当する作品はありません')) {
|
|
484
|
+
return "没有找到相关商品";
|
|
485
|
+
}
|
|
486
|
+
return "没有找到相关商品";
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const itemId = match[1];
|
|
490
|
+
|
|
491
|
+
try {
|
|
492
|
+
const buffer = await captureCard(ctx, itemId);
|
|
493
|
+
if (!buffer) {
|
|
494
|
+
return "卡片生成失败";
|
|
495
|
+
}
|
|
496
|
+
return import_koishi.h.image(buffer, "image/png");
|
|
497
|
+
} catch (error) {
|
|
498
|
+
logger.error('卡片生成失败:', error);
|
|
499
|
+
return "卡片生成失败";
|
|
500
|
+
}
|
|
465
501
|
} catch (error) {
|
|
466
|
-
logger.error(
|
|
467
|
-
|
|
502
|
+
logger.error('搜索失败:', error);
|
|
503
|
+
if (error.message.includes('ERR_EMPTY_RESPONSE') || error.message.includes('net::ERR_CONNECTION_TIMED_OUT')) {
|
|
504
|
+
return "搜索失败,连接BOOTH网站超时,请稍后再试";
|
|
505
|
+
}
|
|
506
|
+
return "搜索失败";
|
|
468
507
|
} finally {
|
|
469
508
|
await page.close();
|
|
470
509
|
}
|
|
@@ -492,11 +531,25 @@ function apply(ctx, config) {
|
|
|
492
531
|
const match = session.content.match(boothUrlRegex);
|
|
493
532
|
|
|
494
533
|
if (match) {
|
|
534
|
+
if (session.onebot) {
|
|
535
|
+
session.onebot._sned = session.send;
|
|
536
|
+
session.send = function (...args) {
|
|
537
|
+
return this._sned.apply(this, args);
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const itemId = match[1];
|
|
495
542
|
try {
|
|
496
|
-
const buffer = await captureCard(ctx,
|
|
497
|
-
|
|
543
|
+
const buffer = await captureCard(ctx, itemId);
|
|
544
|
+
if (buffer) {
|
|
545
|
+
await session.send(import_koishi.h.image(buffer, "image/png"));
|
|
546
|
+
return;
|
|
547
|
+
} else {
|
|
548
|
+
return "商品解析失败";
|
|
549
|
+
}
|
|
498
550
|
} catch (error) {
|
|
499
|
-
logger.warn(error);
|
|
551
|
+
logger.warn("链接解析失败:", error);
|
|
552
|
+
return "商品解析失败";
|
|
500
553
|
}
|
|
501
554
|
}
|
|
502
555
|
return next();
|