Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix: add support for new site and auto post shard count and member count
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Jul 26, 2023
1 parent 3d35e4b commit 8713baa
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
67 changes: 57 additions & 10 deletions src/utils/other/postBotStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Expand All @@ -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,
Expand Down

0 comments on commit 8713baa

Please # to comment.