koishi-plugin-eula-regen 1.0.3 → 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 +25 -19
- package/package.json +4 -1
package/lib/index.js
CHANGED
|
@@ -1,20 +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
|
-
// ES Module 可能使用 default 导出或命名导出
|
|
8
5
|
jsx_runtime_1_promise.then(mod => {
|
|
9
|
-
// 处理可能的 default 导出
|
|
10
6
|
jsx_runtime_1 = mod.default || mod;
|
|
11
7
|
});
|
|
8
|
+
|
|
9
|
+
|
|
12
10
|
const koishi_1 = require("koishi");
|
|
13
|
-
const
|
|
11
|
+
const fs_1 = require("fs");
|
|
14
12
|
const path_1 = require("path");
|
|
15
|
-
//
|
|
13
|
+
// 获取当前文件所在目录
|
|
16
14
|
// @ts-ignore - __filename 和 __dirname 在运行时可用
|
|
17
|
-
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');
|
|
18
28
|
class Eula extends koishi_1.Service {
|
|
19
29
|
constructor(ctx, configs) {
|
|
20
30
|
super(ctx, 'eula', true);
|
|
@@ -22,10 +32,14 @@ class Eula extends koishi_1.Service {
|
|
|
22
32
|
this.filter = false;
|
|
23
33
|
this.usage = Eula.usage;
|
|
24
34
|
this.log = ctx.logger('eula');
|
|
25
|
-
//
|
|
35
|
+
// 加载 YAML 本地化文件
|
|
26
36
|
try {
|
|
27
|
-
|
|
28
|
-
|
|
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));
|
|
29
43
|
}
|
|
30
44
|
catch (err) {
|
|
31
45
|
this.log.error('Failed to load locales:', err);
|
|
@@ -54,7 +68,6 @@ class Eula extends koishi_1.Service {
|
|
|
54
68
|
.action((_) => this.eula(_));
|
|
55
69
|
}
|
|
56
70
|
async eula(argv) {
|
|
57
|
-
// 确保 jsx_runtime 已加载
|
|
58
71
|
if (!jsx_runtime_1) {
|
|
59
72
|
const mod = await jsx_runtime_1_promise;
|
|
60
73
|
jsx_runtime_1 = mod.default || mod;
|
|
@@ -62,14 +75,7 @@ class Eula extends koishi_1.Service {
|
|
|
62
75
|
const session = argv.session;
|
|
63
76
|
const userLocale = session.user.locale || session.user.locales[0] || 'zh';
|
|
64
77
|
const accept = koishi_1.Random.pick(this.configs.accept) ?? session.text('eula.defaultAccept');
|
|
65
|
-
|
|
66
|
-
const jsx = jsx_runtime_1.jsx;
|
|
67
|
-
const jsxs = jsx_runtime_1.jsxs;
|
|
68
|
-
const Fragment = jsx_runtime_1.Fragment;
|
|
69
|
-
if (!jsx || !jsxs || !Fragment) {
|
|
70
|
-
throw new Error("jsx-runtime functions not available. Module keys: " + Object.keys(jsx_runtime_1).join(', '));
|
|
71
|
-
}
|
|
72
|
-
await session.send((0, jsxs)(Fragment, { children: [(0, jsx)("message", { id: "{0}", children: (0, jsx)("i18n", { path: "eula.eulaMessage.title", children: [this.configs.alias] }) }), (0, jsxs)("message", { forward: this.configs.forwardMessgae, children: [(0, jsx)("message", { id: "{0}", children: this.configs.content[userLocale] ?? this.configs.content['zh'] }), (0, jsx)("message", { id: "{0}", children: (0, jsx)("i18n", { path: "eula.eulaMessage.confirm", children: [accept] }) })] })] }));
|
|
78
|
+
await session.send((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("message", { id: "{0}", children: (0, jsx_runtime_1.jsx)("i18n", { path: "eula.eulaMessage.title", children: [this.configs.alias] }) }), (0, jsx_runtime_1.jsxs)("message", { forward: this.configs.forwardMessgae, children: [(0, jsx_runtime_1.jsx)("message", { id: "{0}", children: this.configs.content[userLocale] ?? this.configs.content['zh'] }), (0, jsx_runtime_1.jsx)("message", { id: "{0}", children: (0, jsx_runtime_1.jsx)("i18n", { path: "eula.eulaMessage.confirm", children: [accept] }) })] })] }));
|
|
73
79
|
const prompt = await session.prompt(this.configs.waitTime * 1000);
|
|
74
80
|
this.log.info(`[platfrom: ${session.platform}]user ${session.userId} reply to (${prompt}) eula`);
|
|
75
81
|
if (prompt) {
|
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",
|
|
@@ -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
|
}
|