koishi-plugin-codec-tools 1.0.8 → 1.0.9
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 +9 -13
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -59,16 +59,11 @@ function apply(ctx, config) {
|
|
|
59
59
|
ctx.command('decode-code')
|
|
60
60
|
.action(async ({ session }) => {
|
|
61
61
|
if (!session)
|
|
62
|
-
return;
|
|
63
|
-
const replyWithQuote = (content) => {
|
|
64
|
-
return session.send([
|
|
65
|
-
(0, koishi_1.h)('quote', { id: session.messageId }),
|
|
66
|
-
content
|
|
67
|
-
]);
|
|
68
|
-
};
|
|
62
|
+
return '';
|
|
69
63
|
const imageUrl = await extractImageFromSession(session);
|
|
70
|
-
if (!imageUrl)
|
|
71
|
-
return
|
|
64
|
+
if (!imageUrl) {
|
|
65
|
+
return session.send(session.text('.no-image'), { quote: session.messageId });
|
|
66
|
+
}
|
|
72
67
|
try {
|
|
73
68
|
const buffer = await ctx.http.get(imageUrl, { responseType: 'arraybuffer' });
|
|
74
69
|
const img = await jimp_1.default.read(Buffer.from(buffer));
|
|
@@ -82,8 +77,9 @@ function apply(ctx, config) {
|
|
|
82
77
|
height: img.bitmap.height
|
|
83
78
|
};
|
|
84
79
|
const qrResult = (0, jsqr_1.default)(imageData.data, imageData.width, imageData.height);
|
|
85
|
-
if (qrResult)
|
|
86
|
-
return
|
|
80
|
+
if (qrResult) {
|
|
81
|
+
return session.send(session.text('.qr-content', { content: qrResult.data }), { quote: session.messageId });
|
|
82
|
+
}
|
|
87
83
|
const hints = new Map();
|
|
88
84
|
hints.set(library_1.DecodeHintType.POSSIBLE_FORMATS, [
|
|
89
85
|
library_1.BarcodeFormat.QR_CODE, library_1.BarcodeFormat.CODE_128, library_1.BarcodeFormat.EAN_13,
|
|
@@ -94,11 +90,11 @@ function apply(ctx, config) {
|
|
|
94
90
|
const luminanceSource = new library_1.RGBLuminanceSource(imageData.data, imageData.width, imageData.height);
|
|
95
91
|
const binaryBitmap = new library_1.BinaryBitmap(new library_1.HybridBinarizer(luminanceSource));
|
|
96
92
|
const barcodeResult = reader.decode(binaryBitmap, hints);
|
|
97
|
-
return
|
|
93
|
+
return session.send(session.text('.barcode-content', { content: barcodeResult.text }), { quote: session.messageId });
|
|
98
94
|
}
|
|
99
95
|
catch (e) {
|
|
100
96
|
console.error('解析失败:', e);
|
|
101
|
-
return
|
|
97
|
+
return session.send(session.text('.no-code'), { quote: session.messageId });
|
|
102
98
|
}
|
|
103
99
|
});
|
|
104
100
|
}
|