Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
fix: Handle max queue size in /play command when adding large playlists.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Jul 24, 2023
1 parent d9d6644 commit 8e42f75
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/commands/player/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ module.exports = {
});
}

let queue = useQueue(interaction.guild.id);
let queueSize = queue?.size ?? 0;

if ((searchResult.playlist && searchResult.tracks.length) > playerOptions.maxQueueSize - queueSize) {
logger.debug(`[Shard ${interaction.guild.shardId}] Playlist found but too many tracks. Query: ${query}.`);

return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.warning} Playlist too large**\nThis playlist is too large to be added to the queue.\n\nThe maximum amount of tracks that can be added to the queue is **${playerOptions.maxQueueSize}**.`
)
.setColor(embedOptions.colors.warning)
]
});
}

let track;

try {
Expand Down Expand Up @@ -202,7 +219,7 @@ module.exports = {
);
}

let queue = useQueue(interaction.guild.id);
queue = useQueue(interaction.guild.id);

if (!queue) {
logger.warn(
Expand Down
2 changes: 1 addition & 1 deletion src/config_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports.playerOptions = {
leaveOnStop: true,
leaveOnStopCooldown: 300_000,
defaultVolume: 50,
maxQueueSize: 1_000,
maxQueueSize: 10_000,
maxHistorySize: 100,
bufferingTimeout: 3_000,
connectionTimeout: 30_000,
Expand Down
6 changes: 6 additions & 0 deletions src/events/interactions/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ module.exports = {
try {
await command.autocomplete({ interaction, client });
} catch (error) {
if (error.message === 'Unknown interaction') {
logger.debug(
`[Shard ${interaction.guild.shardId}] Autocomplete failed to be responded to, providing a response took too long.`
);
return;
}
logger.warn(error, `[Shard ${interaction.guild.shardId}] Autocomplete failed to execute.`);
return;
}
Expand Down

0 comments on commit 8e42f75

Please sign in to comment.