@kotori-bot/loader 1.5.0 → 1.5.1

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.
@@ -1,4 +1,4 @@
1
- import { Container, Symbols } from '@kotori-bot/core';
1
+ import { Container, Symbols, formatFactory } from '@kotori-bot/core';
2
2
  import Logger from '@kotori-bot/logger';
3
3
  import Runner from './runner';
4
4
  import Server from '../service/server';
@@ -15,6 +15,8 @@ declare module '@kotori-bot/core' {
15
15
  server: Server;
16
16
  db: Database;
17
17
  file: File;
18
+ format: ReturnType<typeof formatFactory>;
19
+ locale: Context['i18n']['locale'];
18
20
  }
19
21
  interface GlobalConfig {
20
22
  dirs: string[];
@@ -32,11 +32,11 @@ exports.Loader = void 0;
32
32
  * @Blog: https://hotaru.icu
33
33
  * @Date: 2023-06-24 15:12:55
34
34
  * @LastEditors: Hotaru biyuehuya@gmail.com
35
- * @LastEditTime: 2024-05-03 22:05:36
35
+ * @LastEditTime: 2024-05-12 16:24:15
36
36
  */
37
37
  const core_1 = require("@kotori-bot/core");
38
- const path_1 = __importDefault(require("path"));
39
- const fs_1 = __importDefault(require("fs"));
38
+ const node_path_1 = __importDefault(require("node:path"));
39
+ const node_fs_1 = __importDefault(require("node:fs"));
40
40
  const logger_1 = __importStar(require("@kotori-bot/logger"));
41
41
  const runner_1 = __importStar(require("./runner"));
42
42
  const log_1 = __importDefault(require("../utils/log"));
@@ -47,26 +47,26 @@ function getBaseDir(file, dir) {
47
47
  const handle = (root) => {
48
48
  const baseDir = {
49
49
  root,
50
- modules: path_1.default.join(root, 'modules'),
51
- data: path_1.default.join(root, 'data'),
52
- logs: path_1.default.join(root, 'logs')
50
+ modules: node_path_1.default.join(root, 'modules'),
51
+ data: node_path_1.default.join(root, 'data'),
52
+ logs: node_path_1.default.join(root, 'logs')
53
53
  };
54
54
  Object.values(baseDir).forEach((val) => {
55
- if (!fs_1.default.existsSync(val))
56
- fs_1.default.mkdirSync(val);
55
+ if (!node_fs_1.default.existsSync(val))
56
+ node_fs_1.default.mkdirSync(val);
57
57
  });
58
58
  return baseDir;
59
59
  };
60
60
  if (dir)
61
- return handle(path_1.default.resolve(dir));
62
- let root = path_1.default.resolve(__dirname, '..').replace('loader', 'kotori');
61
+ return handle(node_path_1.default.resolve(dir));
62
+ let root = node_path_1.default.resolve(__dirname, '..').replace('loader', 'kotori');
63
63
  let count = 0;
64
- while (!fs_1.default.existsSync(path_1.default.join(root, file))) {
64
+ while (!node_fs_1.default.existsSync(node_path_1.default.join(root, file))) {
65
65
  if (count > 5) {
66
66
  logger_1.default.fatal(`cannot find file ${file} `);
67
67
  process.exit();
68
68
  }
69
- root = path_1.default.join(root, '..');
69
+ root = node_path_1.default.join(root, '..');
70
70
  count += 1;
71
71
  }
72
72
  return handle(root);
@@ -88,7 +88,7 @@ function getCoreConfig(file, baseDir) {
88
88
  .default(core_1.DEFAULT_CORE_CONFIG.plugin)
89
89
  })
90
90
  .default({ global: Object.assign(core_1.DEFAULT_CORE_CONFIG.global), plugin: core_1.DEFAULT_CORE_CONFIG.plugin })
91
- .parse((0, core_1.loadConfig)(path_1.default.join(baseDir.root, file), 'yaml'));
91
+ .parse((0, core_1.loadConfig)(node_path_1.default.join(baseDir.root, file), 'yaml'));
92
92
  return core_1.Tsu.Object({
93
93
  adapter: core_1.Tsu.Object({})
94
94
  .index(core_1.Tsu.Object({
@@ -122,6 +122,9 @@ class Loader extends core_1.Container {
122
122
  ctx.provide('runner', new runner_1.default(ctx, runnerConfig));
123
123
  ctx.mixin('runner', ['baseDir', 'options']);
124
124
  core_1.Container.setInstance(ctx);
125
+ ctx.provide('loader-tools', { format: (0, core_1.formatFactory)(ctx.i18n), locale: ctx.i18n.locale.bind(ctx.i18n) });
126
+ ctx.mixin('loader-tools', ['locale', 'format']);
127
+ ctx.i18n.use(node_path_1.default.resolve(__dirname, '../../locales'));
125
128
  this.ctx = core_1.Container.getInstance();
126
129
  this.ctx.logger.trace(`options:`, options);
127
130
  this.ctx.logger.trace(`runnerConfig:`, runnerConfig);
@@ -161,42 +164,39 @@ class Loader extends core_1.Container {
161
164
  process.on('uncaughtExceptionMonitor', (err) => this.handleError(err, 'sync'));
162
165
  process.on('unhandledRejection', (err) => this.handleError(err, 'async'));
163
166
  process.on('SIGINT', () => process.exit());
164
- this.ctx.logger.debug('run info: develop with debugging...');
167
+ this.ctx.logger.debug(this.ctx.locale('loader.debug.info'));
165
168
  }
166
169
  listenMessage() {
167
170
  this.ctx.on('connect', (data) => {
168
- const { type, mode, normal, address, adapter } = data;
171
+ const { type, mode, normal, address: addr, adapter } = data;
169
172
  let msg;
170
173
  if (type === 'connect') {
171
174
  switch (mode) {
172
175
  case 'ws':
173
- msg = `${normal ? 'Connect' : 'Reconnect'} server to ${address}`;
176
+ msg = this.ctx.format(`loader.bots.${normal ? 'connect' : 'reconnect'}`, [addr]);
174
177
  break;
175
178
  case 'ws-reverse':
176
- msg = `server ${normal ? 'start' : 'restart'} at ${address}`;
179
+ msg = this.ctx.format(`loader.bots.${normal ? 'start' : 'restart'}`, [addr]);
177
180
  break;
178
181
  default:
179
- msg = `ready completed about ${address}`;
182
+ msg = this.ctx.format('loader.bots.ready', [addr]);
180
183
  }
181
184
  }
182
185
  else {
183
186
  switch (mode) {
184
187
  case 'ws':
185
- msg = `disconnect server from ${address}${normal ? '' : ' unexpectedly'}`;
188
+ msg = this.ctx.format(`loader.bots.disconnect${normal ? '' : '.error'}`, [addr]);
186
189
  break;
187
190
  case 'ws-reverse':
188
- msg = `server stop at ${address}${normal ? '' : ' unexpectedly'}`;
191
+ msg = this.ctx.format(`loader.bots.stop${normal ? '' : '.error'}`, [addr]);
189
192
  break;
190
193
  default:
191
- msg = `dispose completed about ${address}`;
194
+ msg = this.ctx.format('loader.bots.dispose', [addr]);
192
195
  }
193
196
  }
194
197
  adapter.ctx.logger[normal ? 'info' : 'warn'](msg);
195
198
  });
196
- this.ctx.on('status', (data) => {
197
- const { status, adapter } = data;
198
- adapter.ctx.logger.info(status);
199
- });
199
+ this.ctx.on('status', ({ status, adapter }) => adapter.ctx.logger.info(status));
200
200
  this.ctx.on('ready_module', (data) => {
201
201
  if (typeof data.instance !== 'object')
202
202
  return;
@@ -207,16 +207,17 @@ class Loader extends core_1.Container {
207
207
  return;
208
208
  this.loadCount += 1;
209
209
  const { name, version, author, peerDependencies } = pkg[0].pkg;
210
- this.ctx.logger.info(`loaded module ${name} version: ${version} ${Array.isArray(author) ? `authors: ${author.join(',')}` : `author: ${author}`}`);
210
+ this.ctx.logger.info(this.ctx.format('loader.modules.load', [name, version, Array.isArray(author) ? author.join(',') : author]));
211
211
  const requiredVersion = peerDependencies['kotori-bot'];
212
- if (!requiredVersion.includes('workspace') &&
213
- (!constants_1.SUPPORTS_VERSION.exec(requiredVersion) || requiredVersion !== this.ctx.pkg.version)) {
214
- if (constants_1.SUPPORTS_HALF_VERSION.exec(requiredVersion)) {
215
- this.ctx.logger.warn(`incomplete supported module version: ${requiredVersion}`);
216
- }
217
- else {
218
- this.ctx.logger.error(`unsupported module version: ${requiredVersion}`);
219
- }
212
+ if (requiredVersion.includes('workspace') ||
213
+ constants_1.SUPPORTS_VERSION.exec(requiredVersion) ||
214
+ requiredVersion.includes(this.ctx.pkg.version))
215
+ return;
216
+ if (constants_1.SUPPORTS_HALF_VERSION.exec(requiredVersion)) {
217
+ this.ctx.logger.warn(this.ctx.format('loader.modules.incomplete', [requiredVersion]));
218
+ }
219
+ else {
220
+ this.ctx.logger.error(this.ctx.format('loader.modules.unsupported', [requiredVersion]));
220
221
  }
221
222
  });
222
223
  }
@@ -227,7 +228,7 @@ class Loader extends core_1.Container {
227
228
  loadAllModules() {
228
229
  this.ctx.get('runner').loadAll();
229
230
  const failLoadCount = this.ctx.get('runner')[core_1.Symbols.modules].size - this.loadCount;
230
- this.ctx.logger.info(`loaded ${this.loadCount} modules successfully${failLoadCount > 0 ? `, failed to load ${failLoadCount} modules` : ''} `);
231
+ this.ctx.logger.info(this.ctx.format(`loader.modules.all${failLoadCount > 0 ? '.fail' : ''}`, [this.loadCount, failLoadCount]));
231
232
  this.loadAllAdapter();
232
233
  this.ctx.emit('ready');
233
234
  }
@@ -236,13 +237,11 @@ class Loader extends core_1.Container {
236
237
  Object.keys(this.ctx.config.adapter).forEach((botName) => {
237
238
  const botConfig = this.ctx.config.adapter[botName];
238
239
  const array = adapters.get(botConfig.extends);
239
- if (!array) {
240
- this.ctx.logger.warn(`cannot find adapter '${botConfig.extends}' for ${botName}`);
241
- return;
242
- }
240
+ if (!array)
241
+ return this.ctx.logger.warn(this.ctx.format('loader.adapter.notfound', [botConfig.extends, botName]));
243
242
  const result = array[1]?.parseSafe(botConfig);
244
243
  if (result && !result.value)
245
- throw new core_1.ModuleError(`Config format of adapter ${botName} is error: ${result.error.message}`);
244
+ throw new core_1.ModuleError(this.ctx.format('error.module.config_bot', [botName, result.error.message]));
246
245
  const bot = new array[0](this.ctx.extends({}, `${botConfig.extends}/${botName}`), result ? result.data : botConfig, botName);
247
246
  this.ctx.on('ready', () => bot.start());
248
247
  this.ctx.on('dispose', () => bot.stop());
@@ -252,15 +251,15 @@ class Loader extends core_1.Container {
252
251
  const { version } = this.ctx.pkg;
253
252
  const res = await this.ctx.http
254
253
  .get("https://hotaru.icu/api/agent/?url=https://raw.githubusercontent.com/kotorijs/kotori/master/packages/core/package.json" /* GLOBAL.UPDATE */)
255
- .catch(() => this.ctx.logger.error('get update failed, please check your network'));
254
+ .catch(() => this.ctx.logger.error(this.ctx.locale('loader.tips.update.failed')));
256
255
  if (!res || !core_1.Tsu.Object({ version: core_1.Tsu.String() }).check(res)) {
257
- this.ctx.logger.warn(`detection update failed`);
256
+ this.ctx.logger.warn(this.ctx.locale('loader.tips.update.failed'));
258
257
  }
259
258
  else if (version === res.version) {
260
- this.ctx.logger.info('kotori is currently the latest version');
259
+ this.ctx.logger.info(this.ctx.locale('loader.tips.update.latest'));
261
260
  }
262
261
  else {
263
- this.ctx.logger.warn(`the current version of Kotori is ${version}, and the latest version is ${res.version}. please go to ${"https://github.com/kotorijs/kotori" /* GLOBAL.REPO */} to update`);
262
+ this.ctx.logger.warn(this.ctx.format('loader.tips.update.available', [version, res.version, "https://github.com/kotorijs/kotori" /* GLOBAL.REPO */]));
264
263
  }
265
264
  }
266
265
  }
@@ -1,5 +1,6 @@
1
1
  import { Context, LocaleType, ModuleConfig, Symbols } from '@kotori-bot/core';
2
2
  import { BUILD_MODE, DEV_MODE, DEV_SOURCE_MODE } from '../constants';
3
+ import './loader';
3
4
  interface BaseDir {
4
5
  root: string;
5
6
  modules: string;
@@ -27,12 +27,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.Runner = exports.localeTypeSchema = void 0;
30
- const fs_1 = __importStar(require("fs"));
31
- const path_1 = __importStar(require("path"));
30
+ const node_fs_1 = __importStar(require("node:fs"));
31
+ const node_path_1 = __importStar(require("node:path"));
32
32
  const core_1 = require("@kotori-bot/core");
33
33
  const logger_1 = require("@kotori-bot/logger");
34
34
  const constants_1 = require("../constants");
35
35
  const logger_2 = __importDefault(require("../utils/logger"));
36
+ require("./loader");
36
37
  exports.localeTypeSchema = core_1.Tsu.Union([
37
38
  core_1.Tsu.Union([core_1.Tsu.Literal('en_US'), core_1.Tsu.Literal('ja_JP')]),
38
39
  core_1.Tsu.Union([core_1.Tsu.Literal('zh_TW'), core_1.Tsu.Any()])
@@ -96,59 +97,59 @@ class Runner {
96
97
  ctx.inject('logger');
97
98
  }
98
99
  getDirFiles(rootDir) {
99
- const files = fs_1.default.readdirSync(rootDir);
100
+ const files = node_fs_1.default.readdirSync(rootDir);
100
101
  const list = [];
101
102
  files.forEach((fileName) => {
102
- const file = path_1.default.join(rootDir, fileName);
103
- if (fs_1.default.statSync(file).isDirectory()) {
103
+ const file = node_path_1.default.join(rootDir, fileName);
104
+ if (node_fs_1.default.statSync(file).isDirectory()) {
104
105
  list.push(...this.getDirFiles(file));
105
106
  }
106
- if (path_1.default.parse(file).ext !== (this.isSourceDev ? constants_1.DEV_FILE : constants_1.BUILD_FILE))
107
+ if (node_path_1.default.parse(file).ext !== (this.isSourceDev ? constants_1.DEV_FILE : constants_1.BUILD_FILE))
107
108
  return;
108
- list.push(path_1.default.resolve(file));
109
+ list.push(node_path_1.default.resolve(file));
109
110
  });
110
111
  return list;
111
112
  }
112
113
  getModuleRootDir() {
113
114
  const moduleRootDir = [];
114
115
  [
115
- ...this.ctx.config.global.dirs.map((dir) => path_1.default.resolve(this.ctx.baseDir.root, dir)),
116
+ ...this.ctx.config.global.dirs.map((dir) => node_path_1.default.resolve(this.ctx.baseDir.root, dir)),
116
117
  this.ctx.baseDir.modules
117
118
  ].forEach((dir) => {
118
- if (fs_1.default.existsSync(dir) && fs_1.default.statSync(dir).isDirectory())
119
+ if (node_fs_1.default.existsSync(dir) && node_fs_1.default.statSync(dir).isDirectory())
119
120
  moduleRootDir.push(dir);
120
121
  });
121
122
  return moduleRootDir;
122
123
  }
123
124
  async checkModuleFiles(rootDir, filename) {
124
- const dir = path_1.default.join(rootDir, filename);
125
- if (!fs_1.default.statSync(dir).isDirectory())
125
+ const dir = node_path_1.default.join(rootDir, filename);
126
+ if (!node_fs_1.default.statSync(dir).isDirectory())
126
127
  return;
127
128
  if (rootDir !== this.ctx.baseDir.modules && !filename.startsWith(core_1.PLUGIN_PREFIX))
128
129
  return;
129
- const packagePath = path_1.default.join(dir, 'package.json');
130
+ const packagePath = node_path_1.default.join(dir, 'package.json');
130
131
  let pkg;
131
- if (!fs_1.default.existsSync(packagePath))
132
+ if (!node_fs_1.default.existsSync(packagePath))
132
133
  return;
133
134
  try {
134
- pkg = JSON.parse(fs_1.default.readFileSync(packagePath).toString());
135
+ pkg = JSON.parse(node_fs_1.default.readFileSync(packagePath).toString());
135
136
  }
136
137
  catch {
137
- throw new core_1.DevError(`illegal package.json ${packagePath}`);
138
+ throw new core_1.DevError(this.ctx.format('error.dev.package.illegal', [packagePath]));
138
139
  }
139
140
  const result = modulePackageSchema.parseSafe(pkg);
140
141
  if (!result.value) {
141
142
  if (rootDir !== this.ctx.baseDir.modules)
142
143
  return;
143
- throw new core_1.DevError(`package.json format error ${packagePath}: ${result.error.message}`);
144
+ throw new core_1.DevError(this.ctx.format('error.dev.package.missing', [packagePath, result.error.message]));
144
145
  }
145
146
  pkg = result.data;
146
- const devMode = this.isSourceDev && (0, fs_1.existsSync)(path_1.default.resolve(dir, constants_1.DEV_IMPORT));
147
- const main = path_1.default.resolve(dir, devMode ? constants_1.DEV_IMPORT : pkg.main);
148
- if (!fs_1.default.existsSync(main))
149
- throw new core_1.DevError(`cannot find ${main}`);
150
- const dirs = path_1.default.join(dir, devMode ? constants_1.DEV_CODE_DIRS : path_1.default.dirname(pkg.main));
151
- const files = fs_1.default.statSync(dirs).isDirectory() ? this.getDirFiles(dirs) : [];
147
+ const devMode = this.isSourceDev && (0, node_fs_1.existsSync)(node_path_1.default.resolve(dir, constants_1.DEV_IMPORT));
148
+ const main = node_path_1.default.resolve(dir, devMode ? constants_1.DEV_IMPORT : pkg.main);
149
+ if (!node_fs_1.default.existsSync(main))
150
+ throw new core_1.DevError(this.ctx.format('error.dev.main_file', [main]));
151
+ const dirs = node_path_1.default.join(dir, devMode ? constants_1.DEV_CODE_DIRS : node_path_1.default.dirname(pkg.main));
152
+ const files = node_fs_1.default.statSync(dirs).isDirectory() ? this.getDirFiles(dirs) : [];
152
153
  this[core_1.Symbols.modules].set(pkg.name, [
153
154
  { pkg, files, main },
154
155
  this.ctx.config.plugin[(0, core_1.stringRightSplit)(pkg.name, core_1.PLUGIN_PREFIX)] || {}
@@ -156,20 +157,20 @@ class Runner {
156
157
  }
157
158
  getModuleList(rootDir) {
158
159
  this.ctx.logger.trace('load dirs:', rootDir);
159
- fs_1.default.readdirSync(rootDir).forEach(async (filename) => {
160
+ node_fs_1.default.readdirSync(rootDir).forEach(async (filename) => {
160
161
  await this.checkModuleFiles(rootDir, filename);
161
162
  });
162
163
  }
163
164
  loadLang(lang) {
164
165
  if (lang)
165
- this.ctx.i18n.use((0, path_1.resolve)(...(Array.isArray(lang) ? lang : [lang])));
166
+ this.ctx.i18n.use((0, node_path_1.resolve)(...(Array.isArray(lang) ? lang : [lang])));
166
167
  }
167
168
  loadEx(instance, origin) {
168
169
  this.ctx.logger.trace('module:', instance, origin);
169
170
  const parsed = (schema) => {
170
171
  const result = schema.parseSafe(config);
171
172
  if (!result.value)
172
- throw new core_1.ModuleError(`Config format of module ${pkg.name} is error: ${result.error.message}`);
173
+ throw new core_1.ModuleError(this.ctx.format('error.module.config', [pkg.name, result.error.message]));
173
174
  return result.data;
174
175
  };
175
176
  const { main, pkg } = instance;
@@ -222,8 +223,8 @@ class Runner {
222
223
  this.watcher();
223
224
  }
224
225
  watcher() {
225
- this[core_1.Symbols.modules].forEach((data) => data[0].files.forEach((file) => fs_1.default.watchFile(file, async () => {
226
- this.ctx.logger.debug(`file happen changed, module ${data[0].pkg.name} is reloading...`);
226
+ this[core_1.Symbols.modules].forEach((data) => data[0].files.forEach((file) => node_fs_1.default.watchFile(file, async () => {
227
+ this.ctx.logger.debug(this.ctx.format('loader.debug.reload', [data[0].pkg.name]));
227
228
  this.unloadEx(data[0]);
228
229
  this.loadEx(...data);
229
230
  })));
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.plugins = void 0;
7
- const fs_1 = require("fs");
8
- const path_1 = require("path");
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = require("node:path");
9
9
  const core_1 = require("@kotori-bot/core");
10
10
  const utils_1 = __importDefault(require("./utils"));
11
11
  function plugins(plugin) {
@@ -14,7 +14,7 @@ function plugins(plugin) {
14
14
  pkgName = plugin.name;
15
15
  }
16
16
  else {
17
- pkgName = JSON.parse((0, fs_1.readFileSync)((0, path_1.resolve)(...(Array.isArray(plugin) ? plugin : [plugin]), 'package.json')).toString()).name;
17
+ pkgName = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.resolve)(...(Array.isArray(plugin) ? plugin : [plugin]), 'package.json')).toString()).name;
18
18
  }
19
19
  const pluginName = pkgName.split(core_1.PLUGIN_PREFIX)[1] ?? pkgName;
20
20
  const ctx = core_1.Container.getInstance().extends(undefined, pluginName);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Decorators = void 0;
4
- const path_1 = require("path");
4
+ const node_path_1 = require("node:path");
5
5
  const core_1 = require("@kotori-bot/core");
6
6
  class Decorators {
7
7
  ctx;
@@ -32,7 +32,7 @@ class Decorators {
32
32
  lang = (target, property) => {
33
33
  this.register(() => {
34
34
  const lang = target[property];
35
- this.ctx.parent.i18n.use((0, path_1.resolve)(...(Array.isArray(lang) ? lang : [lang])));
35
+ this.ctx.parent.i18n.use((0, node_path_1.resolve)(...(Array.isArray(lang) ? lang : [lang])));
36
36
  })();
37
37
  };
38
38
  inject = (target, property) => {
@@ -2,16 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.File = void 0;
4
4
  const core_1 = require("@kotori-bot/core");
5
- const path_1 = require("path");
5
+ const node_path_1 = require("node:path");
6
6
  class File extends core_1.Service {
7
7
  constructor(ctx) {
8
8
  super(ctx, {}, 'file');
9
9
  }
10
10
  getDir() {
11
- return (0, path_1.join)(this.ctx.baseDir.data, ...(this.ctx.identity ? this.ctx.identity.split('/') : []));
11
+ return (0, node_path_1.join)(this.ctx.baseDir.data, ...(this.ctx.identity ? this.ctx.identity.split('/') : []));
12
12
  }
13
13
  getFile(filename) {
14
- return (0, path_1.join)(this.getDir(), filename);
14
+ return (0, node_path_1.join)(this.getDir(), filename);
15
15
  }
16
16
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
17
17
  load(filename, type, init) {
@@ -4,7 +4,7 @@
4
4
  /// <reference types="node" />
5
5
  import { Context, Service } from '@kotori-bot/core';
6
6
  import express from 'express';
7
- import { IncomingMessage } from 'http';
7
+ import { IncomingMessage } from 'node:http';
8
8
  import ws from 'ws';
9
9
  interface ServerConfig {
10
10
  port: number;
@@ -14,7 +14,7 @@ class Server extends core_1.Service {
14
14
  constructor(ctx, config) {
15
15
  super(ctx, config, 'server');
16
16
  this.app = (0, express_1.default)();
17
- this.app.use('/', (_, res, next) => {
17
+ this.app.use('/', (req, res, next) => {
18
18
  let isWebui = false;
19
19
  ctx[core_1.Symbols.modules].forEach((module) => {
20
20
  if (isWebui)
@@ -22,11 +22,12 @@ class Server extends core_1.Service {
22
22
  if (module[0].pkg.name === '@kotori-bot/kotori-plugin-webui')
23
23
  isWebui = true;
24
24
  });
25
- if (!isWebui) {
26
- res.setHeader('Content-type', 'text/html');
27
- res.send(/* html */ `<h1>Welcome to kotori!</h1>`);
25
+ if (isWebui || req.url !== '/') {
26
+ next();
27
+ return;
28
28
  }
29
- next();
29
+ res.setHeader('Content-type', 'text/html');
30
+ res.send(/* html */ `<h1>Welcome to kotori!</h1>`);
30
31
  });
31
32
  this.get = this.app.get.bind(this.app);
32
33
  this.post = this.app.post.bind(this.app);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kotori-bot/loader",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Loader For KotoriBot",
5
5
  "license": "GPL-3.0",
6
6
  "main": "lib/index.js",
@@ -28,8 +28,8 @@
28
28
  "express": "^4.18.2",
29
29
  "knex": "^3.1.0",
30
30
  "ws": "^8.14.2",
31
- "@kotori-bot/core": "^1.4.0",
32
- "@kotori-bot/logger": "^1.2.0"
31
+ "@kotori-bot/core": "^1.4.1",
32
+ "@kotori-bot/logger": "^1.2.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/body-parser": "^1.19.5",