koishi-plugin-eula-regen 1.0.2 → 1.0.4
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 +27 -11
- package/package.json +5 -2
package/lib/index.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// 动态导入 ES Module - 使用 Promise 缓存
|
|
4
3
|
let jsx_runtime_1_promise = import("@satorijs/element/jsx-runtime");
|
|
5
4
|
let jsx_runtime_1;
|
|
6
|
-
// 立即开始加载,并在加载完成后缓存
|
|
7
5
|
jsx_runtime_1_promise.then(mod => {
|
|
8
|
-
jsx_runtime_1 = mod;
|
|
6
|
+
jsx_runtime_1 = mod.default || mod;
|
|
9
7
|
});
|
|
8
|
+
|
|
9
|
+
|
|
10
10
|
const koishi_1 = require("koishi");
|
|
11
|
-
const
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
12
|
const path_1 = require("path");
|
|
13
|
-
//
|
|
13
|
+
// 获取当前文件所在目录
|
|
14
14
|
// @ts-ignore - __filename 和 __dirname 在运行时可用
|
|
15
|
-
const
|
|
15
|
+
const getDirname = () => {
|
|
16
|
+
if (typeof __dirname !== 'undefined') {
|
|
17
|
+
return __dirname;
|
|
18
|
+
}
|
|
19
|
+
else if (typeof __filename !== 'undefined') {
|
|
20
|
+
return (0, path_1.dirname)(__filename);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// 回退到当前工作目录
|
|
24
|
+
return process.cwd();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const localesDir = (0, path_1.join)(getDirname(), 'locales');
|
|
16
28
|
class Eula extends koishi_1.Service {
|
|
17
29
|
constructor(ctx, configs) {
|
|
18
30
|
super(ctx, 'eula', true);
|
|
@@ -20,10 +32,14 @@ class Eula extends koishi_1.Service {
|
|
|
20
32
|
this.filter = false;
|
|
21
33
|
this.usage = Eula.usage;
|
|
22
34
|
this.log = ctx.logger('eula');
|
|
23
|
-
//
|
|
35
|
+
// 加载 YAML 本地化文件
|
|
24
36
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
const yaml = require('js-yaml');
|
|
38
|
+
// 使用 js-yaml 解析 YAML 文件
|
|
39
|
+
const zhContent = (0, fs_1.readFileSync)((0, path_1.join)(localesDir, 'zh.yaml'), 'utf8');
|
|
40
|
+
const enContent = (0, fs_1.readFileSync)((0, path_1.join)(localesDir, 'en.yaml'), 'utf8');
|
|
41
|
+
ctx.i18n.define('zh', yaml.load(zhContent));
|
|
42
|
+
ctx.i18n.define('en', yaml.load(enContent));
|
|
27
43
|
}
|
|
28
44
|
catch (err) {
|
|
29
45
|
this.log.error('Failed to load locales:', err);
|
|
@@ -52,9 +68,9 @@ class Eula extends koishi_1.Service {
|
|
|
52
68
|
.action((_) => this.eula(_));
|
|
53
69
|
}
|
|
54
70
|
async eula(argv) {
|
|
55
|
-
// 确保 jsx_runtime 已加载
|
|
56
71
|
if (!jsx_runtime_1) {
|
|
57
|
-
|
|
72
|
+
const mod = await jsx_runtime_1_promise;
|
|
73
|
+
jsx_runtime_1 = mod.default || mod;
|
|
58
74
|
}
|
|
59
75
|
const session = argv.session;
|
|
60
76
|
const userLocale = session.user.locale || session.user.locales[0] || 'zh';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-eula-regen",
|
|
3
3
|
"description": "EULA(End-user licence agreement) for your koishi bot.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.4",
|
|
5
5
|
"repository": "https://github.com/Lipraty/koishi-plugin-eula",
|
|
6
6
|
"author": "Lipraty <i@lonay.me>",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "tsc && cp -r src/locales lib/ || true",
|
|
16
|
-
"postbuild": "node -
|
|
16
|
+
"postbuild": "node fix-jsx.mjs"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^20.0.0",
|
|
@@ -42,5 +42,8 @@
|
|
|
42
42
|
],
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"koishi": "^4.12.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"js-yaml": "^4.1.1"
|
|
45
48
|
}
|
|
46
49
|
}
|