koishi-plugin-codec-tools 1.0.3 → 1.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 +17 -18
- package/lib/locales/zh-CN.yml +22 -0
- package/package.json +21 -7
- package/src/locales/zh-CN.yml +22 -0
package/lib/index.js
CHANGED
|
@@ -9,33 +9,32 @@ const koishi_1 = require("koishi");
|
|
|
9
9
|
const jimp_1 = __importDefault(require("jimp"));
|
|
10
10
|
const jsqr_1 = __importDefault(require("jsqr"));
|
|
11
11
|
const library_1 = require("@zxing/library");
|
|
12
|
+
const zh_CN_yml_1 = __importDefault(require("./locales/zh-CN.yml"));
|
|
12
13
|
exports.name = 'codec-tools';
|
|
13
14
|
exports.using = ['i18n'];
|
|
14
|
-
exports.Config = koishi_1.Schema.object({})
|
|
15
|
+
exports.Config = koishi_1.Schema.object({})
|
|
16
|
+
.i18n({
|
|
17
|
+
'zh-CN': zh_CN_yml_1.default._config,
|
|
18
|
+
});
|
|
15
19
|
function apply(ctx, config) {
|
|
16
|
-
ctx.i18n.define('zh-CN',
|
|
17
|
-
|
|
18
|
-
'codec-tools.no-code': '未识别到二维码或条形码',
|
|
19
|
-
'codec-tools.qr-content': '二维码内容:{content}',
|
|
20
|
-
'codec-tools.barcode-content': '条形码内容:{content}',
|
|
21
|
-
});
|
|
22
|
-
ctx.command('url-encode <text:text>', 'URL 编码 - 对文本进行 URL 编码')
|
|
20
|
+
ctx.i18n.define('zh-CN', zh_CN_yml_1.default);
|
|
21
|
+
ctx.command('url-encode <text:text>')
|
|
23
22
|
.action((_, text) => encodeURIComponent(text));
|
|
24
|
-
ctx.command('url-decode <text:text>'
|
|
23
|
+
ctx.command('url-decode <text:text>')
|
|
25
24
|
.action((_, text) => decodeURIComponent(text));
|
|
26
|
-
ctx.command('base64-encode <text:text>'
|
|
25
|
+
ctx.command('base64-encode <text:text>')
|
|
27
26
|
.action((_, text) => Buffer.from(text).toString('base64'));
|
|
28
|
-
ctx.command('base64-decode <text:text>'
|
|
27
|
+
ctx.command('base64-decode <text:text>')
|
|
29
28
|
.action((_, text) => Buffer.from(text, 'base64').toString());
|
|
30
|
-
ctx.command('unicode-encode <text:text>'
|
|
29
|
+
ctx.command('unicode-encode <text:text>')
|
|
31
30
|
.action((_, text) => text.split('').map(c => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0')).join(''));
|
|
32
|
-
ctx.command('unicode-decode <text:text>'
|
|
31
|
+
ctx.command('unicode-decode <text:text>')
|
|
33
32
|
.action((_, text) => text.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))));
|
|
34
|
-
ctx.command('decode-code'
|
|
33
|
+
ctx.command('decode-code')
|
|
35
34
|
.action(async ({ session }) => {
|
|
36
35
|
const image = session?.elements.find(el => el.type === 'image');
|
|
37
36
|
if (!image)
|
|
38
|
-
return session.text('
|
|
37
|
+
return session.text('.no-image');
|
|
39
38
|
const url = image.attrs.src;
|
|
40
39
|
const buffer = await ctx.http.get(url, { responseType: 'arraybuffer' });
|
|
41
40
|
const img = await jimp_1.default.read(Buffer.from(buffer));
|
|
@@ -46,7 +45,7 @@ function apply(ctx, config) {
|
|
|
46
45
|
};
|
|
47
46
|
const qrResult = (0, jsqr_1.default)(imageData.data, imageData.width, imageData.height);
|
|
48
47
|
if (qrResult)
|
|
49
|
-
return session.text('
|
|
48
|
+
return session.text('.qr-content', { content: qrResult.data });
|
|
50
49
|
const hints = new Map();
|
|
51
50
|
hints.set(library_1.DecodeHintType.POSSIBLE_FORMATS, [
|
|
52
51
|
library_1.BarcodeFormat.QR_CODE, library_1.BarcodeFormat.CODE_128, library_1.BarcodeFormat.EAN_13,
|
|
@@ -58,10 +57,10 @@ function apply(ctx, config) {
|
|
|
58
57
|
const luminanceSource = new library_1.RGBLuminanceSource(imageData.data, imageData.width, imageData.height);
|
|
59
58
|
const binaryBitmap = new library_1.BinaryBitmap(new library_1.HybridBinarizer(luminanceSource));
|
|
60
59
|
const barcodeResult = reader.decode(binaryBitmap, hints);
|
|
61
|
-
return session.text('
|
|
60
|
+
return session.text('.barcode-content', { content: barcodeResult.text });
|
|
62
61
|
}
|
|
63
62
|
catch (e) {
|
|
64
|
-
return session.text('
|
|
63
|
+
return session.text('.no-code');
|
|
65
64
|
}
|
|
66
65
|
});
|
|
67
66
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
url-encode:
|
|
3
|
+
description: URL 编码
|
|
4
|
+
url-decode:
|
|
5
|
+
description: URL 解码
|
|
6
|
+
base64-encode:
|
|
7
|
+
description: Base64 编码
|
|
8
|
+
base64-decode:
|
|
9
|
+
description: Base64 解码
|
|
10
|
+
unicode-encode:
|
|
11
|
+
description: Unicode 编码
|
|
12
|
+
unicode-decode:
|
|
13
|
+
description: Unicode 解码
|
|
14
|
+
decode-code:
|
|
15
|
+
description: 识别二维码/条形码
|
|
16
|
+
messages:
|
|
17
|
+
no-image: 请发送包含图片的消息
|
|
18
|
+
no-code: 未识别到二维码或条形码
|
|
19
|
+
qr-content: 二维码内容:{content}
|
|
20
|
+
barcode-content: 条形码内容:{content}
|
|
21
|
+
|
|
22
|
+
_config: {}
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-codec-tools",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "1.0.
|
|
3
|
+
"description": "编码&解码 URL/Base64/Unicode 和条形码/二维码的 Koishi 插件",
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib",
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"src/locales"
|
|
10
11
|
],
|
|
11
12
|
"license": "MIT",
|
|
12
13
|
"scripts": {
|
|
13
|
-
"build": "tsc -b"
|
|
14
|
+
"build": "tsc -b && copyfiles -u 1 src/locales/**/* lib/",
|
|
15
|
+
"clean": "tsc -b --clean"
|
|
14
16
|
},
|
|
15
17
|
"keywords": [
|
|
16
18
|
"chatbot",
|
|
@@ -21,7 +23,9 @@
|
|
|
21
23
|
"base64",
|
|
22
24
|
"unicode",
|
|
23
25
|
"qrcode",
|
|
24
|
-
"barcode"
|
|
26
|
+
"barcode",
|
|
27
|
+
"i18n",
|
|
28
|
+
"本地化"
|
|
25
29
|
],
|
|
26
30
|
"repository": {
|
|
27
31
|
"type": "git",
|
|
@@ -32,14 +36,24 @@
|
|
|
32
36
|
},
|
|
33
37
|
"homepage": "https://github.com/Minecraft-1314/koishi-plugin-codec-tools#readme",
|
|
34
38
|
"devDependencies": {
|
|
39
|
+
"copyfiles": "^2.4.1",
|
|
35
40
|
"typescript": "^5.3.3"
|
|
36
41
|
},
|
|
37
42
|
"dependencies": {
|
|
38
43
|
"@zxing/library": "^0.21.3",
|
|
39
44
|
"jimp": "^0.16.13",
|
|
40
|
-
"jsqr": "^1.4.0"
|
|
45
|
+
"jsqr": "^1.4.0",
|
|
46
|
+
"yaml": "^2.3.4"
|
|
41
47
|
},
|
|
42
48
|
"peerDependencies": {
|
|
43
49
|
"koishi": "^4.18.7"
|
|
50
|
+
},
|
|
51
|
+
"koishi": {
|
|
52
|
+
"service": {
|
|
53
|
+
"required": [
|
|
54
|
+
"i18n"
|
|
55
|
+
],
|
|
56
|
+
"optional": []
|
|
57
|
+
}
|
|
44
58
|
}
|
|
45
|
-
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
url-encode:
|
|
3
|
+
description: URL 编码
|
|
4
|
+
url-decode:
|
|
5
|
+
description: URL 解码
|
|
6
|
+
base64-encode:
|
|
7
|
+
description: Base64 编码
|
|
8
|
+
base64-decode:
|
|
9
|
+
description: Base64 解码
|
|
10
|
+
unicode-encode:
|
|
11
|
+
description: Unicode 编码
|
|
12
|
+
unicode-decode:
|
|
13
|
+
description: Unicode 解码
|
|
14
|
+
decode-code:
|
|
15
|
+
description: 识别二维码/条形码
|
|
16
|
+
messages:
|
|
17
|
+
no-image: 请发送包含图片的消息
|
|
18
|
+
no-code: 未识别到二维码或条形码
|
|
19
|
+
qr-content: 二维码内容:{content}
|
|
20
|
+
barcode-content: 条形码内容:{content}
|
|
21
|
+
|
|
22
|
+
_config: {}
|