Logger and fastify, settings server

This commit is contained in:
Isaac
2021-02-25 12:34:16 +00:00
parent a0b1853bff
commit 1f2d40234b
5 changed files with 460 additions and 9 deletions

View File

@@ -60,7 +60,7 @@ const config = require('../user/config');
require('./banner')();
const Logger = require('leekslazylogger');
const Logger = require('leekslazylogger-fastify');
const log = new Logger({
name: 'DiscordTickets by eartharoid',
debug: config.debug,
@@ -72,6 +72,10 @@ const log = new Logger({
title: 'info',
prefix: 'commands'
},
http: {
title: 'info',
prefix: 'http'
},
plugins: {
title: 'info',
prefix: 'plugins'
@@ -88,6 +92,7 @@ const I18n = require('@eartharoid/i18n');
const { CommandManager } = require('./modules/commands');
const TicketManager = require('./modules/tickets');
const { PluginManager } = require('./modules/plugins');
const SettingsServer = require('./server');
require('./modules/structures')(); // load extended structures before creating the client
@@ -142,6 +147,9 @@ class Bot extends Client {
this.plugins = new PluginManager(this);
this.plugins.load(); // load plugins
/** SettingsServer internal plugin instance */
this.server = new SettingsServer(this);
this.log.info('Connecting to Discord API...');
this.login();

34
src/server/index.js Normal file
View File

@@ -0,0 +1,34 @@
const { Plugin } = require('../modules/plugins');
const fastify = require('fastify')();
module.exports = class SettingsServer extends Plugin {
constructor(client){
super(client, {
id: 'internal.settings'
}, {
name: 'Settings server',
commands: []
});
this.client.plugins.plugins.set(this.id, this);
this.preload();
}
async preload() {
fastify.register(this.client.log.fastify, {
type: 'http'
});
}
async load() {
fastify.listen(process.env.HTTP_PORT || 8080, (err, address) => {
if (err) throw err;
this.client.log.info(`Settings server listening at ${address}`);
});
fastify.get('/', async (req, res) => {
res.type('application/json').code(200);
return { hello: 'world' };
});
}
};