mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
fix: add support for new site and auto post shard count and member count
This commit is contained in:
1 parent
3d35e4b8f4
commit
8713baa657
2 files changed
+58
-10
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user