mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 22:15:37 +00:00
fix: refactored pause command, added common method getDisplayTrackDurationAndUrl()
This commit is contained in:
1 parent
ee8cc06e4d
commit
0850d9b26d
7 files changed
+64
-94
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { GuildQueue, Track, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { Logger } from 'pino';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
@@ -26,18 +27,7 @@ class PauseCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const currentTrack: Track = queue.currentTrack!;
|
||||
|
||||
let durationFormat =
|
||||
Number(currentTrack.raw.duration) === 0 || currentTrack.duration === '0:00'
|
||||
? ''
|
||||
: `\`${currentTrack.duration}\``;
|
||||
|
||||
if (currentTrack.raw.live) {
|
||||
durationFormat = `${this.embedOptions.icons.liveTrack} \`LIVE\``;
|
||||
}
|
||||
|
||||
// change paused state to opposite of current state
|
||||
queue.node.setPaused(!queue.node.isPaused());
|
||||
logger.debug(`Set paused state to ${queue.node.isPaused()}.`);
|
||||
this.togglePauseState(queue, logger);
|
||||
|
||||
logger.debug('Responding with success embed.');
|
||||
return await interaction.editReply({
|
||||
@@ -47,13 +37,18 @@ class PauseCommand extends BaseSlashCommandInteraction {
|
||||
.setDescription(
|
||||
`**${this.embedOptions.icons.pauseResumed} ${
|
||||
queue.node.isPaused() ? 'Paused Track' : 'Resumed track'
|
||||
}**\n**${durationFormat} [${currentTrack.title}](${currentTrack.raw.url ?? currentTrack.url})**`
|
||||
}**\n ${this.getDisplayTrackDurationAndUrl(currentTrack)}`
|
||||
)
|
||||
.setThumbnail(currentTrack.thumbnail)
|
||||
.setColor(this.embedOptions.colors.success)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
private togglePauseState(queue: GuildQueue, logger: Logger): void {
|
||||
queue.node.setPaused(!queue.node.isPaused());
|
||||
logger.debug(`Set paused state to ${queue.node.isPaused()}.`);
|
||||
}
|
||||
}
|
||||
|
||||
export default new PauseCommand();
|
||||
Reference in new issue
Block a user