exposeStats parameter

This commit is contained in:
loicbersier 2019-12-16 17:35:09 +01:00
parent 325687a244
commit 520cfd14b8
2 changed files with 41 additions and 37 deletions

View file

@ -7,6 +7,7 @@
"ownerID": "Id of the owner ( probably you )", //optional but recommended "ownerID": "Id of the owner ( probably you )", //optional but recommended
"statsChannel": "channel where the bot send his stats", //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 "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 "feedbackChannel": "id of the channel where the feedback goes", //optional but recommended
"yandexAPI": "yandex api key", //optional | for the translate command "yandexAPI": "yandex api key", //optional | for the translate command
"acoustID": "acoust api key", //optional | for the music match command "acoustID": "acoust api key", //optional | for the music match command

View file

@ -2,7 +2,7 @@ const { Listener } = require('discord-akairo');
const akairoVersion = require('discord-akairo').version; const akairoVersion = require('discord-akairo').version;
const djsVersion = require('discord.js').version; const djsVersion = require('discord.js').version;
const pjson = require('../../package.json'); 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 game = require('../../json/status/playing.json');
const watch = require('../../json/status/watching.json'); const watch = require('../../json/status/watching.json');
@ -73,44 +73,47 @@ class ReadyListener extends Listener {
*/ */
// Expose stats // Expose stats
const port = 3000; if (exposeStats) {
const port = 3000;
const http = require('http'); const http = require('http');
const requestHandler = (req, res) => { const requestHandler = (req, res) => {
// Refresh some info // Refresh some info
commandSize = this.client.commandHandler.modules.size; commandSize = this.client.commandHandler.modules.size;
guildSize = this.client.guilds.size; guildSize = this.client.guilds.size;
userSize = this.client.users.size; userSize = this.client.users.size;
profilePicture = this.client.user.displayAvatarURL(); profilePicture = this.client.user.displayAvatarURL();
let response = { let response = {
'commandSize': commandSize, 'commandSize': commandSize,
'ClientTag': clientTag, 'ClientTag': clientTag,
'guildSize': guildSize, 'guildSize': guildSize,
'userSize': userSize, 'userSize': userSize,
'prefixSize': prefix.length, 'prefixSize': prefix.length,
'profilePicture': profilePicture, 'profilePicture': profilePicture,
'clientID': clientID, 'clientID': clientID,
'djsVersion': djsVersion, 'djsVersion': djsVersion,
'akairoVersion': akairoVersion, 'akairoVersion': akairoVersion,
'homepage': pjson.homepage, 'homepage': pjson.homepage,
'author': author, 'author': author,
'supportServer': supportServer '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); 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}`);
}
server.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err);
}
});
console.log(`Exposing stats on port ${port}`);
console.log('===========[ READY ]==========='); console.log('===========[ READY ]===========');
} }