koishi-plugin-booth-get 2.0.0 → 3.1.0

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 (3) hide show
  1. package/README.md +16 -1
  2. package/lib/index.js +52 -1
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -8,4 +8,19 @@
8
8
 
9
9
  内容展示:
10
10
 
11
- https://www.freeimg.cn/i/2024/09/01/66d47ad049577.png
11
+ https://www.freeimg.cn/i/2024/09/01/66d47ad049577.png
12
+
13
+ 更新内容:
14
+
15
+ 2.0.0版本更新自定义代理
16
+
17
+ 3.0.0版本更新ws服务(目前还在测试阶段,预测5.0.0版本与大家见面)
18
+
19
+
20
+ 感谢大家的喜欢与支持
21
+
22
+ 最后更新预测6.0.0版本,本版本将优化反馈图片
23
+
24
+ 图片预览
25
+
26
+ https://www.freeimg.cn/i/2024/09/15/66e626ea2f552.webp
package/lib/index.js CHANGED
@@ -33,6 +33,8 @@ var Config = import_koishi.Schema.object({
33
33
  loadTimeout: import_koishi.Schema.natural().role("ms").description("加载页面的最长时间。当一个页面等待时间超过这个值时,如果此页面主体已经加载完成,则会发送一条提示消息“正在加载中,请稍等片刻”并继续等待加载;否则会直接提示“无法打开页面”并终止加载。").default(import_koishi.Time.second * 5),
34
34
  idleTimeout: import_koishi.Schema.natural().role("ms").description("等待页面空闲的最长时间。当一个页面等待时间超过这个值时,将停止进一步的加载并立即发送截图。").default(import_koishi.Time.second * 30),
35
35
  proxyServer: import_koishi.Schema.string().description("自定义代理服务器地址。例如:http://127.0.0.1:1080").default(""),
36
+ wsServer: import_koishi.Schema.string().description("WebSocket服务器地址。").default(""),
37
+ enableWs: import_koishi.Schema.boolean().description("是否启用WebSocket连接。").default(false),
36
38
  }).description("booth-get");
37
39
  function apply(ctx, config) {
38
40
  const logger = ctx.logger("screenshot");
@@ -41,6 +43,28 @@ function apply(ctx, config) {
41
43
  const booth_url = "https://booth.pm/zh-cn/items/";
42
44
  const maxSize = 1024 * 1024;
43
45
  const launchOptions = { ...ctx.puppeteer.config.launchOptions };
46
+
47
+ if (config.enableWs && config.wsServer) {
48
+ const WebSocket = require('ws');
49
+ let wsUrl = config.wsServer;
50
+ if (!wsUrl.startsWith('ws://') && !wsUrl.startsWith('wss://')) {
51
+ wsUrl = 'ws://' + wsUrl;
52
+ }
53
+ const ws = new WebSocket(wsUrl);
54
+ ws.on('open', function open() {
55
+ console.log('Connected to WebSocket server');
56
+ ws.send('Hello, server!');
57
+ });
58
+ ws.on('message', function incoming(data) {
59
+ console.log('Received message:', data);
60
+ });
61
+ ws.on('error', function handleErrors(error) {
62
+ console.error('WebSocket error:', error);
63
+ });
64
+ ws.on('close', function close() {
65
+ console.log('Disconnected from WebSocket server');
66
+ });
67
+ }
44
68
 
45
69
  if (proxyServer) {
46
70
  launchOptions.args = launchOptions.args || [];
@@ -103,6 +127,7 @@ function apply(ctx, config) {
103
127
  return "截图失败。";
104
128
  }).finally(() => page.close());
105
129
  });
130
+
106
131
  ctx.command("摊位名称 <query>").action(async ({ session }, query) => {
107
132
  if (!query)
108
133
  return "请输入搜索关键词";
@@ -179,6 +204,23 @@ ctx.middleware((session, next) => {
179
204
 
180
205
  return next();
181
206
  });
207
+ function sendItemImage(itemId) {
208
+ fetch(`http://127.0.0.1:8080/generate_image/${itemId}`)
209
+ .then(response => {
210
+ if (response.ok) {
211
+ return response.blob();
212
+ } else {
213
+ throw new Error('Image generation failed');
214
+ }
215
+ })
216
+ .then(blob => {
217
+ const imageUrl = URL.createObjectURL(blob);
218
+ console.log(imageUrl);
219
+ })
220
+ .catch(error => {
221
+ console.error(error);
222
+ });
223
+ }
182
224
  }
183
225
  __name(apply, "apply");
184
226
  0 && (module.exports = {
@@ -186,4 +228,13 @@ __name(apply, "apply");
186
228
  apply,
187
229
  inject,
188
230
  name
189
- });
231
+ });
232
+ async function triggerImageGeneration() {
233
+ try {
234
+ const response = await fetch('http://localhost:8000/generate');
235
+ const data = await response.json();
236
+ console.log(data.message); // Log the response from the server
237
+ } catch (error) {
238
+ console.error('Error calling the API:', error);
239
+ }
240
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-booth-get",
3
3
  "description": "通过url与名称检查摊位物品并反馈用户搜索的图片",
4
- "version": "2.0.0",
4
+ "version": "3.1.0",
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.12"
32
+ "koishi": "4.18.4"
33
33
  },
34
34
  "dependencies": {
35
35
  "atsc": "^2.1.0",