koishi-plugin-18xx 0.0.2 → 0.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/config.d.ts CHANGED
@@ -1,9 +1,13 @@
1
+ import { Server } from '@koishijs/plugin-server';
1
2
  import { Schema } from 'koishi';
2
3
  export declare const name = "18xx";
3
4
  export declare const inject: {
4
5
  required: string[];
5
6
  };
6
7
  export interface Config {
8
+ server: {
9
+ enable?: boolean;
10
+ } & Partial<Server.Config>;
7
11
  notification: {
8
12
  enable: boolean;
9
13
  path: string;
package/lib/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Context } from 'koishi';
2
- import { Config, name, inject } from './config';
3
- export { name, inject };
4
- export { Config };
2
+ import { Config, inject, name } from './config';
3
+ export { Config, inject, name };
5
4
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
8
  var __export = (target, all) => {
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -28,6 +38,7 @@ __export(src_exports, {
28
38
  module.exports = __toCommonJS(src_exports);
29
39
 
30
40
  // src/config.ts
41
+ var import_plugin_server = require("@koishijs/plugin-server");
31
42
  var import_koishi = require("koishi");
32
43
  var name = "18xx";
33
44
  var inject = {
@@ -35,6 +46,20 @@ var inject = {
35
46
  // optional: ['puppeteer'],
36
47
  };
37
48
  var Config = import_koishi.Schema.object({
49
+ server: import_koishi.Schema.intersect([
50
+ import_koishi.Schema.object({
51
+ enable: import_koishi.Schema.boolean().default(false).description("自定义服务器")
52
+ }),
53
+ import_koishi.Schema.union([
54
+ import_koishi.Schema.intersect([
55
+ import_koishi.Schema.object({
56
+ enable: import_koishi.Schema.const(true).required()
57
+ }),
58
+ import_plugin_server.Server.Config
59
+ ]),
60
+ import_koishi.Schema.object({})
61
+ ])
62
+ ]),
38
63
  notification: import_koishi.Schema.object({
39
64
  enable: import_koishi.Schema.boolean().default(true).description("启用通知"),
40
65
  path: import_koishi.Schema.string().default("/18xx").description("Webhook 监听路径"),
@@ -74,7 +99,7 @@ function command(ctx, config) {
74
99
  if (!found) return "";
75
100
  }
76
101
  }, "checkSessionMiddleware");
77
- ctx.command("18xx.bind <id>", "绑定 18xx.games 账号").usage("id 是个人资料页地址栏 profile 后面的数字").before(checkSessionMiddleware).action(async ({ session }, id) => {
102
+ ctx.command("18xx.bind <id>", "绑定账号").usage("id 是个人资料页地址栏 profile 后面的数字").before(checkSessionMiddleware).action(async ({ session }, id) => {
78
103
  if (Number(id)) {
79
104
  const result = await ctx.database.upsert(name, [
80
105
  {
@@ -94,28 +119,28 @@ function command(ctx, config) {
94
119
  return "绑定失败";
95
120
  }
96
121
  });
97
- ctx.command("18xx.unbind <id>", "取消绑定 18xx.games 账号").usage("id 是个人资料页地址栏 profile 后面的数字").action(async ({ session }, id) => {
122
+ ctx.command("18xx.unbind <id>", "取消绑定账号").usage("id 是个人资料页地址栏 profile 后面的数字").action(async ({ session }, id) => {
98
123
  const result = await ctx.database.remove(name, { id: Number(id), userId: session.userId });
99
124
  if (!result.matched) {
100
- return "你还没有绑定 18xx.games 账号";
125
+ return "你还没有绑定账号";
101
126
  }
102
127
  if (result.removed) {
103
128
  return `${id} 解绑成功`;
104
129
  }
105
130
  return "解绑失败";
106
131
  });
107
- ctx.command("18xx.list", "列出已绑定的 18xx.games 账号").alias("18xx.ls").action(async ({ session }) => {
132
+ ctx.command("18xx.list", "列出已绑定的账号").alias("18xx.ls").action(async ({ session }) => {
108
133
  const profiles = await ctx.database.get(name, { userId: session.userId });
109
134
  if (!profiles.length) {
110
- return "你还没有绑定 18xx.games 账号";
135
+ return "你还没有绑定账号";
111
136
  }
112
137
  return `当前已绑定${profiles.length}个账号:
113
138
  ${profiles.map((p) => `${p.id}`).join("\n")}`;
114
139
  });
115
- ctx.command("18xx.on", "开启 18xx.games 通知").usage("需要先绑定 18xx.games 账号,并在个人资料页 webhook_user_id 中填入你的 id").action(async ({ session }) => {
140
+ ctx.command("18xx.on", "开启通知").usage("需要先绑定账号,并在个人资料页 webhook_user_id 中填入你的 id").action(async ({ session }) => {
116
141
  const profiles = await ctx.database.get(name, { userId: session.userId });
117
142
  if (!profiles.length) {
118
- return "你还没有绑定 18xx.games 账号";
143
+ return "你还没有绑定账号";
119
144
  }
120
145
  const result = await ctx.database.upsert(
121
146
  name,
@@ -126,10 +151,10 @@ ${profiles.map((p) => `${p.id}`).join("\n")}`;
126
151
  }
127
152
  return "通知已开启";
128
153
  });
129
- ctx.command("18xx.off", "关闭 18xx.games 通知").action(async ({ session }) => {
154
+ ctx.command("18xx.off", "关闭通知").action(async ({ session }) => {
130
155
  const profiles = await ctx.database.get(name, { userId: session.userId });
131
156
  if (!profiles.length) {
132
- return "你还没有绑定 18xx.games 账号";
157
+ return "你还没有绑定账号";
133
158
  }
134
159
  const result = await ctx.database.upsert(
135
160
  name,
@@ -144,12 +169,41 @@ ${profiles.map((p) => `${p.id}`).join("\n")}`;
144
169
  __name(command, "command");
145
170
 
146
171
  // src/server.tsx
172
+ var import_plugin_server2 = __toESM(require("@koishijs/plugin-server"));
147
173
  var import_jsx_runtime = require("@satorijs/element/jsx-runtime");
174
+ var ForkServer = class extends import_plugin_server2.default {
175
+ static {
176
+ __name(this, "ForkServer");
177
+ }
178
+ };
179
+ var createProxyCtx = /* @__PURE__ */ __name((ctx) => new Proxy(ctx, {
180
+ get(target, p, receiver) {
181
+ const val = Reflect.get(target, p, receiver);
182
+ if (p === "name" && name !== val) {
183
+ return `${name} > ${val}`;
184
+ }
185
+ return val;
186
+ }
187
+ }), "createProxyCtx");
188
+ var forkServer = /* @__PURE__ */ __name((ctx, config) => new Promise((resolve, reject) => {
189
+ const proxy = createProxyCtx(ctx.isolate("server"));
190
+ proxy.plugin(ForkServer, {
191
+ ...ctx.server.config,
192
+ ...config.server
193
+ });
194
+ proxy.once("server/ready", () => resolve(proxy.server));
195
+ proxy.once("dispose", reject);
196
+ }), "forkServer");
148
197
  var MESSAGE_REGEX = /^<@?(.*?)>\s*(.*)$/;
149
- function server(ctx, config) {
198
+ async function server(ctx, config) {
150
199
  const logger = ctx.logger(name);
200
+ let server2 = ctx.server;
201
+ if (config.server.port && config.server.port !== server2.port) {
202
+ logger.info("Server port is different from koishi Server port, fork server.");
203
+ server2 = await forkServer(ctx, config);
204
+ }
151
205
  if (config.notification.enable) {
152
- ctx.server.post(config.notification.path, async (ptx, _next) => {
206
+ server2.post(config.notification.path, async (ptx, _next) => {
153
207
  const { text = "" } = ptx.request.body || {};
154
208
  const result = MESSAGE_REGEX.exec(text);
155
209
  if (!result) {
package/lib/server.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { Context } from 'koishi';
2
2
  import { Config } from './config';
3
- export declare function server(ctx: Context, config: Config): void;
3
+ export declare function server(ctx: Context, config: Config): Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-18xx",
3
3
  "description": "18xxGames 机器人",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -19,16 +19,16 @@
19
19
  },
20
20
  "keywords": [
21
21
  "koishi",
22
- "18xxgames",
22
+ "18xx.games",
23
23
  "webhook"
24
24
  ],
25
25
  "devDependencies": {
26
26
  "@koishijs/plugin-adapter-onebot": "^6.0.2",
27
- "@koishijs/plugin-server": "^3.2.7",
28
27
  "typescript": "^5.8.3"
29
28
  },
30
29
  "peerDependencies": {
31
- "@satorijs/element": "^3.1.8",
30
+ "@koishijs/plugin-server": "^3.2.7",
31
+ "@satorijs/element": "*",
32
32
  "koishi": "^4.18.7"
33
33
  },
34
34
  "koishi": {