mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-02 00:31:27 +03:00
Logger and fastify, settings server
This commit is contained in:
10
src/index.js
10
src/index.js
@@ -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
34
src/server/index.js
Normal 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' };
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user