fix: refactored play command and added common method for getting thumbnail url

This commit is contained in:
Marius Begby committed 2023-09-12 20:54:49 +02:00
1 parent 85e27afc5c
commit bf30d565d7
7 files changed
+248 -196

No files matched your search

+29 -1
View File
@@ -14,7 +14,7 @@ import {
} from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../services/logger';
import { BotOptions, EmbedOptions } from '../types/configTypes';
import { BotOptions, EmbedOptions, PlayerOptions } from '../types/configTypes';
import {
BaseAutocompleteParams,
BaseAutocompleteReturnType,
@@ -29,10 +29,12 @@ import { Validator, ValidatorParams } from '../types/utilTypes';
abstract class BaseInteraction {
embedOptions: EmbedOptions;
botOptions: BotOptions;
playerOptions: PlayerOptions;
constructor() {
this.embedOptions = config.get('embedOptions');
this.botOptions = config.get('botOptions');
this.playerOptions = config.get('playerOptions');
}
protected getLoggerBase(
@@ -85,6 +87,32 @@ abstract class BaseInteraction {
return `${formattedDuration} ${formattedUrl}`;
}
protected getTrackThumbnailUrl(track: Track): string {
let thumbnailUrl = '';
if (track.source === 'youtube') {
if (track.raw.thumbnail) {
// @ts-ignore -- discord-player bug with thumbnail for youtube?
thumbnailUrl = track.raw.thumbnail.url;
} else if (track.thumbnail && !track.thumbnail.endsWith('maxresdefault.jpg')) {
// @ts-ignore -- discord-player bug with thumbnail for youtube?
thumbnailUrl = track.thumbnail.url;
} else {
thumbnailUrl = this.embedOptions.info.fallbackThumbnailUrl;
}
} else {
if (track.raw.thumbnail) {
thumbnailUrl = track.raw.thumbnail;
} else if (track.thumbnail) {
thumbnailUrl = track.thumbnail;
} else {
thumbnailUrl = this.embedOptions.info.fallbackThumbnailUrl;
}
}
return thumbnailUrl;
}
abstract execute(
params: BaseInteractionParams
): Promise<Message<boolean> | ApplicationCommandOptionChoiceData | void>;