diff --git a/.env.example b/.env.example index b6ee260..26c806f 100644 --- a/.env.example +++ b/.env.example @@ -20,6 +20,7 @@ BOTLIST_DISCORDS_COM_API_TOKEN= BOTLIST_DISCORD_BOTS_GG_API_TOKEN= BOTLIST_BOTLIST_ME_API_TOKEN= BOTLIST_DISCORDLIST_GG_API_TOKEN= +BOTLIST_DISCORD_BOTLIST_EU_API_TOKEN= # Optional: Only change this if you know what you are doing NODE_OPTIONS= diff --git a/src/utils/other/postBotStats.js b/src/utils/other/postBotStats.js index f3eb179..2864503 100644 --- a/src/utils/other/postBotStats.js +++ b/src/utils/other/postBotStats.js @@ -13,11 +13,19 @@ exports.postBotStats = async (client) => { ); let guildCount = 0; + let memberCount = 0; + let shardCount = client.shard.count; + let shardId = client.shard.ids[0]; await client.shard - .fetchClientValues('guilds.cache.size') + .fetchClientValues('guilds.cache') .then((results) => { - guildCount = results.reduce((acc, guildCount) => acc + guildCount, 0); + results.map((guildCache) => { + if (guildCache) { + guildCount += guildCache.length; + memberCount += guildCache.reduce((acc, guildCache) => acc + guildCache.memberCount, 0); + } + }); }) .catch((error) => { logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`); @@ -26,51 +34,90 @@ exports.postBotStats = async (client) => { /* eslint-disable camelcase */ const sites = [ { + enabled: false, hostname: 'top.gg', path: `/api/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', - body: { server_count: guildCount }, + body: { + shard_id: shardId, + shard_count: shardCount, + server_count: guildCount + }, token: process.env.BOTLIST_TOP_GG_API_TOKEN }, { + enabled: false, hostname: 'discordbotlist.com', path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', - body: { guilds: guildCount }, + body: { + shard_id: shardId, + users: memberCount, + guilds: guildCount + }, token: process.env.BOTLIST_DISCORD_BOT_LIST_COM_API_TOKEN }, { + enabled: false, hostname: 'discords.com', path: `/bots/api/bot/${process.env.DISCORD_APPLICATION_ID}`, method: 'POST', - body: { server_count: guildCount }, + body: { + server_count: guildCount + }, token: process.env.BOTLIST_DISCORDS_COM_API_TOKEN }, { + enabled: false, hostname: 'discord.bots.gg', path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', - body: { guildCount: guildCount }, + body: { + shardId: shardId, + shardCount: shardCount, + guildCount: guildCount + }, token: process.env.BOTLIST_DISCORD_BOTS_GG_API_TOKEN }, { + enabled: false, hostname: 'api.botlist.me', path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', - body: { server_count: guildCount }, + body: { + shard_count: shardCount, + server_count: guildCount + }, token: process.env.BOTLIST_BOTLIST_ME_API_TOKEN }, { + enabled: false, hostname: 'api.discordlist.gg', - path: `/v0/bots/${process.env.DISCORD_APPLICATION_ID}/guilds?count=${guildCount}`, - method: 'PUT', - body: {}, + path: `/v0/bots/${process.env.DISCORD_APPLICATION_ID}/guilds`, + method: 'POST', + body: { + count: guildCount + }, token: `Bearer ${process.env.BOTLIST_DISCORDLIST_GG_API_TOKEN}` + }, + { + enabled: false, + hostname: 'api.discord-botlist.eu', + path: '/v1/update', + method: 'PATCH', + body: { + serverCount: guildCount + }, + token: `Bearer ${process.env.BOTLIST_DISCORD_BOTLIST_EU_API_TOKEN}` } ]; logger.info(`[Shard ${client.shard.ids[0]}] Posting stats to bot lists with guildCount ${guildCount}...`); sites.map((site) => { + if (site.disabled) { + return; + } + let options = { protocol: 'https:', hostname: site.hostname,