|
@@ -2,7 +2,7 @@ require('dotenv').config();
|
|
|
|
|
|
const isDebug = ( process.argv[2] === 'debug' );
|
|
|
const got = require('got').extend( {
|
|
|
- throwHttpErrors: true,
|
|
|
+ throwHttpErrors: false,
|
|
|
timeout: 5000,
|
|
|
headers: {
|
|
|
'User-Agent': 'Wiki-Bot/' + ( isDebug ? 'testing' : process.env.npm_package_version ) + ' (Discord; ' + process.env.npm_package_name + ')'
|
|
@@ -49,63 +49,43 @@ manager.on( 'shardCreate', shard => {
|
|
|
} );
|
|
|
|
|
|
manager.spawn().then( shards => {
|
|
|
- if ( !isDebug ) setInterval( postStats, 10800000, shards.size ).unref();
|
|
|
+ if ( !isDebug ) {
|
|
|
+ var botList = JSON.parse(process.env.botlist);
|
|
|
+ for ( let [key, value] of Object.entries(botList) ) {
|
|
|
+ if ( !value ) delete botList[key];
|
|
|
+ }
|
|
|
+ setInterval( postStats, 10800000, botList, shards.size ).unref();
|
|
|
+ }
|
|
|
}, error => {
|
|
|
console.error( '- Error while spawning the shards: ' + error );
|
|
|
manager.respawnAll();
|
|
|
} );
|
|
|
|
|
|
-function postStats(shardCount = manager.totalShards) {
|
|
|
+function postStats(botList = JSON.parse(process.env.botlist), shardCount = manager.totalShards) {
|
|
|
manager.fetchClientValues('guilds.cache.size').then( results => {
|
|
|
var guildCount = results.reduce( (acc, val) => acc + val, 0 );
|
|
|
console.log( '- Current server count: ' + guildCount + '\n' + results.map( (count, i) => {
|
|
|
return '-- Shard[' + i + ']: ' + count;
|
|
|
} ).join('\n') );
|
|
|
- if ( process.env.toptoken ) got.post( 'https://top.gg/api/bots/' + process.env.bot + '/stats', {
|
|
|
- headers: {
|
|
|
- Authorization: process.env.toptoken
|
|
|
- },
|
|
|
- json: {
|
|
|
+ got.post( 'https://botblock.org/api/count', {
|
|
|
+ json: Object.assign( {
|
|
|
+ bot_id: process.env.bot,
|
|
|
server_count: guildCount,
|
|
|
- shards: results,
|
|
|
- shard_count: shardCount
|
|
|
- },
|
|
|
- responseType: 'json'
|
|
|
- } ).catch( error => {
|
|
|
- console.log( '- Error while posting statistics to https://top.gg/bot/' + process.env.bot + ': ' + error );
|
|
|
- } );
|
|
|
- if ( process.env.dbggtoken ) got.post( 'https://discord.bots.gg/api/v1/bots/' + process.env.bot + '/stats', {
|
|
|
- headers: {
|
|
|
- Authorization: process.env.dbggtoken
|
|
|
- },
|
|
|
- json: {
|
|
|
- guildCount: guildCount
|
|
|
- },
|
|
|
- responseType: 'json'
|
|
|
- } ).catch( error => {
|
|
|
- console.log( '- Error while posting statistics to https://discord.bots.gg/bots/' + process.env.bot + ': ' + error );
|
|
|
- } );
|
|
|
- if ( process.env.bodtoken ) got.post( 'https://bots.ondiscord.xyz/bot-api/bots/' + process.env.bot + '/guilds', {
|
|
|
- headers: {
|
|
|
- Authorization: process.env.bodtoken
|
|
|
- },
|
|
|
- json: {
|
|
|
- guildCount: guildCount
|
|
|
- },
|
|
|
- responseType: 'json'
|
|
|
- } ).catch( error => {
|
|
|
- console.log( '- Error while posting statistics to https://bots.ondiscord.xyz/bots/' + process.env.bot + ': ' + error );
|
|
|
- } );
|
|
|
- if ( process.env.dbltoken ) got.post( 'https://discordbotlist.com/api/v1/bots/' + process.env.bot + '/stats', {
|
|
|
- headers: {
|
|
|
- Authorization: process.env.dbltoken
|
|
|
- },
|
|
|
- json: {
|
|
|
- guilds: guildCount
|
|
|
- },
|
|
|
+ shard_count: shardCount,
|
|
|
+ shards: results
|
|
|
+ }, botList ),
|
|
|
responseType: 'json'
|
|
|
- } ).catch( error => {
|
|
|
- console.log( '- Error while posting statistics to https://discordbotlist.com/bots/' + process.env.bot + ': ' + error );
|
|
|
+ } ).then( response => {
|
|
|
+ var body = response.body;
|
|
|
+ if ( response.statusCode !== 200 || !body || body.error ) {
|
|
|
+ console.log( '- ' + response.statusCode + ': Error while posting statistics to BotBlock.org: ' + ( body && body.message ) );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for ( let [key, value] of Object.entries(body.failure) ) {
|
|
|
+ console.log( '- ' + value[0] + ': Error while posting statistics to ' + key + ': ' + value[1] );
|
|
|
+ }
|
|
|
+ }, error => {
|
|
|
+ console.log( '- Error while posting statistics to BotBlock.org: ' + error );
|
|
|
} );
|
|
|
}, error => console.log( '- Error while getting the guild count: ' + error ) );
|
|
|
}
|