mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
rename tracknumber to position / trackPosition
This commit is contained in:
1 parent
6fcb6375f7
commit
e7f7b7a91e
3 files changed
+72
-32
No files matched your search
@@ -12,7 +12,7 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
.setName('back')
|
.setName('back')
|
||||||
.setDescription('Go back to previous track or specified position in history.')
|
.setDescription('Go back to previous track or specified position in history.')
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option.setName('tracknumber').setDescription('The position in history to go back to.').setMinValue(1)
|
option.setName('position').setDescription('The position in history to go back to.').setMinValue(1)
|
||||||
);
|
);
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
checkQueueCurrentTrack
|
checkQueueCurrentTrack
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const backToTrackInput: number = interaction.options.getNumber('tracknumber')!;
|
const backToTrackInput: number = interaction.options.getNumber('position')!;
|
||||||
|
|
||||||
if (backToTrackInput) {
|
if (backToTrackInput) {
|
||||||
return await this.handleBackToTrackPosition(logger, interaction, history, backToTrackInput);
|
return await this.handleBackToTrackPosition(logger, interaction, history, backToTrackInput);
|
||||||
@@ -46,22 +46,27 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
backtoTrackPosition: number
|
backtoTrackPosition: number
|
||||||
) {
|
) {
|
||||||
if (backtoTrackPosition > history.tracks.data.length) {
|
if (backtoTrackPosition > history.tracks.data.length) {
|
||||||
return await this.handleTrackNumberHigherThanTotalTracks(backtoTrackPosition, history, logger, interaction);
|
return await this.handleTrackPositionHigherThanQueueLength(
|
||||||
|
backtoTrackPosition,
|
||||||
|
history,
|
||||||
|
logger,
|
||||||
|
interaction
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await history.back();
|
await history.back();
|
||||||
const recoveredTrack: Track = history.currentTrack! ?? history.tracks.data[backtoTrackPosition - 1];
|
const recoveredTrack: Track = history.currentTrack! ?? history.tracks.data[backtoTrackPosition - 1];
|
||||||
logger.debug('Went back to specified track number in history.');
|
logger.debug('Went back to specified track position in history.');
|
||||||
return await this.respondWithSuccessEmbed(recoveredTrack, interaction);
|
return await this.respondWithSuccessEmbed(recoveredTrack, interaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleTrackNumberHigherThanTotalTracks(
|
private async handleTrackPositionHigherThanQueueLength(
|
||||||
backToTrackPosition: number,
|
backToTrackPosition: number,
|
||||||
history: GuildQueueHistory,
|
history: GuildQueueHistory,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction
|
interaction: ChatInputCommandInteraction
|
||||||
) {
|
) {
|
||||||
logger.debug('Specified track number was higher than total tracks.');
|
logger.debug('Specified track position was higher than total tracks.');
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
|
|||||||
@@ -10,13 +10,41 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
|||||||
constructor() {
|
constructor() {
|
||||||
const data = new SlashCommandBuilder()
|
const data = new SlashCommandBuilder()
|
||||||
.setName('remove')
|
.setName('remove')
|
||||||
.setDescription('Remove specified track from the queue')
|
.setDescription('Remove tracks from the queue')
|
||||||
.addNumberOption((option) =>
|
.addSubcommand((subcommand) =>
|
||||||
|
subcommand
|
||||||
|
.setName('track')
|
||||||
|
.setDescription('Remove a track from the queue')
|
||||||
|
.addIntegerOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('tracknumber')
|
.setName('position')
|
||||||
.setDescription('The position in queue for track to remove.')
|
.setDescription('The position in queue for track to remove.')
|
||||||
.setMinValue(1)
|
.setMinValue(1)
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addSubcommand((subcommand) =>
|
||||||
|
subcommand
|
||||||
|
.setName('range')
|
||||||
|
.setDescription('Remove a range of tracks from the queue')
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('start')
|
||||||
|
.setDescription('The starting position of the range to remove')
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('end')
|
||||||
|
.setDescription('The ending position of the range to remove')
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addSubcommand((subcommand) =>
|
||||||
|
subcommand.setName('queue').setDescription('Remove all tracks from the queue')
|
||||||
|
)
|
||||||
|
.addSubcommand((subcommand) =>
|
||||||
|
subcommand.setName('duplicates').setDescription('Remove all duplicate tracks from the queue')
|
||||||
);
|
);
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
@@ -33,22 +61,29 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
|||||||
checkQueueExists
|
checkQueueExists
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const removeTrackNumber: number = interaction.options.getNumber('tracknumber')!;
|
const subcommand = interaction.options.getSubcommand();
|
||||||
|
|
||||||
if (removeTrackNumber > queue.tracks.data.length) {
|
switch (subcommand) {
|
||||||
return await this.handleInvalidTrackNumber(logger, interaction, removeTrackNumber, queue);
|
default:
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.removeTrackFromQueue(logger, interaction, queue, removeTrackNumber);
|
const trackPositionInput: number = interaction.options.getNumber('position')!;
|
||||||
|
|
||||||
|
if (trackPositionInput > queue.tracks.data.length) {
|
||||||
|
return await this.handleTrackPositionHigherThanQueueLength(logger, interaction, trackPositionInput, queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleInvalidTrackNumber(
|
return await this.removeTrackFromQueue(logger, interaction, queue, trackPositionInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleTrackPositionHigherThanQueueLength(
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
removeTrackNumber: number,
|
trackPositionInput: number,
|
||||||
queue: GuildQueue
|
queue: GuildQueue
|
||||||
) {
|
) {
|
||||||
logger.debug('Specified track number is higher than total tracks.');
|
logger.debug('Specified track position is higher than total tracks.');
|
||||||
|
|
||||||
logger.debug('Responding with warning embed.');
|
logger.debug('Responding with warning embed.');
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
@@ -56,7 +91,7 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
|||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**${this.embedOptions.icons.warning} Oops!**\n` +
|
`**${this.embedOptions.icons.warning} Oops!**\n` +
|
||||||
`Track **\`${removeTrackNumber}\`** is not a valid track number. There are a total of **\`${queue.tracks.data.length}\`** tracks in the queue.` +
|
`Track **\`${trackPositionInput}\`** is not a valid track position. There are a total of **\`${queue.tracks.data.length}\`** tracks in the queue.` +
|
||||||
'\n\nView tracks added to the queue with **`/queue`**.'
|
'\n\nView tracks added to the queue with **`/queue`**.'
|
||||||
)
|
)
|
||||||
.setColor(this.embedOptions.colors.warning)
|
.setColor(this.embedOptions.colors.warning)
|
||||||
@@ -69,9 +104,9 @@ class RemoveCommand extends BaseSlashCommandInteraction {
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
queue: GuildQueue,
|
queue: GuildQueue,
|
||||||
removeTrackNumber: number
|
trackPositionInput: number
|
||||||
) {
|
) {
|
||||||
const removedTrack: Track = queue.node.remove(removeTrackNumber - 1)!;
|
const removedTrack: Track = queue.node.remove(trackPositionInput - 1)!;
|
||||||
logger.debug(`Removed track '${removedTrack.url}' from queue.`);
|
logger.debug(`Removed track '${removedTrack.url}' from queue.`);
|
||||||
|
|
||||||
logger.debug('Responding with success embed.');
|
logger.debug('Responding with success embed.');
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SkipCommand extends BaseSlashCommandInteraction {
|
|||||||
.setName('skip')
|
.setName('skip')
|
||||||
.setDescription('Skip track to next or specified position in queue.')
|
.setDescription('Skip track to next or specified position in queue.')
|
||||||
.addNumberOption((option) =>
|
.addNumberOption((option) =>
|
||||||
option.setName('tracknumber').setDescription('The position in queue to skip to.').setMinValue(1)
|
option.setName('position').setDescription('The position in queue to skip to.').setMinValue(1)
|
||||||
);
|
);
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
@@ -30,10 +30,10 @@ class SkipCommand extends BaseSlashCommandInteraction {
|
|||||||
checkQueueCurrentTrack
|
checkQueueCurrentTrack
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const skipToTrackInput: number = interaction.options.getNumber('tracknumber')!;
|
const trackPositionInput: number = interaction.options.getNumber('position')!;
|
||||||
|
|
||||||
if (skipToTrackInput) {
|
if (trackPositionInput) {
|
||||||
return await this.handleSkipToTrackPosition(logger, interaction, queue, skipToTrackInput);
|
return await this.handleSkipToTrackPosition(logger, interaction, queue, trackPositionInput);
|
||||||
} else {
|
} else {
|
||||||
return await this.handleSkipToNextTrack(logger, interaction, queue);
|
return await this.handleSkipToNextTrack(logger, interaction, queue);
|
||||||
}
|
}
|
||||||
@@ -43,31 +43,31 @@ class SkipCommand extends BaseSlashCommandInteraction {
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
queue: GuildQueue,
|
queue: GuildQueue,
|
||||||
skipToTrackPosition: number
|
trackPosition: number
|
||||||
) {
|
) {
|
||||||
if (skipToTrackPosition > queue.tracks.data.length) {
|
if (trackPosition > queue.tracks.data.length) {
|
||||||
return await this.handleTrackNumberHigherThanTotalTracks(skipToTrackPosition, queue, logger, interaction);
|
return await this.handleTrackPositionHigherThanQueueLength(trackPosition, queue, logger, interaction);
|
||||||
} else {
|
} else {
|
||||||
const skippedTrack: Track = queue.currentTrack!;
|
const skippedTrack: Track = queue.currentTrack!;
|
||||||
queue.node.skipTo(skipToTrackPosition - 1);
|
queue.node.skipTo(trackPosition - 1);
|
||||||
logger.debug('Skipped to specified track number.');
|
logger.debug('Skipped to specified track position.');
|
||||||
return await this.respondWithSuccessEmbed(skippedTrack, interaction);
|
return await this.respondWithSuccessEmbed(skippedTrack, interaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleTrackNumberHigherThanTotalTracks(
|
private async handleTrackPositionHigherThanQueueLength(
|
||||||
skipToTrack: number,
|
trackPosition: number,
|
||||||
queue: GuildQueue,
|
queue: GuildQueue,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction
|
interaction: ChatInputCommandInteraction
|
||||||
) {
|
) {
|
||||||
logger.debug('Specified track number was higher than total tracks.');
|
logger.debug('Specified track position was higher than total tracks.');
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**${this.embedOptions.icons.warning} Oops!**\n` +
|
`**${this.embedOptions.icons.warning} Oops!**\n` +
|
||||||
`There are only **\`${queue.tracks.data.length}\`** tracks in the queue. You cannot skip to track **\`${skipToTrack}\`**.\n\n` +
|
`There are only **\`${queue.tracks.data.length}\`** tracks in the queue. You cannot skip to track **\`${trackPosition}\`**.\n\n` +
|
||||||
'View tracks added to the queue with **`/queue`**.'
|
'View tracks added to the queue with **`/queue`**.'
|
||||||
)
|
)
|
||||||
.setColor(this.embedOptions.colors.warning)
|
.setColor(this.embedOptions.colors.warning)
|
||||||
|
|||||||
Reference in new issue
Block a user