From 520cfd14b838d236768ec46f8b3fbee4a8118527 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Mon, 16 Dec 2019 17:35:09 +0100 Subject: [PATCH] exposeStats parameter --- config-exemple.jsonc | 1 + event/listeners/ready.js | 77 +++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/config-exemple.jsonc b/config-exemple.jsonc index de43fc0..b6cd366 100644 --- a/config-exemple.jsonc +++ b/config-exemple.jsonc @@ -7,6 +7,7 @@ "ownerID": "Id of the owner ( probably you )", //optional but recommended "statsChannel": "channel where the bot send his stats", //optional but recommended "supportServer": "Invite to the support server of the bot", //optional but recommended + "exposeStats": true, // False or true, it open a webserver that expose various stats about the bot "feedbackChannel": "id of the channel where the feedback goes", //optional but recommended "yandexAPI": "yandex api key", //optional | for the translate command "acoustID": "acoust api key", //optional | for the music match command diff --git a/event/listeners/ready.js b/event/listeners/ready.js index ed6013e..802ae5e 100644 --- a/event/listeners/ready.js +++ b/event/listeners/ready.js @@ -2,7 +2,7 @@ const { Listener } = require('discord-akairo'); const akairoVersion = require('discord-akairo').version; const djsVersion = require('discord.js').version; const pjson = require('../../package.json'); -const { prefix, statsChannel, ownerID, supportServer } = require('../../config.json'); +const { prefix, statsChannel, ownerID, supportServer, exposeStats } = require('../../config.json'); const game = require('../../json/status/playing.json'); const watch = require('../../json/status/watching.json'); @@ -73,44 +73,47 @@ class ReadyListener extends Listener { */ // Expose stats - const port = 3000; + if (exposeStats) { + const port = 3000; - const http = require('http'); - - const requestHandler = (req, res) => { - // Refresh some info - commandSize = this.client.commandHandler.modules.size; - guildSize = this.client.guilds.size; - userSize = this.client.users.size; - profilePicture = this.client.user.displayAvatarURL(); - - let response = { - 'commandSize': commandSize, - 'ClientTag': clientTag, - 'guildSize': guildSize, - 'userSize': userSize, - 'prefixSize': prefix.length, - 'profilePicture': profilePicture, - 'clientID': clientID, - 'djsVersion': djsVersion, - 'akairoVersion': akairoVersion, - 'homepage': pjson.homepage, - 'author': author, - 'supportServer': supportServer + const http = require('http'); + + const requestHandler = (req, res) => { + // Refresh some info + commandSize = this.client.commandHandler.modules.size; + guildSize = this.client.guilds.size; + userSize = this.client.users.size; + profilePicture = this.client.user.displayAvatarURL(); + + let response = { + 'commandSize': commandSize, + 'ClientTag': clientTag, + 'guildSize': guildSize, + 'userSize': userSize, + 'prefixSize': prefix.length, + 'profilePicture': profilePicture, + 'clientID': clientID, + 'djsVersion': djsVersion, + 'akairoVersion': akairoVersion, + 'homepage': pjson.homepage, + 'author': author, + 'supportServer': supportServer + }; + res.statusCode = 200; + res.setHeader('Content-Type', 'application/json'); + res.end(JSON.stringify(response)); }; - res.statusCode = 200; - res.setHeader('Content-Type', 'application/json'); - res.end(JSON.stringify(response)); - }; - - const server = http.createServer(requestHandler); - - server.listen(port, (err) => { - if (err) { - return console.log('something bad happened', err); - } - }); - console.log(`Exposing stats on port ${port}`); + + const server = http.createServer(requestHandler); + + server.listen(port, (err) => { + if (err) { + return console.log('something bad happened', err); + } + }); + console.log(`Exposing stats on port ${port}`); + } + console.log('===========[ READY ]==========='); }