mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 06:28:53 +00:00
feat!: Sharding implemented across the bot
This commit is contained in:
1 parent
b160cbf564
commit
9c15c636d9
29 files changed
+270
-142
No files matched your search
@@ -4,7 +4,7 @@ const { stream } = require('yt-stream');
|
||||
|
||||
exports.createPlayer = async (client) => {
|
||||
try {
|
||||
logger.info('Creating discord-player player...');
|
||||
logger.info(`[Shard ${client.shard.ids[0]}] Creating discord-player player...`);
|
||||
|
||||
const player = new Player(client, {
|
||||
useLegacyFFmpeg: false,
|
||||
@@ -35,11 +35,11 @@ exports.createPlayer = async (client) => {
|
||||
});
|
||||
|
||||
await player.extractors.loadDefault();
|
||||
logger.debug(`discord-player loaded dependencies:\n${player.scanDeps()}`);
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] discord-player loaded dependencies:\n${player.scanDeps()}`);
|
||||
|
||||
return player;
|
||||
} catch (error) {
|
||||
logger.error('Failed to create discord-player player', error);
|
||||
logger.error(`[Shard ${client.shard.ids[0]}] Failed to create discord-player player`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -4,12 +4,12 @@ const https = require('node:https');
|
||||
exports.postBotStats = async (client) => {
|
||||
try {
|
||||
if (client.shard.ids[0] !== 0) {
|
||||
return logger.debug(`Shard ${client.shard.ids[0]}> Shard is not the first shard, not posting stats.`);
|
||||
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.`
|
||||
`[Shard ${client.shard.ids[0]}] Posting stats to bot lists from client with shard id 0.`
|
||||
);
|
||||
|
||||
let guildCount = 0;
|
||||
@@ -20,7 +20,7 @@ exports.postBotStats = async (client) => {
|
||||
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.`);
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
||||
});
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
@@ -69,7 +69,7 @@ exports.postBotStats = async (client) => {
|
||||
}
|
||||
];
|
||||
|
||||
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) => {
|
||||
let options = {
|
||||
protocol: 'https:',
|
||||
@@ -93,6 +93,6 @@ exports.postBotStats = async (client) => {
|
||||
request.end();
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error, `Shard ${client.shard.ids[0]}> Failed to post stats to bot lists.`);
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to post stats to bot lists.`);
|
||||
}
|
||||
};
|
||||
@@ -4,7 +4,7 @@ const path = require('node:path');
|
||||
const { Collection } = require('discord.js');
|
||||
|
||||
exports.registerClientCommands = (client) => {
|
||||
logger.debug('Registering client commands...');
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering client commands...`);
|
||||
client.commands = new Collection();
|
||||
|
||||
const commandFolders = fs.readdirSync(path.resolve('./src/commands'));
|
||||
@@ -15,11 +15,13 @@ exports.registerClientCommands = (client) => {
|
||||
|
||||
for (const file of commandFiles) {
|
||||
try {
|
||||
logger.debug(`Registering command ${folder}/${file}...`);
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering command ${folder}/${file}...`);
|
||||
const command = require(`../commands/${folder}/${file}`);
|
||||
client.commands.set(command.data.name, command);
|
||||
} catch (error) {
|
||||
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
||||
logger.error(
|
||||
`[Shard ${client.shard.ids[0]}] Error registering command ${folder}/${file}: ${error.message}`
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
exports.registerEventListeners = (client, player) => {
|
||||
logger.debug('Registering event listeners...');
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering event listeners...`);
|
||||
|
||||
const eventFolders = fs.readdirSync(path.resolve('./src/events'));
|
||||
for (const folder of eventFolders) {
|
||||
@@ -15,7 +15,7 @@ exports.registerEventListeners = (client, player) => {
|
||||
const event = require(`../events/${folder}/${file}`);
|
||||
switch (folder) {
|
||||
case 'client':
|
||||
logger.debug(`Registering client event listener ${event.name}...`);
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering client event listener ${event.name}...`);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
} else {
|
||||
@@ -26,17 +26,19 @@ exports.registerEventListeners = (client, player) => {
|
||||
break;
|
||||
|
||||
case 'interactions':
|
||||
logger.debug(`Registering interactions event listener ${event.name}...`);
|
||||
logger.debug(
|
||||
`[Shard ${client.shard.ids[0]}] Registering interactions event listener ${event.name}...`
|
||||
);
|
||||
client.on(event.name, (...args) => event.execute(...args, { client }));
|
||||
break;
|
||||
|
||||
case 'process':
|
||||
logger.debug(`Registering process event listener ${event.name}...`);
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering process event listener ${event.name}...`);
|
||||
process.on(event.name, (...args) => event.execute(...args));
|
||||
break;
|
||||
|
||||
case 'player':
|
||||
logger.debug(`Registering player event listener ${event.name}...`);
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering player event listener ${event.name}...`);
|
||||
if (
|
||||
!event.isDebug ||
|
||||
process.env.NODE_ENV === 'development' ||
|
||||
@@ -52,7 +54,9 @@ exports.registerEventListeners = (client, player) => {
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.error(`Unknown event folder '${folder}' while trying to register events.`);
|
||||
logger.error(
|
||||
`[Shard ${client.shard.ids[0]}] Unknown event folder '${folder}' while trying to register events.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user