koishi-plugin-eula-regen 1.0.0 → 1.0.2
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 +46 -31
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// 动态导入 ES Module - 使用 Promise 缓存
|
|
4
|
+
let jsx_runtime_1_promise = import("@satorijs/element/jsx-runtime");
|
|
5
|
+
let jsx_runtime_1;
|
|
6
|
+
// 立即开始加载,并在加载完成后缓存
|
|
7
|
+
jsx_runtime_1_promise.then(mod => {
|
|
8
|
+
jsx_runtime_1 = mod;
|
|
9
|
+
});
|
|
10
|
+
const koishi_1 = require("koishi");
|
|
11
|
+
const module_1 = require("module");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
// 在 CommonJS 环境中,使用 __filename 或 __dirname
|
|
14
|
+
// @ts-ignore - __filename 和 __dirname 在运行时可用
|
|
15
|
+
const localRequire = (0, module_1.createRequire)(typeof __filename !== 'undefined' ? __filename : (0, path_1.join)(typeof __dirname !== 'undefined' ? __dirname : '.', 'index.js'));
|
|
16
|
+
class Eula extends koishi_1.Service {
|
|
6
17
|
constructor(ctx, configs) {
|
|
7
18
|
super(ctx, 'eula', true);
|
|
8
19
|
this.configs = configs;
|
|
@@ -11,8 +22,8 @@ class Eula extends Service {
|
|
|
11
22
|
this.log = ctx.logger('eula');
|
|
12
23
|
// 使用 createRequire 加载 YAML 本地化文件
|
|
13
24
|
try {
|
|
14
|
-
ctx.i18n.define('zh',
|
|
15
|
-
ctx.i18n.define('en',
|
|
25
|
+
ctx.i18n.define('zh', localRequire('./locales/zh'));
|
|
26
|
+
ctx.i18n.define('en', localRequire('./locales/en'));
|
|
16
27
|
}
|
|
17
28
|
catch (err) {
|
|
18
29
|
this.log.error('Failed to load locales:', err);
|
|
@@ -41,14 +52,18 @@ class Eula extends Service {
|
|
|
41
52
|
.action((_) => this.eula(_));
|
|
42
53
|
}
|
|
43
54
|
async eula(argv) {
|
|
55
|
+
// 确保 jsx_runtime 已加载
|
|
56
|
+
if (!jsx_runtime_1) {
|
|
57
|
+
jsx_runtime_1 = await jsx_runtime_1_promise;
|
|
58
|
+
}
|
|
44
59
|
const session = argv.session;
|
|
45
60
|
const userLocale = session.user.locale || session.user.locales[0] || 'zh';
|
|
46
|
-
const accept = Random.pick(this.configs.accept) ?? session.text('eula.defaultAccept');
|
|
47
|
-
await session.send(
|
|
61
|
+
const accept = koishi_1.Random.pick(this.configs.accept) ?? session.text('eula.defaultAccept');
|
|
62
|
+
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] }) })] })] }));
|
|
48
63
|
const prompt = await session.prompt(this.configs.waitTime * 1000);
|
|
49
64
|
this.log.info(`[platfrom: ${session.platform}]user ${session.userId} reply to (${prompt}) eula`);
|
|
50
65
|
if (prompt) {
|
|
51
|
-
const promptEle = h.parse(prompt);
|
|
66
|
+
const promptEle = koishi_1.h.parse(prompt);
|
|
52
67
|
if (promptEle[0].type === 'at' && promptEle[0].attrs.id === session.bot.selfId)
|
|
53
68
|
promptEle.shift(); // remove `at` element
|
|
54
69
|
const accredit = promptEle[0].attrs.content.replace(/^\//g, '').trim() === accept;
|
|
@@ -78,35 +93,35 @@ class Eula extends Service {
|
|
|
78
93
|
|
|
79
94
|
协议内容文本可以在 <a href="/locales/eula/eulaMessage">本地化 - eula.eulaMessage</a> 中修改,因此你可以根据不同语言给予不同的协议文本。
|
|
80
95
|
`;
|
|
81
|
-
Eula.Config = Schema.intersect([
|
|
82
|
-
Schema.object({
|
|
83
|
-
waitTime: Schema.number().min(30).max(300).step(1).default(60).description('等待回复时长(秒)'),
|
|
84
|
-
replyAuthority: Schema.number().min(1).max(5).default(1).description('协议生效最高等级'),
|
|
85
|
-
forwardMessgae: Schema.boolean().default(true).description('合并发送的协议以及认可段(目前仅在 QQ 生效)')
|
|
96
|
+
Eula.Config = koishi_1.Schema.intersect([
|
|
97
|
+
koishi_1.Schema.object({
|
|
98
|
+
waitTime: koishi_1.Schema.number().min(30).max(300).step(1).default(60).description('等待回复时长(秒)'),
|
|
99
|
+
replyAuthority: koishi_1.Schema.number().min(1).max(5).default(1).description('协议生效最高等级'),
|
|
100
|
+
forwardMessgae: koishi_1.Schema.boolean().default(true).description('合并发送的协议以及认可段(目前仅在 QQ 生效)')
|
|
86
101
|
}).description('基本设置'),
|
|
87
|
-
Schema.object({
|
|
88
|
-
alias: Schema.string().default('EULA').description('《最终用户许可协议》别名,或其他自拟协议名称'),
|
|
89
|
-
content: Schema.dict(Schema.string().role('textarea', { rows: [2, 4] })).default({
|
|
102
|
+
koishi_1.Schema.object({
|
|
103
|
+
alias: koishi_1.Schema.string().default('EULA').description('《最终用户许可协议》别名,或其他自拟协议名称'),
|
|
104
|
+
content: koishi_1.Schema.dict(koishi_1.Schema.string().role('textarea', { rows: [2, 4] })).default({
|
|
90
105
|
'zh': '协议内容',
|
|
91
106
|
}).description('协议内容的多语言设置'),
|
|
92
|
-
accept: Schema.array(String).description('认可协议关键字,如果有多个,则随机某一个作为认可关键字')
|
|
107
|
+
accept: koishi_1.Schema.array(String).description('认可协议关键字,如果有多个,则随机某一个作为认可关键字')
|
|
93
108
|
}).description('协议设置'),
|
|
94
|
-
Schema.intersect([
|
|
95
|
-
Schema.object({
|
|
96
|
-
enable: Schema.boolean().default(true).description('限制所有的命令')
|
|
109
|
+
koishi_1.Schema.intersect([
|
|
110
|
+
koishi_1.Schema.object({
|
|
111
|
+
enable: koishi_1.Schema.boolean().default(true).description('限制所有的命令')
|
|
97
112
|
}),
|
|
98
|
-
Schema.union([
|
|
99
|
-
Schema.object({
|
|
100
|
-
enable: Schema.const(false).required(),
|
|
101
|
-
model: Schema.union([
|
|
102
|
-
Schema.const(true).description('白名单'),
|
|
103
|
-
Schema.const(false).description('黑名单'),
|
|
113
|
+
koishi_1.Schema.union([
|
|
114
|
+
koishi_1.Schema.object({
|
|
115
|
+
enable: koishi_1.Schema.const(false).required(),
|
|
116
|
+
model: koishi_1.Schema.union([
|
|
117
|
+
koishi_1.Schema.const(true).description('白名单'),
|
|
118
|
+
koishi_1.Schema.const(false).description('黑名单'),
|
|
104
119
|
]).description('限制命令的模式'),
|
|
105
|
-
commands: Schema.array(String).description('指令列表')
|
|
120
|
+
commands: koishi_1.Schema.array(String).description('指令列表')
|
|
106
121
|
}),
|
|
107
|
-
Schema.object({})
|
|
122
|
+
koishi_1.Schema.object({})
|
|
108
123
|
])
|
|
109
124
|
]).description('指令限制')
|
|
110
125
|
]);
|
|
111
126
|
})(Eula || (Eula = {}));
|
|
112
|
-
|
|
127
|
+
exports.default = Eula;
|
package/package.json
CHANGED
|
@@ -1,8 +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.
|
|
5
|
-
"type": "module",
|
|
4
|
+
"version": "1.0.2",
|
|
6
5
|
"repository": "https://github.com/Lipraty/koishi-plugin-eula",
|
|
7
6
|
"author": "Lipraty <i@lonay.me>",
|
|
8
7
|
"main": "lib/index.js",
|
|
@@ -13,7 +12,8 @@
|
|
|
13
12
|
],
|
|
14
13
|
"license": "MIT",
|
|
15
14
|
"scripts": {
|
|
16
|
-
"build": "tsc && cp -r src/locales lib/"
|
|
15
|
+
"build": "tsc && cp -r src/locales lib/ || true",
|
|
16
|
+
"postbuild": "node -e \"const fs=require('fs');const p='lib/index.js';let c=fs.readFileSync(p,'utf8');if(c.includes('require(\\\"@satorijs/element/jsx-runtime\\\")')){c=c.replace(/const jsx_runtime_1 = require\\(\"@satorijs\\\\/element\\\\/jsx-runtime\"\\);?/,'');c=c.replace(/('use strict';\\\\nObject\\\\.defineProperty\\(exports, '__esModule', \\\\{ value: true \\\\}\\);)/,'$1\\\\nlet jsx_runtime_1_promise = import(\\\"@satorijs/element/jsx-runtime\\\");\\\\nlet jsx_runtime_1;\\\\njsx_runtime_1_promise.then(mod=>{jsx_runtime_1=mod;});\\\\n');c=c.replace(/(async eula\\(argv\\) \\{)/,'$1\\\\nif(!jsx_runtime_1){jsx_runtime_1=await jsx_runtime_1_promise;}\\\\n');fs.writeFileSync(p,c);}\""
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^20.0.0",
|