koishi-plugin-booth-get 5.2.2 → 5.2.3

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.
Files changed (2) hide show
  1. package/lib/index.js +20 -20
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -347,7 +347,7 @@ async function getBoothItem(id) {
347
347
  fetch(`https://booth.pm/zh-cn/items/${id}.json`),
348
348
  fetch(`https://accounts.booth.pm/wish_lists.json?item_ids%5B%5D=${id}`)
349
349
  ]);
350
-
350
+
351
351
  const itemData = await itemRes.json();
352
352
  const wishData = await wishRes.json();
353
353
 
@@ -360,7 +360,7 @@ async function getBoothItem(id) {
360
360
  category: itemData.category?.name,
361
361
  parent_category: itemData.category?.parent?.name,
362
362
  author: itemData.shop?.name,
363
- author_thumbnail_url: itemData.shop?.icon?.thumb?.original || itemData.shop?.icon?.small?.original,
363
+ author_thumbnail_url: itemData.shop?.thumbnail_url,
364
364
  likes: wishData.wishlists_counts[id] || 0,
365
365
  tags: itemData.tags
366
366
  };
@@ -393,21 +393,21 @@ async function captureCard(ctx, id) {
393
393
  if (!item) return null;
394
394
 
395
395
  const relatedItems = await fetchRelatedItems(item.author);
396
-
396
+
397
397
  const html = generateCardHTML(item, relatedItems);
398
398
 
399
399
  const page = await ctx.puppeteer.page();
400
400
  try {
401
401
  await page.setRequestInterception(true);
402
402
  page.on('request', (request) => request.continue());
403
-
404
- await page.setContent(html, {
403
+
404
+ await page.setContent(html, {
405
405
  waitUntil: 'domcontentloaded',
406
406
  timeout: ctx.config.loadTimeout || import_koishi.Time.second * 10
407
407
  });
408
-
408
+
409
409
  await new Promise(resolve => setTimeout(resolve, 2000));
410
-
410
+
411
411
  await page.setViewport({ width: 640, height: 1200 });
412
412
  const container = await page.$('.container');
413
413
  return await container.screenshot({
@@ -438,30 +438,30 @@ function apply(ctx, config) {
438
438
  }
439
439
  });
440
440
 
441
- ctx.command("摊位名称 <query>")
441
+ ctx.command("摊位名称 <query>")
442
442
  .action(async ({ session }, query) => {
443
443
  if (!query) return "请输入商品名称";
444
444
 
445
445
  const tags = ['Vrchat'];
446
446
  const tagsParams = tags.map(tag => `tags[]=${encodeURIComponent(tag)}`).join('&');
447
447
  const searchUrl = `https://booth.pm/zh-cn/search/${encodeURIComponent(query)}?${tagsParams}&min_price=0&in_stock=true`;
448
-
448
+
449
449
  const page = await ctx.puppeteer.page();
450
-
450
+
451
451
  try {
452
452
  await page.goto(searchUrl, { waitUntil: 'networkidle0', timeout: ctx.config.loadTimeout || import_koishi.Time.second * 10 });
453
453
  const content = await page.content();
454
-
454
+
455
455
  const itemRegex = /item-card__wrap"[\s\S]*?id="item_(\d+)"/g;
456
456
  const matches = [...content.matchAll(itemRegex)];
457
-
457
+
458
458
  if (!matches.length) return "没有找到相关商品";
459
-
459
+
460
460
  const itemId = matches[0][1];
461
-
461
+
462
462
  const buffer = await captureCard(ctx, itemId);
463
463
  return buffer ? import_koishi.h.image(buffer, "image/png") : "卡片生成失败";
464
-
464
+
465
465
  } catch (error) {
466
466
  logger.error("搜索失败:", error);
467
467
  return "搜索失败,请检查商品名称或稍后再试";
@@ -469,28 +469,28 @@ function apply(ctx, config) {
469
469
  await page.close();
470
470
  }
471
471
  });
472
-
472
+
473
473
  function getSimilarity(a, b) {
474
474
  if (a === b) return 1;
475
475
  if (a.length < 2 || b.length < 2) return 0;
476
-
476
+
477
477
  const bigramsA = new Set();
478
478
  for (let i = 0; i < a.length - 1; i++) {
479
479
  bigramsA.add(a.substring(i, i + 2));
480
480
  }
481
-
481
+
482
482
  let matches = 0;
483
483
  for (let i = 0; i < b.length - 1; i++) {
484
484
  if (bigramsA.has(b.substring(i, i + 2))) matches++;
485
485
  }
486
-
486
+
487
487
  return (2 * matches) / (a.length + b.length - 2);
488
488
  }
489
489
 
490
490
  ctx.middleware(async (session, next) => {
491
491
  const boothUrlRegex = /https:\/\/booth.pm\/[\w-]+\/items\/(\d+)/;
492
492
  const match = session.content.match(boothUrlRegex);
493
-
493
+
494
494
  if (match) {
495
495
  try {
496
496
  const buffer = await captureCard(ctx, match[1]);
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.2",
4
+ "version": "5.2.3",
5
5
  "contributors": [
6
6
  "rixiang <1148147857@qq.com>"
7
7
  ],