koishi-plugin-booth-get 5.2.0 → 5.2.2
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/README.md +8 -1
- package/lib/index.js +17 -38
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
简单获取booth.pm页面的插件
|
|
1
|
+
简单获取booth.pm页面的插件
|
|
2
|
+
适用用于“vrchat”“MMD模型”“周边”“游戏”“Live2D”“视频”
|
|
3
|
+
在使用vrchat的搜索时由于booth.pm的特殊性《指令摊:位搜索》会以最新发布商品为第一检索
|
|
4
|
+
默认情况下,插件会自动获取最新发布商品,如需获取其他商品,请自行修改插件代码
|
|
5
|
+
============================================================
|
|
6
|
+
后续更新会以卡片样式web版进行更新
|
|
7
|
+
优化更好且简介的样式面板
|
|
8
|
+
============================================================
|
package/lib/index.js
CHANGED
|
@@ -31,10 +31,9 @@ var QRCode = require("qrcode");
|
|
|
31
31
|
var name = "booth-get";
|
|
32
32
|
var inject = ["puppeteer"];
|
|
33
33
|
var Config = import_koishi.Schema.object({
|
|
34
|
-
loadTimeout: import_koishi.Schema.natural().role("ms").description("加载页面的最长时间").default(import_koishi.Time.second *
|
|
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
|
-
proxyServer: import_koishi.Schema.string().description("代理服务器地址").default(""),
|
|
37
|
-
Text: import_koishi.Schema.title("摊位卡片生成器").description("生成BOOTH商品的摊位卡片,由VRCBBS提供"),
|
|
36
|
+
proxyServer: import_koishi.Schema.string().description("代理服务器地址").default("61.216.156.222:60808"),
|
|
38
37
|
|
|
39
38
|
}).description("booth-get");
|
|
40
39
|
|
|
@@ -403,10 +402,12 @@ async function captureCard(ctx, id) {
|
|
|
403
402
|
page.on('request', (request) => request.continue());
|
|
404
403
|
|
|
405
404
|
await page.setContent(html, {
|
|
406
|
-
waitUntil: '
|
|
407
|
-
timeout: ctx.config.loadTimeout
|
|
405
|
+
waitUntil: 'domcontentloaded',
|
|
406
|
+
timeout: ctx.config.loadTimeout || import_koishi.Time.second * 10
|
|
408
407
|
});
|
|
409
408
|
|
|
409
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
410
|
+
|
|
410
411
|
await page.setViewport({ width: 640, height: 1200 });
|
|
411
412
|
const container = await page.$('.container');
|
|
412
413
|
return await container.screenshot({
|
|
@@ -440,47 +441,25 @@ function apply(ctx, config) {
|
|
|
440
441
|
ctx.command("摊位名称 <query>")
|
|
441
442
|
.action(async ({ session }, query) => {
|
|
442
443
|
if (!query) return "请输入商品名称";
|
|
443
|
-
|
|
444
|
-
const
|
|
444
|
+
|
|
445
|
+
const tags = ['Vrchat'];
|
|
446
|
+
const tagsParams = tags.map(tag => `tags[]=${encodeURIComponent(tag)}`).join('&');
|
|
447
|
+
const searchUrl = `https://booth.pm/zh-cn/search/${encodeURIComponent(query)}?${tagsParams}&min_price=0&in_stock=true`;
|
|
448
|
+
|
|
445
449
|
const page = await ctx.puppeteer.page();
|
|
446
450
|
|
|
447
451
|
try {
|
|
448
|
-
await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout:
|
|
452
|
+
await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout: ctx.config.loadTimeout || import_koishi.Time.second * 10 });
|
|
449
453
|
const content = await page.content();
|
|
450
|
-
|
|
451
|
-
const itemRegex = /item-card__wrap"
|
|
454
|
+
|
|
455
|
+
const itemRegex = /item-card__wrap"[\s\S]*?id="item_(\d+)"/g;
|
|
452
456
|
const matches = [...content.matchAll(itemRegex)];
|
|
453
457
|
|
|
454
458
|
if (!matches.length) return "没有找到相关商品";
|
|
455
459
|
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}));
|
|
460
|
-
|
|
461
|
-
const exactMatches = items.filter(item => item.name === query);
|
|
462
|
-
if (exactMatches.length === 1) {
|
|
463
|
-
|
|
464
|
-
const buffer = await captureCard(ctx, exactMatches[0].id);
|
|
465
|
-
return buffer ? import_koishi.h.image(buffer, "image/png") : "卡片生成失败";
|
|
466
|
-
} else if (exactMatches.length > 1) {
|
|
467
|
-
|
|
468
|
-
const buffer = await captureCard(ctx, exactMatches[0].id);
|
|
469
|
-
return buffer ? import_koishi.h.image(buffer, "image/png") : "卡片生成失败";
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
const queryLower = query.toLowerCase();
|
|
473
|
-
const scoredItems = items.map(item => ({
|
|
474
|
-
...item,
|
|
475
|
-
score: getSimilarity(queryLower, item.name.toLowerCase())
|
|
476
|
-
})).sort((a, b) => b.score - a.score);
|
|
477
|
-
|
|
478
|
-
const bestMatch = scoredItems[0];
|
|
479
|
-
if (bestMatch.score < 0.3) {
|
|
480
|
-
return `没有找到完全匹配的商品,最接近的是:${bestMatch.name}`;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
const buffer = await captureCard(ctx, bestMatch.id);
|
|
460
|
+
const itemId = matches[0][1];
|
|
461
|
+
|
|
462
|
+
const buffer = await captureCard(ctx, itemId);
|
|
484
463
|
return buffer ? import_koishi.h.image(buffer, "image/png") : "卡片生成失败";
|
|
485
464
|
|
|
486
465
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-booth-get",
|
|
3
3
|
"description": "通过url与名称检查摊位物品并反馈用户搜索的图片",
|
|
4
|
-
"version": "5.2.
|
|
4
|
+
"version": "5.2.2",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"rixiang <1148147857@qq.com>"
|
|
7
7
|
],
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"koishi",
|
|
28
28
|
"plugin",
|
|
29
29
|
"booth",
|
|
30
|
-
"pngjs"
|
|
30
|
+
"pngjs",
|
|
31
|
+
"puppeteer",
|
|
32
|
+
"qrcode"
|
|
31
33
|
],
|
|
32
34
|
"peerDependencies": {
|
|
33
35
|
"koishi": "4.18.9"
|