mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 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,5 +1,4 @@
|
||||
import config from 'config';
|
||||
import { GuildQueue, PlayerTimestamp, Track, useQueue } from 'discord-player';
|
||||
import { GuildQueue, Track, useQueue } from 'discord-player';
|
||||
import {
|
||||
APIActionRowComponent,
|
||||
APIButtonComponent,
|
||||
@@ -12,13 +11,10 @@ import {
|
||||
SlashCommandBuilder
|
||||
} from 'discord.js';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { PlayerOptions } from '../../../types/configTypes';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../../types/interactionTypes';
|
||||
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
|
||||
const playerOptions: PlayerOptions = config.get('playerOptions');
|
||||
|
||||
class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
const data = new SlashCommandBuilder()
|
||||
@@ -46,7 +42,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
const displayTrackRequestedBy: string = this.getDisplayTrackRequestedBy(currentTrack);
|
||||
const displayTrackPlayingStatus: string = this.getDisplayTrackPlayingStatus(queue);
|
||||
const displayQueueRepeatMode: string = this.getDisplayQueueRepeatMode(queue);
|
||||
const displayEmbedProgressBar: string = await this.getDisplayQueueProgressBar(queue);
|
||||
const displayEmbedProgressBar: string = this.getDisplayQueueProgressBar(queue);
|
||||
|
||||
const customId: string = `nowplaying-skip-button_${currentTrack.id}`;
|
||||
logger.debug(`Generated custom id for skip button: ${customId}`);
|
||||
@@ -107,28 +103,6 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
return author;
|
||||
}
|
||||
|
||||
private async getDisplayQueueProgressBar(queue: GuildQueue): Promise<string> {
|
||||
const timestamp: PlayerTimestamp = queue.node.getTimestamp()!;
|
||||
let progressBar: string = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({
|
||||
queue: false,
|
||||
length: playerOptions.progressBar.length ?? 12,
|
||||
timecodes: playerOptions.progressBar.timecodes ?? false,
|
||||
indicator: playerOptions.progressBar.indicator ?? '🔘',
|
||||
leftChar: playerOptions.progressBar.leftChar ?? '▬',
|
||||
rightChar: 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;
|
||||
}
|
||||
|
||||
private getTrackSourceString(currentTrack: Track): string {
|
||||
const sourceStringsFormatted: Map<string, string> = new Map([
|
||||
['youtube', 'YouTube'],
|
||||
@@ -188,10 +162,6 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
: `**${this.embedOptions.icons.audioPlaying} Now Playing**`;
|
||||
};
|
||||
|
||||
private getDisplayTrackRequestedBy = (currentTrack: Track): string => {
|
||||
return currentTrack.requestedBy ? `<@${currentTrack.requestedBy.id}>` : 'Unavailable';
|
||||
};
|
||||
|
||||
private getEmbedFields = (currentTrack: Track): EmbedField[] => {
|
||||
const fields: EmbedField[] = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user