This commit is contained in:
23
app.js
23
app.js
@ -3,6 +3,7 @@ import { join } from 'path';
|
||||
import CreateBot from '#root/bot/index.js';
|
||||
import CreateWebhookServer from '#root/http/index.js';
|
||||
import logger from '#root/utils/logger.js';
|
||||
import handlers from './handlers';
|
||||
|
||||
let retryCount = 0;
|
||||
|
||||
@ -37,17 +38,17 @@ let retryCount = 0;
|
||||
const webhook = new CreateWebhookServer();
|
||||
|
||||
logger('开始引入handler函数');
|
||||
const files = fs.readdirSync('./handlers');
|
||||
const handlers = files
|
||||
.filter((it) => /\.js$/.test(it))
|
||||
.map((it) => {
|
||||
let fPath = join(__dirname, './handlers', it);
|
||||
return {
|
||||
event: it.split('.').slice(0, -1).join('.'),
|
||||
handler: require(fPath).bind(this, bot),
|
||||
};
|
||||
});
|
||||
webhook.registerHanlder(handlers);
|
||||
// const files = fs.readdirSync('./handlers');
|
||||
// const handlers = files
|
||||
// .filter((it) => /\.js$/.test(it))
|
||||
// .map((it) => {
|
||||
// let fPath = join(__dirname, './handlers', it);
|
||||
// return {
|
||||
// event: it.split('.').slice(0, -1).join('.'),
|
||||
// handler: require(fPath).bind(this, bot),
|
||||
// };
|
||||
// });
|
||||
webhook.registerHandler(handlers.map(i => ({ event: i.event, handler: i.handler.bind(this, bot) })));
|
||||
|
||||
webhook.startListen(port);
|
||||
logger(`开始监听端口: ${port}`);
|
||||
|
Reference in New Issue
Block a user