koishi-plugin-eula-regen 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/lib/index.js +13 -3
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  let jsx_runtime_1_promise = import("@satorijs/element/jsx-runtime");
5
5
  let jsx_runtime_1;
6
6
  // 立即开始加载,并在加载完成后缓存
7
+ // ES Module 可能使用 default 导出或命名导出
7
8
  jsx_runtime_1_promise.then(mod => {
8
- jsx_runtime_1 = mod;
9
+ // 处理可能的 default 导出
10
+ jsx_runtime_1 = mod.default || mod;
9
11
  });
10
12
  const koishi_1 = require("koishi");
11
13
  const module_1 = require("module");
@@ -54,12 +56,20 @@ class Eula extends koishi_1.Service {
54
56
  async eula(argv) {
55
57
  // 确保 jsx_runtime 已加载
56
58
  if (!jsx_runtime_1) {
57
- jsx_runtime_1 = await jsx_runtime_1_promise;
59
+ const mod = await jsx_runtime_1_promise;
60
+ jsx_runtime_1 = mod.default || mod;
58
61
  }
59
62
  const session = argv.session;
60
63
  const userLocale = session.user.locale || session.user.locales[0] || 'zh';
61
64
  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] }) })] })] }));
65
+ // 确保 jsx jsxs 函数存在
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] }) })] })] }));
63
73
  const prompt = await session.prompt(this.configs.waitTime * 1000);
64
74
  this.log.info(`[platfrom: ${session.platform}]user ${session.userId} reply to (${prompt}) eula`);
65
75
  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.2",
4
+ "version": "1.0.3",
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 -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);}\""
16
+ "postbuild": "node fix-jsx.mjs"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^20.0.0",