koishi-plugin-booth-get 0.0.3 → 0.0.5
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 +32 -2
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -17,7 +17,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/index.ts
|
|
21
20
|
var src_exports = {};
|
|
22
21
|
__export(src_exports, {
|
|
23
22
|
Config: () => Config,
|
|
@@ -141,9 +140,40 @@ ctx.command("摊位名称 <query>").action(async ({ session }, query) => {
|
|
|
141
140
|
await page.close();
|
|
142
141
|
}
|
|
143
142
|
});
|
|
143
|
+
async function captureBoothPage(url) {
|
|
144
|
+
const page = await ctx.puppeteer.page();
|
|
145
|
+
try {
|
|
146
|
+
await page.goto(url, { waitUntil: 'networkidle0' });
|
|
147
|
+
const shooter = await page.$('div.u-pt-600');
|
|
148
|
+
if (!shooter) {
|
|
149
|
+
throw new Error("找不到满足该选择器的元素。");
|
|
150
|
+
}
|
|
151
|
+
const buffer = await shooter.screenshot();
|
|
152
|
+
return import_koishi.h.image(buffer, "image/png");
|
|
153
|
+
} catch (error) {
|
|
154
|
+
throw error;
|
|
155
|
+
} finally {
|
|
156
|
+
await page.close();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
ctx.middleware((session, next) => {
|
|
160
|
+
const message = session.content;
|
|
161
|
+
const boothUrlRegex = /https:\/\/booth.pm\/[\w-]+\/items\/\d+/;
|
|
162
|
+
|
|
163
|
+
if (boothUrlRegex.test(message)) {
|
|
164
|
+
const boothUrl = message.match(boothUrlRegex)[0];
|
|
165
|
+
return captureBoothPage(boothUrl).then(image => {
|
|
166
|
+
return session.send(image);
|
|
167
|
+
}).catch(error => {
|
|
168
|
+
ctx.logger.debug(error);
|
|
169
|
+
return session.send("无法获取页面截图。");
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return next();
|
|
174
|
+
});
|
|
144
175
|
}
|
|
145
176
|
__name(apply, "apply");
|
|
146
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
147
177
|
0 && (module.exports = {
|
|
148
178
|
Config,
|
|
149
179
|
apply,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-booth-get",
|
|
3
3
|
"description": "通过url与名称检查摊位物品并反馈用户搜索的图片",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"rixiang <1148147857@qq.com>"
|
|
7
7
|
],
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"booth"
|
|
30
30
|
],
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"koishi": "4.17.
|
|
32
|
+
"koishi": "4.17.12"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"atsc": "^2.1.0",
|