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

+15 -5
View File
@@ -78,7 +78,9 @@ module.exports = {
],
components: [filterActionRow, disableFiltersActionRow]
});
logger.debug(`Sent embed for command ${interaction.commandName}, awaiting interaction response.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Sent embed for command ${interaction.commandName}, awaiting interaction response.`
);
const collectorFilter = (i) => i.user.id === interaction.user.id;
try {
@@ -87,7 +89,9 @@ module.exports = {
time: 60000
});
logger.debug(`Received interaction response for command ${interaction.commandName}.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Received interaction response for command ${interaction.commandName}.`
);
confirmation.deferUpdate();
@@ -128,7 +132,11 @@ module.exports = {
// Enable provided filters
queue.filters.ffmpeg.toggle(confirmation.values);
logger.debug(`Enabled filters ${confirmation.values.join(', ')} for command ${interaction.commandName}.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Enabled filters ${confirmation.values.join(', ')} for command ${
interaction.commandName
}.`
);
return await interaction.editReply({
embeds: [
@@ -157,13 +165,15 @@ module.exports = {
});
} catch (error) {
if (error.code === 'InteractionCollectorError') {
logger.debug(`Interaction response timed out for command ${interaction.commandName}.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Interaction response timed out for command ${interaction.commandName}.`
);
return;
}
logger.debug(
error,
`Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.`
`[Shard ${interaction.guild.shardId}] Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.`
);
throw error;
}
+6 -2
View File
@@ -19,7 +19,9 @@ module.exports = {
const queue = useQueue(interaction.guild.id);
if (!queue) {
logger.debug(`User used command ${interaction.commandName} but there was no queue.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
@@ -33,7 +35,9 @@ module.exports = {
if (!queue.deleted) {
queue.delete();
logger.debug(`User used command ${interaction.commandName} and deleted the queue.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and deleted the queue.`
);
return await interaction.editReply({
embeds: [
+16 -6
View File
@@ -46,7 +46,9 @@ module.exports = {
const currentModeUserString = loopModesFormatted.get(currentMode);
if (!mode && mode !== 0) {
logger.debug(`User used command ${interaction.commandName} but no mode was provided.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but no mode was provided.`
);
return await interaction.editReply({
embeds: [
@@ -63,7 +65,7 @@ module.exports = {
if (mode === currentMode) {
logger.debug(
`User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.`
);
return await interaction.editReply({
@@ -80,7 +82,9 @@ module.exports = {
queue.setRepeatMode(mode);
if (!queue.repeatMode === mode) {
logger.debug(`User used command ${interaction.commandName} but failed to change loop mode.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but failed to change loop mode.`
);
return await interaction.editReply({
embeds: [
@@ -94,7 +98,9 @@ module.exports = {
}
if (queue.repeatMode === 0) {
logger.debug(`User used command ${interaction.commandName} and disabled loop mode.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and disabled loop mode.`
);
return await interaction.editReply({
embeds: [
@@ -112,7 +118,9 @@ module.exports = {
}
if (queue.repeatMode === 3) {
logger.debug(`User used command ${interaction.commandName} and enabled autoplay.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and enabled autoplay.`
);
return await interaction.editReply({
embeds: [
@@ -129,7 +137,9 @@ module.exports = {
});
}
logger.debug(`User used command ${interaction.commandName} and enabled loop mode.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and enabled loop mode.`
);
return await interaction.editReply({
embeds: [
+21 -8
View File
@@ -93,7 +93,9 @@ module.exports = {
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
logger.debug(`User used command ${interaction.commandName}, finished intializing data.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, finished intializing data.`
);
const response = await interaction.editReply({
embeds: [
@@ -143,7 +145,9 @@ module.exports = {
components: [nowPlayingActionRow]
});
logger.debug(`User used command ${interaction.commandName}, finished sending response.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, finished sending response.`
);
const collectorFilter = (i) => i.user.id === interaction.user.id;
try {
@@ -155,10 +159,12 @@ module.exports = {
confirmation.deferUpdate();
if (confirmation.customId === 'nowplaying-skip') {
logger.debug(`User used command ${interaction.commandName}, received skip confirmation.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, received skip confirmation.`
);
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
logger.debug(
`User used command ${interaction.commandName} and tried skipping but there was no queue.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and tried skipping but there was no queue.`
);
return await interaction.followUp({
embeds: [
@@ -174,7 +180,7 @@ module.exports = {
if (queue.currentTrack !== currentTrack) {
logger.debug(
`User used command ${interaction.commandName} and tried skipping but the track was already removed.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and tried skipping but the track was already removed.`
);
return await interaction.followUp({
embeds: [
@@ -197,7 +203,9 @@ module.exports = {
const repeatModeUserString = loopModesFormatted.get(queue.repeatMode);
logger.debug(`User used command ${interaction.commandName} and skipped the track.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped the track.`
);
return await interaction.followUp({
embeds: [
new EmbedBuilder()
@@ -225,11 +233,16 @@ module.exports = {
}
} catch (error) {
if (error.code === 'InteractionCollectorError') {
logger.debug(`User used command ${interaction.commandName} but did not respond to the skip prompt.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but did not respond to the skip prompt.`
);
return;
}
logger.debug(error, `User used command ${interaction.commandName} but there was an unhandled error.`);
logger.debug(
error,
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was an unhandled error.`
);
throw error;
}
}
+5 -1
View File
@@ -32,7 +32,11 @@ module.exports = {
// change paused state to opposite of current state
queue.node.setPaused(!queue.node.isPaused());
logger.debug(`User used command ${interaction.commandName} and set paused state to ${queue.node.isPaused()}.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${
interaction.commandName
} and set paused state to ${queue.node.isPaused()}.`
);
return await interaction.editReply({
embeds: [
+27 -11
View File
@@ -28,12 +28,12 @@ module.exports = {
requestedBy: interaction.user
});
} catch (error) {
logger.error('Failed to search for track with player.search()');
logger.error('[Shard ${interaction.guild.shardId}] Failed to search for track with player.search()');
logger.error(error);
}
if (!searchResult || searchResult.tracks.length === 0) {
logger.debug(`No results found for query: ${query}`);
logger.debug(`[Shard ${interaction.guild.shardId}] No results found for query: ${query}`);
return await interaction.editReply({
embeds: [
@@ -51,7 +51,9 @@ module.exports = {
searchResult.tracks[0].raw.duration === 0 &&
searchResult.tracks[0].source === 'youtube'
) {
logger.debug(`Unsupported audio source. Query: ${query}. Track is live, 0 duration and from YouTube.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Unsupported audio source. Query: ${query}. Track is live, 0 duration and from YouTube.`
);
return await interaction.editReply({
embeds: [
@@ -88,7 +90,7 @@ module.exports = {
}
}));
logger.debug(`player.play() successful. Query: ${query}.`);
logger.debug(`[Shard ${interaction.guild.shardId}] player.play() successful. Query: ${query}.`);
} catch (error) {
if (error.message.includes('Sign in to confirm your age')) {
return await interaction.editReply({
@@ -108,7 +110,10 @@ module.exports = {
error.message.includes('Failed to fetch resources for ytdl streaming'))) ||
error.message.includes('Could not extract stream for this track')
) {
logger.debug(error, `Found track but failed to retrieve audio. Query: ${query}.`);
logger.debug(
error,
`[Shard ${interaction.guild.shardId}] Found track but failed to retrieve audio. Query: ${query}.`
);
return await interaction.editReply({
embeds: [
@@ -122,7 +127,7 @@ module.exports = {
}
if (error.message === 'Cancelled') {
logger.debug(error, `Operation cancelled. Query: ${query}.`);
logger.debug(error, `[Shard ${interaction.guild.shardId}] Operation cancelled. Query: ${query}.`);
return await interaction.editReply({
embeds: [
@@ -135,13 +140,18 @@ module.exports = {
});
}
logger.error(error, 'Failed to play track with player.play(), unhandled error.');
logger.error(
error,
'[Shard ${interaction.guild.shardId}] Failed to play track with player.play(), unhandled error.'
);
}
let queue = useQueue(interaction.guild.id);
if (!queue) {
logger.warn(`After player.play(), queue is undefined. Query: ${query}.`);
logger.warn(
`[Shard ${interaction.guild.shardId}] After player.play(), queue is undefined. Query: ${query}.`
);
return await interaction.editReply({
embeds: [
@@ -162,7 +172,9 @@ module.exports = {
let durationFormat = track.raw.duration === 0 || track.duration === '0:00' ? '' : `\`${track.duration}\``;
if (searchResult.playlist && searchResult.tracks.length > 1) {
logger.debug(`Playlist found and added with player.play(). Query: ${query}.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Playlist found and added with player.play(). Query: ${query}.`
);
return await interaction.editReply({
embeds: [
@@ -185,7 +197,9 @@ module.exports = {
}
if (queue.currentTrack === track && queue.tracks.data.length === 0) {
logger.debug(`Track found and added with player.play(), started playing. Query: ${query}.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Track found and added with player.play(), started playing. Query: ${query}.`
);
return await interaction.editReply({
embeds: [
@@ -204,7 +218,9 @@ module.exports = {
});
}
logger.debug(`Track found and added with player.play(), added to queue. Query: ${query}.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] Track found and added with player.play(), added to queue. Query: ${query}.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
+15 -5
View File
@@ -21,7 +21,9 @@ module.exports = {
if (!queue) {
if (pageIndex >= 1) {
logger.debug(`User used command ${interaction.commandName} but there was no queue.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
@@ -35,7 +37,9 @@ module.exports = {
});
}
logger.debug(`User used command ${interaction.commandName} but there was no queue.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
);
queueString = 'The queue is empty, add some tracks with **`/play`**!';
return await interaction.editReply({
embeds: [
@@ -57,7 +61,9 @@ module.exports = {
const totalPages = Math.ceil(queueLength / 10) || 1;
if (pageIndex > totalPages - 1) {
logger.debug(`User used command ${interaction.commandName} but page was higher than total pages.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but page was higher than total pages.`
);
return await interaction.editReply({
embeds: [
@@ -106,7 +112,9 @@ module.exports = {
}`;
if (!currentTrack) {
logger.debug(`User used command ${interaction.commandName} but there was no current track.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no current track.`
);
return await interaction.editReply({
embeds: [
@@ -139,7 +147,9 @@ module.exports = {
bar = '_No duration available._';
}
logger.debug(`User used command ${interaction.commandName} and got queue in reply with current track.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and got queue in reply with current track.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
+6 -2
View File
@@ -31,7 +31,9 @@ module.exports = {
const removeTrackNumber = interaction.options.getNumber('tracknumber');
if (removeTrackNumber > queue.tracks.data.length) {
logger.debug(`User used command ${interaction.commandName} but track number was higher than total tracks.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but track number was higher than total tracks.`
);
return await interaction.editReply({
embeds: [
@@ -49,7 +51,9 @@ module.exports = {
let durationFormat =
removedTrack.raw.duration === 0 || removedTrack.duration === '0:00' ? '' : `\`${removedTrack.duration}\``;
logger.debug(`User used command ${interaction.commandName} and removed track.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and removed track.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
+11 -5
View File
@@ -46,7 +46,9 @@ module.exports = {
}
if (durationArray.length === 0 || durationArray.length > 3) {
logger.debug(`User used command ${interaction.commandName} but entered an invalid duration.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration.`
);
return await interaction.editReply({
embeds: [
@@ -74,7 +76,7 @@ module.exports = {
if (!validElements) {
logger.debug(
`User used command ${interaction.commandName} but entered an invalid duration after parsing duration.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration after parsing duration.`
);
return await interaction.editReply({
embeds: [
@@ -97,7 +99,7 @@ module.exports = {
if (!isValidDuration) {
logger.debug(
`User used command ${interaction.commandName} but entered an invalid duration after regex checks.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration after regex checks.`
);
return await interaction.editReply({
@@ -118,7 +120,9 @@ module.exports = {
const durationInMilliseconds = durationArray[0] * 3600000 + durationArray[1] * 60000 + durationArray[2] * 1000;
if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
logger.debug(`User used command ${interaction.commandName} but entered a duration longer than the track.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered a duration longer than the track.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
@@ -132,7 +136,9 @@ module.exports = {
queue.node.seek(durationInMilliseconds);
logger.debug(`User used command ${interaction.commandName} and seeked to duration.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and seeked to duration.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
+8 -4
View File
@@ -33,7 +33,7 @@ module.exports = {
if (skipToTrack) {
if (skipToTrack > queue.tracks.data.length) {
logger.debug(
`User used command ${interaction.commandName} but track number was higher than total tracks.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but track number was higher than total tracks.`
);
return await interaction.editReply({
embeds: [
@@ -52,7 +52,9 @@ module.exports = {
: `\`${skippedTrack.duration}\``;
queue.node.skipTo(skipToTrack - 1);
logger.debug(`User used command ${interaction.commandName} and skipped to track.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped to track.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
@@ -71,7 +73,7 @@ module.exports = {
} else {
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
logger.debug(
`User used command ${interaction.commandName} but there was no tracks in queue or current track.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no tracks in queue or current track.`
);
return await interaction.editReply({
embeds: [
@@ -100,7 +102,9 @@ module.exports = {
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
logger.debug(`User used command ${interaction.commandName} and skipped track.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped track.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
+8 -4
View File
@@ -34,7 +34,7 @@ module.exports = {
const currentVolume = queue.node.volume;
logger.debug(
`User used command ${interaction.commandName} but no volume was provided, providing info of current volume.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but no volume was provided, providing info of current volume.`
);
return await interaction.editReply({
embeds: [
@@ -49,7 +49,7 @@ module.exports = {
});
} else if (volume > 100 || volume < 0) {
logger.debug(
`User used command ${interaction.commandName} but volume was higher than 100% or lower than 0%.`
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but volume was higher than 100% or lower than 0%.`
);
return await interaction.editReply({
embeds: [
@@ -64,7 +64,9 @@ module.exports = {
queue.node.setVolume(volume);
if (volume === 0) {
logger.debug(`User used command ${interaction.commandName} and muted volume.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and muted volume.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()
@@ -80,7 +82,9 @@ module.exports = {
});
}
logger.debug(`User used command ${interaction.commandName} and changed volume.`);
logger.debug(
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and changed volume.`
);
return await interaction.editReply({
embeds: [
new EmbedBuilder()