mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
feat: update ready events to handle sharding
This commit is contained in:
1 parent
006f2fab51
commit
184b528f56
4 files changed
+55
-17
No files matched your search
@@ -1,9 +1,27 @@
|
||||
const logger = require('../../services/logger');
|
||||
const https = require('node:https');
|
||||
|
||||
exports.postBotStats = (client) => {
|
||||
exports.postBotStats = async (client) => {
|
||||
try {
|
||||
const guildCount = client.guilds.cache.size;
|
||||
if (client.shard.ids[0] !== 0) {
|
||||
return logger.debug(`Shard ${client.shard.ids[0]}> Shard is not the first shard, not posting stats.`);
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
client.shard.ids,
|
||||
`Shard ${client.shard.ids[0]}> Posting stats to bot lists from client with shard id 0.`
|
||||
);
|
||||
|
||||
let guildCount = 0;
|
||||
|
||||
await client.shard
|
||||
.fetchClientValues('guilds.cache.size')
|
||||
.then((results) => {
|
||||
guildCount = results.reduce((acc, guildCount) => acc + guildCount, 0);
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(error, `Shard ${client.shard.ids[0]}> Failed to fetch client values from shards.`);
|
||||
});
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
const sites = [
|
||||
@@ -51,7 +69,7 @@ exports.postBotStats = (client) => {
|
||||
}
|
||||
];
|
||||
|
||||
logger.info(`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) => {
|
||||
let options = {
|
||||
protocol: 'https:',
|
||||
@@ -75,6 +93,6 @@ exports.postBotStats = (client) => {
|
||||
request.end();
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error, 'Failed to post stats to bot lists');
|
||||
logger.error(error, `Shard ${client.shard.ids[0]}> Failed to post stats to bot lists.`);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user