koishi-plugin-codec-tools 1.0.6 → 1.0.7

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 CHANGED
@@ -37,9 +37,17 @@ function apply(ctx, config) {
37
37
  .action((_, text) => text.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))));
38
38
  ctx.command('decode-code')
39
39
  .action(async ({ session }) => {
40
- const image = session?.elements.find(el => el.type === 'image');
40
+ if (!session)
41
+ return;
42
+ const image = session.elements.find(el => el.type === 'image');
43
+ const replyWithQuote = (content) => {
44
+ return session.send([
45
+ (0, koishi_1.h)('quote', { id: session.messageId }),
46
+ content
47
+ ]);
48
+ };
41
49
  if (!image)
42
- return session.text('.no-image');
50
+ return replyWithQuote(session.text('.no-image'));
43
51
  const url = image.attrs.src;
44
52
  const buffer = await ctx.http.get(url, { responseType: 'arraybuffer' });
45
53
  const img = await jimp_1.default.read(Buffer.from(buffer));
@@ -50,7 +58,7 @@ function apply(ctx, config) {
50
58
  };
51
59
  const qrResult = (0, jsqr_1.default)(imageData.data, imageData.width, imageData.height);
52
60
  if (qrResult)
53
- return session.text('.qr-content', { content: qrResult.data });
61
+ return replyWithQuote(session.text('.qr-content', { content: qrResult.data }));
54
62
  const hints = new Map();
55
63
  hints.set(library_1.DecodeHintType.POSSIBLE_FORMATS, [
56
64
  library_1.BarcodeFormat.QR_CODE, library_1.BarcodeFormat.CODE_128, library_1.BarcodeFormat.EAN_13,
@@ -62,10 +70,10 @@ function apply(ctx, config) {
62
70
  const luminanceSource = new library_1.RGBLuminanceSource(imageData.data, imageData.width, imageData.height);
63
71
  const binaryBitmap = new library_1.BinaryBitmap(new library_1.HybridBinarizer(luminanceSource));
64
72
  const barcodeResult = reader.decode(binaryBitmap, hints);
65
- return session.text('.barcode-content', { content: barcodeResult.text });
73
+ return replyWithQuote(session.text('.barcode-content', { content: barcodeResult.text }));
66
74
  }
67
75
  catch (e) {
68
- return session.text('.no-code');
76
+ return replyWithQuote(session.text('.no-code'));
69
77
  }
70
78
  });
71
79
  }
@@ -14,9 +14,9 @@ commands:
14
14
  decode-code:
15
15
  description: 识别二维码/条形码
16
16
  messages:
17
- no-image: 请发送包含图片的消息
18
- no-code: 未识别到二维码或条形码
19
- qr-content: 二维码内容:{content}
20
- barcode-content: 条形码内容:{content}
17
+ no-image: 未找到图片!请发送图片或引用包含图片的消息后重试。
18
+ qr-content: 二维码内容:{{content}}
19
+ barcode-content: 条形码内容:{{content}}
20
+ no-code: 未识别到二维码/条形码!
21
21
 
22
22
  _config: {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-codec-tools",
3
3
  "description": "编码&解码 URL/Base64/Unicode 和条形码/二维码的 Koishi 插件",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -14,9 +14,9 @@ commands:
14
14
  decode-code:
15
15
  description: 识别二维码/条形码
16
16
  messages:
17
- no-image: 请发送包含图片的消息
18
- no-code: 未识别到二维码或条形码
19
- qr-content: 二维码内容:{content}
20
- barcode-content: 条形码内容:{content}
17
+ no-image: 未找到图片!请发送图片或引用包含图片的消息后重试。
18
+ qr-content: 二维码内容:{{content}}
19
+ barcode-content: 条形码内容:{{content}}
20
+ no-code: 未识别到二维码/条形码!
21
21
 
22
22
  _config: {}