feat!: Sharding implemented across the bot

This commit is contained in:
Marius Begby committed 2023-07-21 14:17:04 +02:00
1 parent b160cbf564
commit 9c15c636d9
29 files changed
+270 -142

No files matched your search

+14 -11
View File
@@ -7,20 +7,23 @@ module.exports = {
isDebug: false,
once: false,
execute: async (client) => {
logger.warn(`${client.user.tag} lost connection to Discord APIs. Disconnected.`);
logger.warn(`[Shard ${client.shard.ids[0]}] ${client.user.tag} lost connection to Discord APIs. Disconnected.`);
// send message to system message channel for event
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
await client.channels.cache.get(systemOptions.systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`disconnected\`**!` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.warning)
]
});
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
if (channel) {
await channel.send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`disconnected\`**!` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.warning)
]
});
}
}
}
};
+1 -1
View File
@@ -6,6 +6,6 @@ module.exports = {
isDebug: false,
once: false,
execute: async (guild) => {
logger.info(`Shard ${guild.shardId}> Added to guild '${guild.name}' with ${guild.memberCount} members.`);
logger.info(`[Shard ${guild.shardId}] Added to guild '${guild.name}' with ${guild.memberCount} members.`);
}
};
+1 -1
View File
@@ -7,7 +7,7 @@ module.exports = {
once: false,
execute: async (guild) => {
logger.info(
`Shard ${guild.shardId}> Removed from guild '${guild.name}' with ${guild.memberCount} members.`
`[Shard ${guild.shardId}] Removed from guild '${guild.name}' with ${guild.memberCount} members.`
);
}
};
+2 -2
View File
@@ -8,7 +8,7 @@ module.exports = {
isDebug: false,
once: false,
execute: async (client) => {
logger.debug(`Shard ${client.shard.ids[0]}> Client 'ready' event emitted after 'allShardsReady'.`);
logger.debug(`[Shard ${client.shard.ids[0]}] Client 'ready' event emitted after 'allShardsReady'.`);
await client.user.setPresence(presenceStatusOptions);
await client.user.setPresence(presenceStatusOptions);
@@ -17,7 +17,7 @@ module.exports = {
// Check if the channel exists in curent shard and send a message
if (channel) {
logger.info(
`Shard ${client.shard.ids[0]}> All shards ready, sending system message to channel id ${channel.id}.`
`[Shard ${client.shard.ids[0]}] ALL SHARDS READY, sending system message to channel id ${channel.id}.`
);
channel.send({
embeds: [
+16 -11
View File
@@ -7,20 +7,25 @@ module.exports = {
isDebug: false,
once: false,
execute: async (client) => {
logger.warn(`${client.user.tag} is reconnecting to Discord APIs.`);
logger.warn(`[Shard ${client.shard.ids[0]}] ${client.user.tag} is reconnecting to Discord APIs.`);
// send message to system message channel for event
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
await client.channels.cache.get(systemOptions.systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`reconnecting\`**!` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.warning)
]
});
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
if (channel) {
await channel.send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.warning} **${client.user.tag}** is **\`reconnecting\`**!` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.warning)
]
});
}
}
}
}
};
+7 -5
View File
@@ -12,7 +12,9 @@ module.exports = {
const command = client.commands.get(interaction.commandName);
if (!command) {
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
logger.warn(
`[Shard ${interaction.guild.shardId}] Interaction created but command '${interaction.commandName}' was not found.`
);
return;
}
@@ -32,13 +34,13 @@ module.exports = {
executionTime > 55000
) {
logger.info(
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' executed in ${executionTime} ms.`
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Command '${interaction}' executed in ${executionTime} ms.`
);
return;
}
logger.warn(
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' took ${executionTime} ms to execute.`
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Command '${interaction}' took ${executionTime} ms to execute.`
);
return await interaction.followUp({
@@ -54,13 +56,13 @@ module.exports = {
});
} else {
logger.info(
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' executed in ${executionTime} ms.`
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Command '${interaction}' executed in ${executionTime} ms.`
);
}
} catch (error) {
logger.error(
error,
`(${interaction.guild.memberCount}) ${interaction.guild.name}> Command '${interaction}' failed to execute.`
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Command '${interaction}' failed to execute.`
);
await interaction.followUp({
+17 -11
View File
@@ -8,7 +8,10 @@ module.exports = {
isDebug: false,
isPlayerEvent: true,
execute: async (queue, error) => {
logger.error(error, 'player.events.on(\'error\'): Player queue encountered error event');
logger.error(
error,
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('error'): Player queue encountered error event`
);
await queue.metadata.channel.send({
embeds: [
@@ -21,16 +24,19 @@ module.exports = {
});
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.error} **player.events.on('error')**\n${error.message}` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.error)
]
});
const channel = await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId);
if (channel) {
await channel.send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.error} **player.events.on('error')**\n${error.message}` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.error)
]
});
}
}
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
+17 -11
View File
@@ -8,7 +8,10 @@ module.exports = {
isDebug: false,
isPlayerEvent: true,
execute: async (queue, error) => {
logger.error(error, 'player.events.on(\'playerError\'): Player error while streaming track');
logger.error(
error,
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('playerError'): Player error while streaming track`
);
await queue.metadata.channel.send({
embeds: [
@@ -21,16 +24,19 @@ module.exports = {
});
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.error} **player.events.on('playerError')**\n${error.message}` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.error)
]
});
const channel = await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId);
if (channel) {
await channel.send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.error} **player.events.on('playerError')**\n${error.message}` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.error)
]
});
}
}
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
+16 -11
View File
@@ -8,7 +8,9 @@ module.exports = {
isDebug: false,
isPlayerEvent: true,
execute: async (queue, track) => {
logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.`);
logger.error(
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('playerSkip'): Failed to play '${track.url}'.`
);
await queue.metadata.channel.send({
embeds: [
@@ -21,16 +23,19 @@ module.exports = {
});
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId).send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.error} **player.events.on('playerSkip')**\n${track.url}` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.error)
]
});
const channel = await queue.metadata.client.channels.cache.get(systemOptions.systemMessageChannelId);
if (channel) {
await channel.send({
embeds: [
new EmbedBuilder()
.setDescription(
`${embedOptions.icons.error} **player.events.on('playerSkip')**\n${track.url}` +
`\n\n<@${systemOptions.systemUserId}>`
)
.setColor(embedOptions.colors.error)
]
});
}
}
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
+3 -1
View File
@@ -5,7 +5,9 @@ module.exports = {
isDebug: false,
isPlayerEvent: true,
execute: async (queue, track) => {
logger.debug(`playerStart event: Started playing '${track.raw.source}'.`);
logger.debug(
`[Shard ${queue.metadata.client.shard.ids[0]}] playerStart event: Started playing '${track.raw.source}'.`
);
process.env.NODE_ENV === 'development' ? logger.trace(queue) : null;
}
};