mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
fix: refactored queue command, added more common methods
This commit is contained in:
1 parent
bf30d565d7
commit
1ebb7c3b89
6 files changed
+175
-149
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import config from 'config';
|
||||
import { GuildQueue, Track } from 'discord-player';
|
||||
import { GuildQueue, PlayerTimestamp, Track } from 'discord-player';
|
||||
import {
|
||||
ApplicationCommandOptionChoiceData,
|
||||
AutocompleteInteraction,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedAuthorOptions,
|
||||
EmbedFooterData,
|
||||
GuildMember,
|
||||
Interaction,
|
||||
Message,
|
||||
@@ -113,6 +114,44 @@ abstract class BaseInteraction {
|
||||
return thumbnailUrl;
|
||||
}
|
||||
|
||||
protected getFooterDisplayPageInfo(interaction: ChatInputCommandInteraction, queue: GuildQueue): EmbedFooterData {
|
||||
if (!queue.tracks.data.length) {
|
||||
return { text: 'Page 1 of 1 (0 tracks)' };
|
||||
}
|
||||
|
||||
const pageIndex: number = (interaction.options.getNumber('page') || 1) - 1;
|
||||
const totalPages: number = Math.ceil(queue.tracks.data.length / 10) || 1;
|
||||
return {
|
||||
text: `Page ${pageIndex + 1} of ${totalPages} (${queue.tracks.data.length} tracks)`
|
||||
};
|
||||
}
|
||||
|
||||
protected getDisplayTrackRequestedBy = (track: Track): string => {
|
||||
return track.requestedBy ? `<@${track.requestedBy.id}>` : 'Unavailable';
|
||||
};
|
||||
|
||||
protected getDisplayQueueProgressBar(queue: GuildQueue): string {
|
||||
const timestamp: PlayerTimestamp = queue.node.getTimestamp()!;
|
||||
let progressBar: string = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({
|
||||
queue: false,
|
||||
length: this.playerOptions.progressBar.length ?? 12,
|
||||
timecodes: this.playerOptions.progressBar.timecodes ?? false,
|
||||
indicator: this.playerOptions.progressBar.indicator ?? '🔘',
|
||||
leftChar: this.playerOptions.progressBar.leftChar ?? '▬',
|
||||
rightChar: this.playerOptions.progressBar.rightChar ?? '▬'
|
||||
})} **\`${timestamp.total.label}\`**`;
|
||||
|
||||
if (Number(queue.currentTrack?.raw.duration) === 0 || queue.currentTrack?.duration === '0:00') {
|
||||
progressBar = '_No duration available._';
|
||||
}
|
||||
|
||||
if (queue.currentTrack?.raw.live) {
|
||||
progressBar = `${this.embedOptions.icons.liveTrack} **\`LIVE\`** - Playing continuously from live source.`;
|
||||
}
|
||||
|
||||
return progressBar;
|
||||
}
|
||||
|
||||
abstract execute(
|
||||
params: BaseInteractionParams
|
||||
): Promise<Message<boolean> | ApplicationCommandOptionChoiceData | void>;
|
||||
|
||||
Reference in new issue
Block a user