mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
Merge pull request #122 from mariusbegby/bot-stats-improvements
fix: add support for new site and auto post shard count and member count
This commit is contained in:
2 files changed
+58
-10
No files matched your search
@@ -20,6 +20,7 @@ BOTLIST_DISCORDS_COM_API_TOKEN=
|
|||||||
BOTLIST_DISCORD_BOTS_GG_API_TOKEN=
|
BOTLIST_DISCORD_BOTS_GG_API_TOKEN=
|
||||||
BOTLIST_BOTLIST_ME_API_TOKEN=
|
BOTLIST_BOTLIST_ME_API_TOKEN=
|
||||||
BOTLIST_DISCORDLIST_GG_API_TOKEN=
|
BOTLIST_DISCORDLIST_GG_API_TOKEN=
|
||||||
|
BOTLIST_DISCORD_BOTLIST_EU_API_TOKEN=
|
||||||
|
|
||||||
# Optional: Only change this if you know what you are doing
|
# Optional: Only change this if you know what you are doing
|
||||||
NODE_OPTIONS=
|
NODE_OPTIONS=
|
||||||
|
|||||||
@@ -13,11 +13,19 @@ exports.postBotStats = async (client) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let guildCount = 0;
|
let guildCount = 0;
|
||||||
|
let memberCount = 0;
|
||||||
|
let shardCount = client.shard.count;
|
||||||
|
let shardId = client.shard.ids[0];
|
||||||
|
|
||||||
await client.shard
|
await client.shard
|
||||||
.fetchClientValues('guilds.cache.size')
|
.fetchClientValues('guilds.cache')
|
||||||
.then((results) => {
|
.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) => {
|
.catch((error) => {
|
||||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
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 */
|
/* eslint-disable camelcase */
|
||||||
const sites = [
|
const sites = [
|
||||||
{
|
{
|
||||||
|
enabled: false,
|
||||||
hostname: 'top.gg',
|
hostname: 'top.gg',
|
||||||
path: `/api/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
path: `/api/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { server_count: guildCount },
|
body: {
|
||||||
|
shard_id: shardId,
|
||||||
|
shard_count: shardCount,
|
||||||
|
server_count: guildCount
|
||||||
|
},
|
||||||
token: process.env.BOTLIST_TOP_GG_API_TOKEN
|
token: process.env.BOTLIST_TOP_GG_API_TOKEN
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
enabled: false,
|
||||||
hostname: 'discordbotlist.com',
|
hostname: 'discordbotlist.com',
|
||||||
path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { guilds: guildCount },
|
body: {
|
||||||
|
shard_id: shardId,
|
||||||
|
users: memberCount,
|
||||||
|
guilds: guildCount
|
||||||
|
},
|
||||||
token: process.env.BOTLIST_DISCORD_BOT_LIST_COM_API_TOKEN
|
token: process.env.BOTLIST_DISCORD_BOT_LIST_COM_API_TOKEN
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
enabled: false,
|
||||||
hostname: 'discords.com',
|
hostname: 'discords.com',
|
||||||
path: `/bots/api/bot/${process.env.DISCORD_APPLICATION_ID}`,
|
path: `/bots/api/bot/${process.env.DISCORD_APPLICATION_ID}`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { server_count: guildCount },
|
body: {
|
||||||
|
server_count: guildCount
|
||||||
|
},
|
||||||
token: process.env.BOTLIST_DISCORDS_COM_API_TOKEN
|
token: process.env.BOTLIST_DISCORDS_COM_API_TOKEN
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
enabled: false,
|
||||||
hostname: 'discord.bots.gg',
|
hostname: 'discord.bots.gg',
|
||||||
path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { guildCount: guildCount },
|
body: {
|
||||||
|
shardId: shardId,
|
||||||
|
shardCount: shardCount,
|
||||||
|
guildCount: guildCount
|
||||||
|
},
|
||||||
token: process.env.BOTLIST_DISCORD_BOTS_GG_API_TOKEN
|
token: process.env.BOTLIST_DISCORD_BOTS_GG_API_TOKEN
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
enabled: false,
|
||||||
hostname: 'api.botlist.me',
|
hostname: 'api.botlist.me',
|
||||||
path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { server_count: guildCount },
|
body: {
|
||||||
|
shard_count: shardCount,
|
||||||
|
server_count: guildCount
|
||||||
|
},
|
||||||
token: process.env.BOTLIST_BOTLIST_ME_API_TOKEN
|
token: process.env.BOTLIST_BOTLIST_ME_API_TOKEN
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
enabled: false,
|
||||||
hostname: 'api.discordlist.gg',
|
hostname: 'api.discordlist.gg',
|
||||||
path: `/v0/bots/${process.env.DISCORD_APPLICATION_ID}/guilds?count=${guildCount}`,
|
path: `/v0/bots/${process.env.DISCORD_APPLICATION_ID}/guilds`,
|
||||||
method: 'PUT',
|
method: 'POST',
|
||||||
body: {},
|
body: {
|
||||||
|
count: guildCount
|
||||||
|
},
|
||||||
token: `Bearer ${process.env.BOTLIST_DISCORDLIST_GG_API_TOKEN}`
|
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}...`);
|
logger.info(`[Shard ${client.shard.ids[0]}] Posting stats to bot lists with guildCount ${guildCount}...`);
|
||||||
sites.map((site) => {
|
sites.map((site) => {
|
||||||
|
if (site.disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
protocol: 'https:',
|
protocol: 'https:',
|
||||||
hostname: site.hostname,
|
hostname: site.hostname,
|
||||||
|
|||||||
Reference in new issue
Block a user