Transcribe everything

Untranscribed sections are marked TODO
This commit is contained in:
tacheometry committed 2023-12-16 00:15:49 +02:00
1 parent 5398831944
commit 694767fc03
32 files changed
+1034 -392

No files matched your search

+4 -4
View File
@@ -50,7 +50,7 @@ class BackCommand extends BaseSlashCommandInteraction {
translator: TFunction
) {
if (backtoTrackPosition > history.tracks.data.length) {
return await this.handleTrackPositionHigherThanQueueLength(
return await this.handleTrackPositionHigherThanHistoryLength(
backtoTrackPosition,
history,
logger,
@@ -65,7 +65,7 @@ class BackCommand extends BaseSlashCommandInteraction {
}
}
private async handleTrackPositionHigherThanQueueLength(
private async handleTrackPositionHigherThanHistoryLength(
backToTrackPosition: number,
history: GuildQueueHistory,
logger: Logger,
@@ -77,7 +77,7 @@ class BackCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
translator('commands.back.trackPositionHigherThanQueueLength', {
translator('commands.back.trackPositionHigherThanHistoryLength', {
icon: this.embedOptions.icons.warning,
count: history.tracks.data.length,
backPosition: backToTrackPosition,
@@ -137,7 +137,7 @@ class BackCommand extends BaseSlashCommandInteraction {
.setDescription(
translator('commands.back.trackRecovered', {
icon: this.embedOptions.icons.back,
track: this.getDisplayTrackDurationAndUrl(recoveredTrack)
track: this.getDisplayTrackDurationAndUrl(recoveredTrack, translator)
})
)
.setThumbnail(this.getTrackThumbnailUrl(recoveredTrack))
+66 -31
View File
@@ -16,7 +16,9 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkHistoryExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
class HistoryCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -31,6 +33,7 @@ class HistoryCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const history: GuildQueueHistory = useHistory(interaction.guild!.id)!;
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -45,10 +48,10 @@ class HistoryCommand extends BaseSlashCommandInteraction {
const totalPages: number = this.getTotalPages(history);
if (pageIndex > totalPages - 1) {
return await this.handleInvalidPage(logger, interaction, pageIndex, totalPages);
return await this.handleInvalidPage(logger, interaction, pageIndex, totalPages, translator);
}
const historyTracksListString: string = this.getHistoryTracksListString(history, pageIndex);
const historyTracksListString: string = this.getHistoryTracksListString(history, pageIndex, translator);
const currentTrack: Track = history.currentTrack!;
if (currentTrack) {
@@ -58,11 +61,19 @@ class HistoryCommand extends BaseSlashCommandInteraction {
queue,
history,
currentTrack,
historyTracksListString
historyTracksListString,
translator
);
}
return await this.handleNoCurrentTrack(logger, interaction, queue, history, historyTracksListString);
return await this.handleNoCurrentTrack(
logger,
interaction,
queue,
history,
historyTracksListString,
translator
);
}
private async handleCurrentTrack(
@@ -71,7 +82,8 @@ class HistoryCommand extends BaseSlashCommandInteraction {
queue: GuildQueue,
history: GuildQueueHistory,
currentTrack: Track,
historyTracksListString: string
historyTracksListString: string,
translator: TFunction
) {
logger.debug('History exists with current track, gathering information.');
@@ -100,9 +112,11 @@ class HistoryCommand extends BaseSlashCommandInteraction {
components.push(skipButton);
if (this.embedOptions.components.showButtonLabels) {
previousButton.label = 'Previous';
playPauseButton.label = queue.node.isPaused() ? 'Resume' : 'Pause';
skipButton.label = 'Skip';
previousButton.label = translator('musicPlayerCommon.controls.previous');
playPauseButton.label = queue.node.isPaused()
? translator('musicPlayerCommon.controls.resume')
: translator('musicPlayerCommon.controls.pause');
skipButton.label = translator('musicPlayerCommon.controls.skip');
}
const embedActionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
@@ -114,18 +128,30 @@ class HistoryCommand extends BaseSlashCommandInteraction {
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedQueueAuthor(interaction, queue))
.setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator))
.setDescription(
`**${this.embedOptions.icons.audioPlaying} Now playing**\n` +
`${this.getFormattedTrackUrl(currentTrack)}\n` +
`**Requested by:** ${this.getDisplayTrackRequestedBy(currentTrack)}\n` +
`${this.getDisplayQueueProgressBar(queue)}\n\n` +
`${this.getDisplayRepeatMode(queue.repeatMode)}` +
`**${this.embedOptions.icons.queue} Tracks in history**\n` +
translator('musicPlayerCommon.nowPlayingTitle', {
icon: this.embedOptions.icons.audioPlaying
}) +
'\n' +
this.getFormattedTrackUrl(currentTrack, translator) +
'\n' +
translator('musicPlayerCommon.requestedBy', {
user: this.getDisplayTrackRequestedBy(currentTrack, translator)
}) +
'\n' +
this.getDisplayQueueProgressBar(queue, translator) +
'\n' +
'\n' +
this.getDisplayRepeatMode(queue.repeatMode, translator) +
translator('commands.history.tracksInHistoryTitle', {
icon: this.embedOptions.icons.queue
}) +
'\n' +
historyTracksListString
)
.setThumbnail(this.getTrackThumbnailUrl(currentTrack))
.setFooter(this.getDisplayFullFooterInfo(interaction, history))
.setFooter(this.getDisplayFullFooterInfo(interaction, history, translator))
.setColor(this.embedOptions.colors.info)
],
components: [embedActionRow]
@@ -138,7 +164,8 @@ class HistoryCommand extends BaseSlashCommandInteraction {
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
history: GuildQueueHistory,
historyTracksListString: string
historyTracksListString: string,
translator: TFunction
) {
logger.debug('History exists but there is no current track.');
@@ -146,13 +173,15 @@ class HistoryCommand extends BaseSlashCommandInteraction {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedQueueAuthor(interaction, queue))
.setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator))
.setDescription(
`${this.getDisplayRepeatMode(queue.repeatMode)}` +
`**${this.embedOptions.icons.queue} Tracks in history**\n` +
translator('commands.history.tracksInHistoryTitle', {
icon: this.embedOptions.icons.queue
}) +
'\n' +
historyTracksListString
)
.setFooter(this.getDisplayFullFooterInfo(interaction, history))
.setFooter(this.getDisplayFullFooterInfo(interaction, history, translator))
.setColor(this.embedOptions.colors.info)
]
});
@@ -162,7 +191,8 @@ class HistoryCommand extends BaseSlashCommandInteraction {
logger: Logger,
interaction: ChatInputCommandInteraction,
pageIndex: number,
totalPages: number
totalPages: number,
translator: TFunction
) {
logger.debug('Specified page was higher than total pages.');
@@ -171,9 +201,11 @@ class HistoryCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`Page **\`${pageIndex + 1}\`** is not a valid page number.\n\n` +
`There are only a total of **\`${totalPages}\`** pages in the history.`
translator('commands.history.invalidPageNumber', {
icon: this.embedOptions.icons.warning,
page: pageIndex + 1,
count: totalPages
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -189,24 +221,27 @@ class HistoryCommand extends BaseSlashCommandInteraction {
return Math.ceil(history.tracks.data.length / 10) || 1;
}
private getHistoryTracksListString(history: GuildQueueHistory, pageIndex: number): string {
private getHistoryTracksListString(history: GuildQueueHistory, pageIndex: number, translator: TFunction): string {
if (!history || history.tracks.data.length === 0) {
return 'The history is empty, add some tracks with **`/play`**!';
return translator('commands.history.emptyHistory', {
playCommand: formatSlashCommand('play', translator)
});
}
return history.tracks.data
.slice(pageIndex * 10, pageIndex * 10 + 10)
.map((track, index) => {
return `**${pageIndex * 10 + index + 1}.** ${this.getDisplayTrackDurationAndUrl(track)}`;
return `**${pageIndex * 10 + index + 1}.** ${this.getDisplayTrackDurationAndUrl(track, translator)}`;
})
.join('\n');
}
private getDisplayFullFooterInfo(
interaction: ChatInputCommandInteraction,
history: GuildQueueHistory
history: GuildQueueHistory,
translator: TFunction
): EmbedFooterData {
const pagination = this.getFooterDisplayPageInfo(interaction, history);
const pagination = this.getFooterDisplayPageInfo(interaction, history, translator);
const fullFooterData = {
text: `${pagination.text}`
+30 -15
View File
@@ -5,7 +5,9 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkInVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { checkVoicePermissionJoinAndTalk } from '../../../utils/validation/permissionValidator';
import { Logger } from 'pino';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
import { TFunction } from 'i18next';
class JoinCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -16,23 +18,24 @@ class JoinCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
await this.runValidators({ interaction, executionId }, [checkInVoiceChannel, checkVoicePermissionJoinAndTalk]);
const existingQueue = useQueue(interaction.guild!.id);
if (existingQueue) {
return await this.handleExisitingQueue(interaction, existingQueue);
return await this.handleExisitingQueue(interaction, existingQueue, translator);
}
const queue = this.createQueue(interaction);
if (!queue) {
return await this.handleCouldNotConnect(interaction);
return await this.handleCouldNotConnect(interaction, translator);
}
await this.connectToVoiceChannel(logger, queue, interaction);
if (!queue.dispatcher) {
return await this.handleCouldNotConnect(interaction);
return await this.handleCouldNotConnect(interaction, translator);
}
logger.debug('Responding with success embed.');
@@ -41,9 +44,11 @@ class JoinCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Joined channel**\n` +
`Connected to voice channel: <#${queue.dispatcher.channel.id}>\n\n` +
'To add tracks, use the **`/play`** command!'
translator('commands.join.joinedChannel', {
icon: this.embedOptions.icons.success,
channel: `<#${queue.dispatcher.channel.id}>`,
playCommand: formatSlashCommand('play', translator)
})
)
.setColor(this.embedOptions.colors.success)
]
@@ -82,32 +87,42 @@ class JoinCommand extends BaseSlashCommandInteraction {
}
}
private async handleCouldNotConnect(interaction: ChatInputCommandInteraction): Promise<Message> {
private async handleCouldNotConnect(
interaction: ChatInputCommandInteraction,
translator: TFunction
): Promise<Message> {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
'Could not join voice channel, please try again.'
translator('commands.join.couldNotJoin', {
icon: this.embedOptions.icons.warning
})
)
.setColor(this.embedOptions.colors.warning)
]
});
}
private async handleExisitingQueue(interaction: ChatInputCommandInteraction, queue: GuildQueue): Promise<Message> {
private async handleExisitingQueue(
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
): Promise<Message> {
const connectedChannel = queue.dispatcher?.channel;
const channelMention = connectedChannel?.id ? `<#${connectedChannel.id}>` : 'Unknown';
const channelMention = connectedChannel?.id ? `<#${connectedChannel.id}>` : '<#0>';
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`I am already connected to voice channel ${channelMention}.\n\n` +
'To disconnect me from the channel, use the **`/leave`** command.'
translator('commands.join.alreadyConnected', {
icon: this.embedOptions.icons.warning,
channel: channelMention,
leaveCommand: formatSlashCommand('leave', translator)
})
)
.setColor(this.embedOptions.colors.warning)
]
+7 -4
View File
@@ -4,7 +4,8 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
class LeaveCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -15,6 +16,7 @@ class LeaveCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -33,9 +35,10 @@ class LeaveCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Leaving channel**\n` +
'Cleared the track queue and left voice channel.\n\n' +
'To play more music, use the **`/play`** command!'
translator('commands.leave.leavingChannel', {
icon: this.embedOptions.icons.success,
playCommand: formatSlashCommand('play', translator)
})
)
.setColor(this.embedOptions.colors.success)
]
+61 -28
View File
@@ -11,7 +11,8 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class LoopCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -37,6 +38,7 @@ class LoopCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -50,34 +52,44 @@ class LoopCommand extends BaseSlashCommandInteraction {
const currentRepeatMode: QueueRepeatMode = queue.repeatMode;
if (!userInputRepeatMode && userInputRepeatMode !== 0) {
return await this.handleNoInputMode(logger, interaction, currentRepeatMode);
return await this.handleNoInputMode(logger, interaction, currentRepeatMode, translator);
}
if (userInputRepeatMode === currentRepeatMode) {
return await this.handleSameMode(logger, interaction, userInputRepeatMode);
return await this.handleSameMode(logger, interaction, userInputRepeatMode, translator);
}
return await this.handleChangeMode(logger, interaction, queue, currentRepeatMode, userInputRepeatMode);
return await this.handleChangeMode(
logger,
interaction,
queue,
currentRepeatMode,
userInputRepeatMode,
translator
);
}
private async handleNoInputMode(
logger: Logger,
interaction: ChatInputCommandInteraction,
currentRepeatMode: QueueRepeatMode
currentRepeatMode: QueueRepeatMode,
translator: TFunction
): Promise<Message> {
logger.debug('No repeat mode was provided, responding with current repeat mode.');
const repeatModeEmbedIcon =
currentRepeatMode === 3 ? this.embedOptions.icons.autoplay : this.embedOptions.icons.loop;
const repeatModeEmbedName = this.getRepeatModeEmbedName(currentRepeatMode);
const repeatModeEmbedName = this.getRepeatModeEmbedName(currentRepeatMode, translator);
logger.debug('Responding with info embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${repeatModeEmbedIcon} Current loop mode**\n` +
`The looping mode is currently set to **\`${repeatModeEmbedName}\`**.`
translator('commands.loop.loopModeInformation', {
icon: repeatModeEmbedIcon,
mode: repeatModeEmbedName
})
)
.setColor(this.embedOptions.colors.info)
]
@@ -87,17 +99,20 @@ class LoopCommand extends BaseSlashCommandInteraction {
private async handleSameMode(
logger: Logger,
interaction: ChatInputCommandInteraction,
currentRepeatMode: QueueRepeatMode
currentRepeatMode: QueueRepeatMode,
translator: TFunction
): Promise<Message> {
const repeatModeEmbedName = this.getRepeatModeEmbedName(currentRepeatMode);
const repeatModeEmbedName = this.getRepeatModeEmbedName(currentRepeatMode, translator);
logger.debug(`Loop mode is already set to '${repeatModeEmbedName}'.`);
logger.debug('Responding with warning embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`Loop mode is already **\`${repeatModeEmbedName}\`**.`
translator('commands.loop.alreadySet', {
icon: this.embedOptions.icons.warning,
mode: repeatModeEmbedName
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -109,10 +124,15 @@ class LoopCommand extends BaseSlashCommandInteraction {
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
fromRepeatMode: QueueRepeatMode,
toRepeatMode: QueueRepeatMode
toRepeatMode: QueueRepeatMode,
translator: TFunction
): Promise<Message> {
const newRepeatModeEmbedName = this.getRepeatModeEmbedName(toRepeatMode);
const getChangedRepeatModeEmbedReply = this.getChangedRepeatModeEmbedReply(fromRepeatMode, toRepeatMode);
const newRepeatModeEmbedName = this.getRepeatModeEmbedName(toRepeatMode, translator);
const getChangedRepeatModeEmbedReply = this.getChangedRepeatModeEmbedReply(
fromRepeatMode,
toRepeatMode,
translator
);
queue.setRepeatMode(toRepeatMode);
logger.debug(`Loop mode changed to '${newRepeatModeEmbedName}'.`);
@@ -128,35 +148,48 @@ class LoopCommand extends BaseSlashCommandInteraction {
});
}
private getRepeatModeEmbedName(repeatMode: QueueRepeatMode): string {
private getRepeatModeEmbedName(repeatMode: QueueRepeatMode, translator: TFunction): string {
const repeatModeEmbedString: { [key in QueueRepeatMode]: string } = {
[QueueRepeatMode.OFF]: 'disabled',
[QueueRepeatMode.TRACK]: 'track',
[QueueRepeatMode.QUEUE]: 'queue',
[QueueRepeatMode.AUTOPLAY]: 'autoplay'
[QueueRepeatMode.OFF]: translator('commands.loop.repeatMode.off'),
[QueueRepeatMode.TRACK]: translator('commands.loop.repeatMode.track'),
[QueueRepeatMode.QUEUE]: translator('commands.loop.repeatMode.queue'),
[QueueRepeatMode.AUTOPLAY]: translator('commands.loop.repeatMode.autoplay')
};
return repeatModeEmbedString[repeatMode];
}
private getChangedRepeatModeEmbedReply(fromRepeatMode: QueueRepeatMode, toRepeatMode: QueueRepeatMode): string {
const fromRepeatModeEmbedName = this.getRepeatModeEmbedName(fromRepeatMode);
const toRepeatModeEmbedName = this.getRepeatModeEmbedName(toRepeatMode);
private getChangedRepeatModeEmbedReply(
fromRepeatMode: QueueRepeatMode,
toRepeatMode: QueueRepeatMode,
translator: TFunction
): string {
const fromRepeatModeEmbedName = this.getRepeatModeEmbedName(fromRepeatMode, translator);
const toRepeatModeEmbedName = this.getRepeatModeEmbedName(toRepeatMode, translator);
let repeatModeIcon = this.embedOptions.icons.looping;
let newRepeatModeMessage = `The ${toRepeatModeEmbedName} will now play on repeat!`;
let newRepeatModeMessage: string = translator('commands.loop.willNowPlay', {
mode: toRepeatModeEmbedName
});
if (toRepeatMode === QueueRepeatMode.OFF) {
repeatModeIcon = this.embedOptions.icons.success;
newRepeatModeMessage = `The ${fromRepeatModeEmbedName} will no longer play on repeat!`;
newRepeatModeMessage = translator('commands.loop.willNoLongerPlay', {
mode: fromRepeatModeEmbedName
});
} else if (toRepeatMode === QueueRepeatMode.AUTOPLAY) {
repeatModeIcon = this.embedOptions.icons.autoplaying;
newRepeatModeMessage = 'When the queue is empty, similar tracks will start playing!';
newRepeatModeMessage = translator('commands.loop.willAutoplay');
}
return (
`**${repeatModeIcon} Loop mode changed**\n` +
`Changing loop mode from **\`${fromRepeatModeEmbedName}\`** to **\`${toRepeatModeEmbedName}\`**.\n\n` +
translator('commands.loop.modeChanged', {
icon: repeatModeIcon,
fromName: fromRepeatModeEmbedName,
toName: toRepeatModeEmbedName
}) +
'\n' +
'\n' +
newRepeatModeMessage
);
}
+32 -15
View File
@@ -6,7 +6,8 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class LyricsCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -23,6 +24,7 @@ class LyricsCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
const query: string = interaction.options.getString('query')!;
@@ -50,14 +52,14 @@ class LyricsCommand extends BaseSlashCommandInteraction {
if (!finalLyricsData) {
logger.debug('No matching lyrics found.');
return await this.sendNoLyricsFoundEmbed(logger, interaction, geniusSearchQuery);
return await this.sendNoLyricsFoundEmbed(logger, interaction, geniusSearchQuery, translator);
}
if (finalLyricsData.lyrics.length > 3800) {
return await this.sendMultipleLyricsMessages(logger, interaction, finalLyricsData);
return await this.sendMultipleLyricsMessages(logger, interaction, finalLyricsData, translator);
}
return await this.sendLyricsEmbed(logger, interaction, finalLyricsData);
return await this.sendLyricsEmbed(logger, interaction, finalLyricsData, translator);
}
private getGeniusSearchQuery(logger: Logger, query: string, queue: GuildQueue): string {
@@ -155,15 +157,18 @@ class LyricsCommand extends BaseSlashCommandInteraction {
private async sendNoLyricsFoundEmbed(
logger: Logger,
interaction: ChatInputCommandInteraction,
geniusSearchQuery: string
geniusSearchQuery: string,
translator: TFunction
) {
logger.debug('Responding with warning embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} No lyrics found**\n` +
`There was no Genius lyrics found for track **${geniusSearchQuery}**.`
translator('commands.lyrics.noLyricsFound', {
icon: this.embedOptions.icons.warning,
query: geniusSearchQuery
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -173,7 +178,8 @@ class LyricsCommand extends BaseSlashCommandInteraction {
private async sendMultipleLyricsMessages(
logger: Logger,
interaction: ChatInputCommandInteraction,
geniusLyricsResult: LyricsData
geniusLyricsResult: LyricsData,
translator: TFunction
): Promise<Message> {
logger.debug('Lyrics text too long, splitting into multiple messages.');
const messageCount: number = Math.ceil(geniusLyricsResult.lyrics.length / 3800);
@@ -181,9 +187,13 @@ class LyricsCommand extends BaseSlashCommandInteraction {
embedList.push(
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.queue} Showing lyrics**\n` +
`**Track: [${geniusLyricsResult.title}](${geniusLyricsResult.url})**\n` +
`**Artist: [${geniusLyricsResult.artist.name}](${geniusLyricsResult.artist.url})**\n\n`
translator('commands.lyrics.lyricsEmbed', {
icon: this.embedOptions.icons.queue,
trackTitle: geniusLyricsResult.title,
trackUrl: geniusLyricsResult.url,
artistName: geniusLyricsResult.artist.name,
artistUrl: geniusLyricsResult.artist.url
})
)
.setColor(this.embedOptions.colors.info)
);
@@ -204,16 +214,23 @@ class LyricsCommand extends BaseSlashCommandInteraction {
private async sendLyricsEmbed(
logger: Logger,
interaction: ChatInputCommandInteraction,
geniusLyricsResult: LyricsData
geniusLyricsResult: LyricsData,
translator: TFunction
): Promise<Message> {
logger.debug('Responding with info embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.queue} Showing lyrics**\n` +
`**Track: [${geniusLyricsResult.title}](${geniusLyricsResult.url})**\n` +
`**Artist: [${geniusLyricsResult.artist.name}](${geniusLyricsResult.artist.url})**\n\n` +
translator('commands.lyrics.lyricsEmbed', {
icon: this.embedOptions.icons.queue,
trackTitle: geniusLyricsResult.title,
trackUrl: geniusLyricsResult.url,
artistName: geniusLyricsResult.artist.name,
artistUrl: geniusLyricsResult.artist.url
}) +
'\n' +
'\n' +
`\`\`\`fix\n${geniusLyricsResult.lyrics}\`\`\``
)
.setColor(this.embedOptions.colors.info)
+34 -13
View File
@@ -5,7 +5,9 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
class MoveCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -21,6 +23,7 @@ class MoveCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -33,7 +36,14 @@ class MoveCommand extends BaseSlashCommandInteraction {
const fromPositionInput: number = interaction.options.getInteger('from')!;
const toPositionInput: number = interaction.options.getInteger('to')!;
return await this.handleMoveTrackToPosition(logger, interaction, queue, fromPositionInput, toPositionInput);
return await this.handleMoveTrackToPosition(
logger,
interaction,
queue,
fromPositionInput,
toPositionInput,
translator
);
}
private async handleMoveTrackToPosition(
@@ -41,7 +51,8 @@ class MoveCommand extends BaseSlashCommandInteraction {
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
fromPosition: number,
toPosition: number
toPosition: number,
translator: TFunction
) {
if (fromPosition > queue.tracks.data.length || toPosition > queue.tracks.data.length) {
logger.debug('One of the specified track positions was higher than total tracks.');
@@ -50,13 +61,14 @@ class MoveCommand extends BaseSlashCommandInteraction {
toPosition,
queue,
logger,
interaction
interaction,
translator
);
} else {
const trackToMove: Track = queue.tracks.data[fromPosition - 1];
queue.node.move(trackToMove, toPosition - 1);
logger.debug(`Moved track from position ${fromPosition} to position ${toPosition} in queue`);
return await this.respondWithSuccessEmbed(trackToMove, interaction, fromPosition, toPosition);
return await this.respondWithSuccessEmbed(trackToMove, interaction, fromPosition, toPosition, translator);
}
}
@@ -65,16 +77,21 @@ class MoveCommand extends BaseSlashCommandInteraction {
toPosition: number,
queue: GuildQueue,
logger: Logger,
interaction: ChatInputCommandInteraction
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
logger.debug('One of the specified track positions was higher than total tracks.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`You cannot move track in position **\`${fromPosition}\`** to position **\`${toPosition}\`**. There are only **\`${queue.tracks.data.length}\`** tracks in the queue.\n\n` +
'View tracks added to the queue with **`/queue`**.'
translator('commands.move.trackPositionHigherThanQueueLength', {
icon: this.embedOptions.icons.warning,
fromPosition,
toPosition,
count: queue.tracks.data.length,
queueCommand: formatSlashCommand('queue', translator)
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -85,16 +102,20 @@ class MoveCommand extends BaseSlashCommandInteraction {
movedTrack: Track,
interaction: ChatInputCommandInteraction,
fromPosition: number,
toPosition: number
toPosition: number,
translator: TFunction
) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.moved} Moved track**\n` +
`${this.getDisplayTrackDurationAndUrl(movedTrack)}\n\n` +
`Track has been moved from position **\`${fromPosition}\`** to position **\`${toPosition}\`**.`
translator('commands.move.trackMoved', {
icon: this.embedOptions.icons.moved,
track: this.getDisplayTrackDurationAndUrl(movedTrack, translator),
fromPosition,
toPosition
})
)
.setThumbnail(this.getTrackThumbnailUrl(movedTrack))
.setColor(this.embedOptions.colors.success)
@@ -14,7 +14,7 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
class NowPlayingCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -25,6 +25,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -37,11 +38,11 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
const tracksInQueueCount: number = queue.tracks.data.length;
const currentTrack: Track = queue.currentTrack!;
const displayTrackUrl: string = this.getFormattedTrackUrl(currentTrack);
const displayTrackRequestedBy: string = this.getDisplayTrackRequestedBy(currentTrack);
const displayTrackUrl: string = this.getFormattedTrackUrl(currentTrack, translator);
const displayTrackRequestedBy: string = this.getDisplayTrackRequestedBy(currentTrack, translator);
const displayTrackPlayingStatus: string = this.getDisplayTrackPlayingStatus(queue);
const displayQueueRepeatMode: string = this.getDisplayQueueRepeatMode(queue);
const displayEmbedProgressBar: string = this.getDisplayQueueProgressBar(queue);
const displayEmbedProgressBar: string = this.getDisplayQueueProgressBar(queue, translator);
const components: APIMessageActionRowComponent[] = [];
@@ -82,7 +83,7 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedQueueAuthor(interaction, queue))
.setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator))
.setDescription(
`${displayTrackPlayingStatus}\n` +
`${displayTrackUrl}\n` +
+12 -4
View File
@@ -5,7 +5,7 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
class PauseCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -16,6 +16,7 @@ class PauseCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -36,9 +37,16 @@ class PauseCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.pauseResumed} ${
queue.node.isPaused() ? 'Paused Track' : 'Resumed track'
}**\n ${this.getDisplayTrackDurationAndUrl(currentTrack)}`
translator(
queue.node.isPaused()
? 'commands.pause.pauseConfirmation'
: 'commands.pause.resumeConfirmation',
{
icon: this.embedOptions.icons.success
}
) +
'\n' +
this.getDisplayTrackDurationAndUrl(currentTrack, translator)
)
.setThumbnail(currentTrack.thumbnail)
.setColor(this.embedOptions.colors.success)
+46 -18
View File
@@ -6,7 +6,9 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkVoicePermissionJoinAndTalk } from '../../../utils/validation/permissionValidator';
import { transformQuery } from '../../../utils/validation/searchQueryValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
class PlayCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -23,6 +25,7 @@ class PlayCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
await this.runValidators({ interaction, executionId }, [checkInVoiceChannel]);
@@ -39,14 +42,14 @@ class PlayCommand extends BaseSlashCommandInteraction {
const searchResult = await this.searchTrack(player, transformedQuery, interaction, logger);
if (!searchResult || searchResult.tracks.length === 0) {
return await this.handleNoResultsFound(transformedQuery, interaction, logger);
return await this.handleNoResultsFound(transformedQuery, interaction, logger, translator);
}
queue = useQueue(interaction.guild!.id)!;
const queueSize = queue?.size ?? 0;
if ((searchResult.playlist! && searchResult.tracks.length) > this.playerOptions.maxQueueSize - queueSize) {
return await this.handlePlaylistTooLarge(searchQuery, interaction, logger);
return await this.handlePlaylistTooLarge(searchQuery, interaction, logger, translator);
}
const track: Track | void = await this.addResultsToPlayer(
@@ -63,7 +66,7 @@ class PlayCommand extends BaseSlashCommandInteraction {
throw new Error('Failed to add track to player.');
}
return await this.handleResultAddedToQueue(track, searchResult, interaction, logger);
return await this.handleResultAddedToQueue(track, searchResult, interaction, logger, translator);
}
private async searchTrack(
@@ -145,18 +148,39 @@ class PlayCommand extends BaseSlashCommandInteraction {
track: Track,
searchResult: SearchResult,
interaction: ChatInputCommandInteraction,
logger: Logger
logger: Logger,
translator: TFunction
): Promise<Message> {
logger.debug('Result found and added with player.play(), added to queue.');
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
const trackUrl = this.getDisplayTrackDurationAndUrl(track);
const trackUrl = this.getDisplayTrackDurationAndUrl(track, translator);
let message = `${this.embedOptions.icons.success} **Added to queue**\n${trackUrl}`;
let message =
translator('commands.play.addedToQueueTitle', {
icon: this.embedOptions.icons.success
}) +
'\n' +
trackUrl;
if (searchResult.playlist) {
const otherTracksString = `And **${searchResult.tracks.length}** more tracks... **\`/queue\`** to view all.`;
message = `${this.embedOptions.icons.success} **Added playlist to queue**\n${trackUrl}\n\n${otherTracksString}`;
message =
translator('commands.play.playlistAddedTitle', {
icon: this.embedOptions.icons.success
}) +
'\n' +
trackUrl +
'\n' +
'\n' +
translator('commands.play.playlistAddedTrackCount', {
count: searchResult.tracks.length,
queueCommand: formatSlashCommand('queue', translator)
});
} else if (queue.currentTrack === track && queue.tracks.data.length === 0) {
message = `**${this.embedOptions.icons.audioStartedPlaying} Now playing**\n${trackUrl}`;
message =
translator('musicPlayerCommon.nowPlayingTitle', {
icon: this.embedOptions.icons.audioStartedPlaying
}) +
'\n' +
trackUrl;
}
logger.debug('Responding with success embed.');
@@ -174,7 +198,8 @@ class PlayCommand extends BaseSlashCommandInteraction {
private async handleNoResultsFound(
transformedQuery: string,
interaction: ChatInputCommandInteraction,
logger: Logger
logger: Logger,
translator: TFunction
): Promise<Message> {
logger.debug(`No results found for query: '${transformedQuery}'`);
@@ -183,9 +208,10 @@ class PlayCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} No track found**\n` +
`No results found for **\`${transformedQuery}\`**.\n\n` +
'If you specified a URL, please make sure it is valid and public.'
translator('commands.play.trackNotFound', {
icon: this.embedOptions.icons.warning,
query: transformedQuery
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -195,7 +221,8 @@ class PlayCommand extends BaseSlashCommandInteraction {
private async handlePlaylistTooLarge(
query: string,
interaction: ChatInputCommandInteraction,
logger: Logger
logger: Logger,
translator: TFunction
): Promise<Message> {
logger.debug(`Playlist found but would exceed max queue size. Query: '${query}'.`);
@@ -204,9 +231,10 @@ class PlayCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Playlist too large**\n` +
'This playlist is too large to be added to the queue.\n\n' +
`The maximum amount of tracks that can be added to the queue is **${this.playerOptions.maxQueueSize}**.`
translator('commands.play.playlistTooLarge', {
icon: this.embedOptions.icons.warning,
count: this.playerOptions.maxQueueSize
})
)
.setColor(this.embedOptions.colors.warning)
]
+52 -24
View File
@@ -17,7 +17,8 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { formatDuration } from '../../../common/formattingUtils';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class QueueCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -32,6 +33,7 @@ class QueueCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -48,14 +50,21 @@ class QueueCommand extends BaseSlashCommandInteraction {
return await this.handleInvalidPage(logger, interaction, pageIndex, totalPages);
}
const queueTracksListString: string = this.getQueueTracksListString(queue, pageIndex);
const queueTracksListString: string = this.getQueueTracksListString(queue, pageIndex, translator);
const currentTrack: Track = queue.currentTrack!;
if (currentTrack) {
return await this.handleCurrentTrack(logger, interaction, queue, currentTrack, queueTracksListString);
return await this.handleCurrentTrack(
logger,
interaction,
queue,
currentTrack,
queueTracksListString,
translator
);
}
return await this.handleNoCurrentTrack(logger, interaction, queue, queueTracksListString);
return await this.handleNoCurrentTrack(logger, interaction, queue, queueTracksListString, translator);
}
private async handleCurrentTrack(
@@ -63,7 +72,8 @@ class QueueCommand extends BaseSlashCommandInteraction {
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
currentTrack: Track,
queueTracksListString: string
queueTracksListString: string,
translator: TFunction
) {
logger.debug('Queue exists with current track, gathering information.');
@@ -92,9 +102,11 @@ class QueueCommand extends BaseSlashCommandInteraction {
components.push(skipButton);
if (this.embedOptions.components.showButtonLabels) {
previousButton.label = 'Previous';
playPauseButton.label = queue.node.isPaused() ? 'Resume' : 'Pause';
skipButton.label = 'Skip';
previousButton.label = translator('musicPlayerCommon.controls.previous');
playPauseButton.label = queue.node.isPaused()
? translator('musicPlayerCommon.controls.resume')
: translator('musicPlayerCommon.controls.pause');
skipButton.label = translator('musicPlayerCommon.controls.skip');
}
const embedActionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
@@ -106,18 +118,29 @@ class QueueCommand extends BaseSlashCommandInteraction {
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedQueueAuthor(interaction, queue))
.setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator))
.setDescription(
`**${this.embedOptions.icons.audioPlaying} Now playing**\n` +
`${this.getFormattedTrackUrl(currentTrack)}\n` +
`**Requested by:** ${this.getDisplayTrackRequestedBy(currentTrack)}\n` +
`${this.getDisplayQueueProgressBar(queue)}\n\n` +
`${this.getDisplayRepeatMode(queue.repeatMode)}` +
`**${this.embedOptions.icons.queue} Tracks in queue**\n` +
translator('musicPlayerCommon.nowPlayingTitle', {
icon: this.embedOptions.icons.audioPlaying
}) +
this.getFormattedTrackUrl(currentTrack, translator) +
'\n' +
translator('musicPlayerCommon.requestedBy', {
user: this.getDisplayTrackRequestedBy(currentTrack, translator)
}) +
'\n' +
this.getDisplayQueueProgressBar(queue, translator) +
'\n' +
'\n' +
this.getDisplayRepeatMode(queue.repeatMode, translator) +
translator('commands.queue.tracksInQueueTitle', {
icon: this.embedOptions.icons.queue
}) +
'\n' +
queueTracksListString
)
.setThumbnail(this.getTrackThumbnailUrl(currentTrack))
.setFooter(this.getDisplayFullFooterInfo(interaction, queue))
.setFooter(this.getDisplayFullFooterInfo(interaction, queue, translator))
.setColor(this.embedOptions.colors.info)
],
components: [embedActionRow]
@@ -129,7 +152,8 @@ class QueueCommand extends BaseSlashCommandInteraction {
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
queueTracksListString: string
queueTracksListString: string,
translator: TFunction
) {
logger.debug('Queue exists but there is no current track.');
@@ -137,13 +161,13 @@ class QueueCommand extends BaseSlashCommandInteraction {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedQueueAuthor(interaction, queue))
.setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator))
.setDescription(
`${this.getDisplayRepeatMode(queue.repeatMode)}` +
`${this.getDisplayRepeatMode(queue.repeatMode, translator)}` +
`**${this.embedOptions.icons.queue} Tracks in queue**\n` +
queueTracksListString
)
.setFooter(this.getDisplayFullFooterInfo(interaction, queue))
.setFooter(this.getDisplayFullFooterInfo(interaction, queue, translator))
.setColor(this.embedOptions.colors.info)
]
});
@@ -180,7 +204,7 @@ class QueueCommand extends BaseSlashCommandInteraction {
return Math.ceil(queue.tracks.data.length / 10) || 1;
}
private getQueueTracksListString(queue: GuildQueue, pageIndex: number): string {
private getQueueTracksListString(queue: GuildQueue, pageIndex: number, translator: TFunction): string {
if (!queue || queue.tracks.data.length === 0) {
return 'The queue is empty, add some tracks with **`/play`**!';
}
@@ -188,7 +212,7 @@ class QueueCommand extends BaseSlashCommandInteraction {
return queue.tracks.data
.slice(pageIndex * 10, pageIndex * 10 + 10)
.map((track, index) => {
return `**${pageIndex * 10 + index + 1}.** ${this.getDisplayTrackDurationAndUrl(track)}`;
return `**${pageIndex * 10 + index + 1}.** ${this.getDisplayTrackDurationAndUrl(track, translator)}`;
})
.join('\n');
}
@@ -210,8 +234,12 @@ class QueueCommand extends BaseSlashCommandInteraction {
return `Estimated duration: ${formatDuration(queueDurationMs)}`;
}
private getDisplayFullFooterInfo(interaction: ChatInputCommandInteraction, queue: GuildQueue): EmbedFooterData {
const pagination = this.getFooterDisplayPageInfo(interaction, queue);
private getDisplayFullFooterInfo(
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
): EmbedFooterData {
const pagination = this.getFooterDisplayPageInfo(interaction, queue, translator);
const totalDuration = this.getDisplayQueueTotalDuration(queue);
const fullFooterData = {
+88 -36
View File
@@ -5,6 +5,9 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { TFunction } from 'i18next';
import { useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
class RemoveCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -63,6 +66,7 @@ class RemoveCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -76,21 +80,26 @@ class RemoveCommand extends BaseSlashCommandInteraction {
switch (subcommand) {
case 'track':
return await this.handleRemovedTrack(logger, interaction, queue);
return await this.handleRemovedTrack(logger, interaction, queue, translator);
case 'range':
return await this.handleRemoveRange(logger, interaction, queue);
return await this.handleRemoveRange(logger, interaction, queue, translator);
case 'queue':
return await this.handleRemoveQueue(logger, interaction, queue);
return await this.handleRemoveQueue(logger, interaction, queue, translator);
case 'user':
return await this.handleRemoveUserTracks(logger, interaction, queue);
return await this.handleRemoveUserTracks(logger, interaction, queue, translator);
case 'duplicates':
return await this.handleRemoveDuplicates(logger, interaction, queue);
return await this.handleRemoveDuplicates(logger, interaction, queue, translator);
default:
return Promise.resolve();
}
}
private async handleRemoveUserTracks(logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue) {
private async handleRemoveUserTracks(
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
) {
const targetUser = interaction.options.getUser('target')!;
const removedTracks: Track[] = [];
queue.tracks.data.forEach((track) => {
@@ -103,15 +112,20 @@ class RemoveCommand extends BaseSlashCommandInteraction {
});
if (removedTracks.length === 0) {
return await this.handleNoTracksRemoved(logger, interaction);
return await this.handleNoTracksRemoved(logger, interaction, translator);
}
logger.debug(`Removed ${removedTracks.length} tracks from queue added by a user.`);
return await this.handleResponseRemovedTracks(logger, interaction, removedTracks.length);
return await this.handleResponseRemovedTracks(logger, interaction, removedTracks.length, translator);
}
private async handleRemoveDuplicates(logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue) {
private async handleRemoveDuplicates(
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
) {
const removedTracks: Track[] = [];
const uniqueTrackUrls = new Set<string>();
queue.tracks.data.forEach((track) => {
@@ -126,20 +140,25 @@ class RemoveCommand extends BaseSlashCommandInteraction {
});
if (removedTracks.length === 0) {
return await this.handleNoTracksRemoved(logger, interaction);
return await this.handleNoTracksRemoved(logger, interaction, translator);
}
logger.debug(`Removed ${removedTracks.length} duplicate tracks from queue.`);
return await this.handleResponseRemovedTracks(logger, interaction, removedTracks.length);
return await this.handleResponseRemovedTracks(logger, interaction, removedTracks.length, translator);
}
private async handleRemoveRange(logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue) {
private async handleRemoveRange(
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
) {
const start: number = interaction.options.getInteger('start')!;
const end: number = interaction.options.getInteger('end')!;
if (start > queue.tracks.data.length || end > queue.tracks.data.length) {
return await this.handleTrackPositionHigherThanQueueLength(logger, interaction, start, queue);
return await this.handleTrackPositionHigherThanQueueLength(logger, interaction, start, queue, translator);
} else if (start > end) {
logger.debug('Start position is higher than end position.');
@@ -148,9 +167,12 @@ class RemoveCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`Start position **\`${start}\`** is higher than end position **\`${end}\`**. Please specify a valid range.` +
'\n\nView tracks added to the queue with **`/queue`**.'
translator('commands.remove.startPositionHigherThanEndPosition', {
icon: this.embedOptions.icons.warning,
start,
end,
queueCommand: formatSlashCommand('queue', translator)
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -167,32 +189,48 @@ class RemoveCommand extends BaseSlashCommandInteraction {
}
if (removedTracks.length === 0) {
return await this.handleNoTracksRemoved(logger, interaction);
return await this.handleNoTracksRemoved(logger, interaction, translator);
}
logger.debug(`Removed ${removedTracks.length} tracks from queue.`);
return await this.handleResponseRemovedTracks(logger, interaction, removedTracks.length);
return await this.handleResponseRemovedTracks(logger, interaction, removedTracks.length, translator);
}
private async handleRemoveQueue(logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue) {
private async handleRemoveQueue(
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
) {
const queueLength = queue.tracks.data.length;
queue.clear();
if (queueLength === 0) {
return await this.handleNoTracksRemoved(logger, interaction);
return await this.handleNoTracksRemoved(logger, interaction, translator);
}
logger.debug('Cleared the queue and removed all tracks.');
return await this.handleResponseRemovedTracks(logger, interaction, queueLength);
return await this.handleResponseRemovedTracks(logger, interaction, queueLength, translator);
}
private async handleRemovedTrack(logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue) {
private async handleRemovedTrack(
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
) {
const trackPositionInput: number = interaction.options.getInteger('position')!;
if (trackPositionInput > queue.tracks.data.length) {
return await this.handleTrackPositionHigherThanQueueLength(logger, interaction, trackPositionInput, queue);
return await this.handleTrackPositionHigherThanQueueLength(
logger,
interaction,
trackPositionInput,
queue,
translator
);
}
const removedTrack: Track = queue.node.remove(trackPositionInput - 1)!;
@@ -204,9 +242,11 @@ class RemoveCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Removed track**\n${this.getDisplayTrackDurationAndUrl(
removedTrack
)}`
translator('commands.remove.removedTrack', {
icon: this.embedOptions.icons.success
}) +
'\n' +
this.getDisplayTrackDurationAndUrl(removedTrack, translator)
)
.setThumbnail(this.getTrackThumbnailUrl(removedTrack))
.setColor(this.embedOptions.colors.success)
@@ -215,15 +255,20 @@ class RemoveCommand extends BaseSlashCommandInteraction {
return Promise.resolve();
}
private async handleNoTracksRemoved(logger: Logger, interaction: ChatInputCommandInteraction) {
private async handleNoTracksRemoved(
logger: Logger,
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
logger.debug('Responding with warning embed.');
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.warning} No tracks removed**\n` +
'There were no tracks removed from the queue. Please check if the option you selected has tracks to remove.'
translator('commands.remove.noTracksRemoved', {
icon: this.embedOptions.icons.warning
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -234,7 +279,8 @@ class RemoveCommand extends BaseSlashCommandInteraction {
private async handleResponseRemovedTracks(
logger: Logger,
interaction: ChatInputCommandInteraction,
removedAmount: number
removedAmount: number,
translator: TFunction
) {
logger.debug('Responding with success embed.');
await interaction.editReply({
@@ -242,8 +288,10 @@ class RemoveCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Removed tracks**\n` +
`**\`${removedAmount}\`** tracks were removed from the queue.`
translator('commands.remove.removedTracks', {
icon: this.embedOptions.icons.success,
count: removedAmount
})
)
.setColor(this.embedOptions.colors.success)
]
@@ -255,7 +303,8 @@ class RemoveCommand extends BaseSlashCommandInteraction {
logger: Logger,
interaction: ChatInputCommandInteraction,
trackPositionInput: number,
queue: GuildQueue
queue: GuildQueue,
translator: TFunction
) {
logger.debug('Specified track position is higher than total tracks.');
@@ -264,9 +313,12 @@ class RemoveCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`Position **\`${trackPositionInput}\`** is not a valid track position. There are only a total of **\`${queue.tracks.data.length}\`** tracks in the queue.` +
'\n\nView tracks added to the queue with **`/queue`**.'
translator('commands.skip.trackPositionHigherThanQueueLength', {
icon: this.embedOptions.icons.warning,
position: trackPositionInput,
count: queue.tracks.data.length,
queueCommand: formatSlashCommand('queue', translator)
})
)
.setColor(this.embedOptions.colors.warning)
]
+32 -21
View File
@@ -5,7 +5,8 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class SeekCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -20,6 +21,7 @@ class SeekCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -34,14 +36,20 @@ class SeekCommand extends BaseSlashCommandInteraction {
const formattedDurationString: string = this.parseDurationArray(durationInputSplit);
if (!this.validateDurationFormat(formattedDurationString)) {
return await this.handleInvalidDurationFormat(logger, interaction, formattedDurationString);
return await this.handleInvalidDurationFormat(logger, interaction, formattedDurationString, translator);
}
const currentTrackMaxDurationInMs: number = queue.currentTrack!.durationMS;
const inputDurationInMilliseconds: number = this.getDurationInputInMilliseconds(durationInputSplit);
if (inputDurationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
return await this.handleDurationLongerThanTrack(logger, interaction, formattedDurationString, queue);
return await this.handleDurationLongerThanTrack(
logger,
interaction,
formattedDurationString,
queue,
translator
);
}
return await this.seekToDurationInCurrentTrack(
@@ -49,14 +57,16 @@ class SeekCommand extends BaseSlashCommandInteraction {
interaction,
queue,
inputDurationInMilliseconds,
formattedDurationString
formattedDurationString,
translator
);
}
private async handleInvalidDurationFormat(
logger: Logger,
interaction: ChatInputCommandInteraction,
formattedDurationString: string
formattedDurationString: string,
translator: TFunction
): Promise<Message> {
logger.debug('Invalid duration format input.');
@@ -65,13 +75,10 @@ class SeekCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`You entered an invalid duration format, **\`${formattedDurationString}\`**.\n` +
'Please use the format **`HH:mm:ss`**, **`mm:ss`** or **`ss`**.\n\n' +
'**Examples:**\n' +
'- **`/seek`** **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' +
'- **`/seek`** **`3:27`** - Seek to 3 minutes and 27 seconds.\n' +
'- **`/seek`** **`42`** - Seek to 42 seconds.'
translator('commands.seek.correctFormatInstruction', {
icon: this.embedOptions.icons.warning,
wrongDuration: formattedDurationString
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -83,7 +90,8 @@ class SeekCommand extends BaseSlashCommandInteraction {
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
durationInMilliseconds: number,
formattedDurationString: string
formattedDurationString: string,
translator: TFunction
): Promise<Message> {
queue.node.seek(durationInMilliseconds);
logger.debug(`Seeked to '${formattedDurationString}' in current track.`);
@@ -94,8 +102,10 @@ class SeekCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(await this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Seeking to duration**\n` +
`Seeking to **\`${formattedDurationString}\`** in current track.`
translator('commands.seek.seekingToTimestamp', {
icon: this.embedOptions.icons.success,
duration: formattedDurationString
})
)
.setThumbnail(this.getTrackThumbnailUrl(queue.currentTrack!))
.setColor(this.embedOptions.colors.success)
@@ -107,7 +117,8 @@ class SeekCommand extends BaseSlashCommandInteraction {
logger: Logger,
interaction: ChatInputCommandInteraction,
formattedDurationString: string,
queue: GuildQueue
queue: GuildQueue,
translator: TFunction
): Promise<Message> {
logger.debug('Duration specified is longer than the track duration.');
@@ -116,11 +127,11 @@ class SeekCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`You entered **\`${formattedDurationString}\`**, which is a duration that is longer than the duration for the current track.\n\n` +
`Please try a duration that is less than the duration of the track (**\`${
queue.currentTrack!.duration
}\`**).`
translator('commands.seek.durationLongerThanTrackDuration', {
icon: this.embedOptions.icons.warning,
wrongDuration: formattedDurationString,
trackDuration: queue.currentTrack!.duration
})
)
.setColor(this.embedOptions.colors.warning)
]
+8 -4
View File
@@ -4,7 +4,8 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueEmpty, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
class ShuffleCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -15,6 +16,7 @@ class ShuffleCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -34,9 +36,11 @@ class ShuffleCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.shuffled} Shuffled queue tracks**\n` +
`The **${queue.tracks.data.length}** tracks in the queue has been shuffled.\n\n` +
'View the new queue order with **`/queue`**.'
translator('commands.shuffle.shuffledTracks', {
icon: this.embedOptions.icons.shuffled,
count: queue.tracks.data.length,
queueCommand: formatSlashCommand('queue', translator)
})
)
.setColor(this.embedOptions.colors.success)
]
+51 -19
View File
@@ -5,7 +5,9 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
import { formatSlashCommand } from '../../../common/formattingUtils';
class SkipCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -20,6 +22,7 @@ class SkipCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -33,9 +36,9 @@ class SkipCommand extends BaseSlashCommandInteraction {
const trackPositionInput: number = interaction.options.getInteger('position')!;
if (trackPositionInput) {
return await this.handleSkipToTrackPosition(logger, interaction, queue, trackPositionInput);
return await this.handleSkipToTrackPosition(logger, interaction, queue, trackPositionInput, translator);
} else {
return await this.handleSkipToNextTrack(logger, interaction, queue);
return await this.handleSkipToNextTrack(logger, interaction, queue, translator);
}
}
@@ -43,15 +46,22 @@ class SkipCommand extends BaseSlashCommandInteraction {
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
trackPosition: number
trackPosition: number,
translator: TFunction
) {
if (trackPosition > queue.tracks.data.length) {
return await this.handleTrackPositionHigherThanQueueLength(trackPosition, queue, logger, interaction);
return await this.handleTrackPositionHigherThanQueueLength(
trackPosition,
queue,
logger,
interaction,
translator
);
} else {
const skippedTrack: Track = queue.currentTrack!;
queue.node.skipTo(trackPosition - 1);
logger.debug('Skipped to specified track position.');
return await this.respondWithSuccessEmbed(skippedTrack, interaction);
return await this.respondWithSuccessEmbed(skippedTrack, interaction, translator);
}
}
@@ -59,55 +69,77 @@ class SkipCommand extends BaseSlashCommandInteraction {
trackPosition: number,
queue: GuildQueue,
logger: Logger,
interaction: ChatInputCommandInteraction
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
logger.debug('Specified track position was higher than total tracks.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\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`**.'
translator('commands.skip.trackPositionHigherThanQueueLength', {
icon: this.embedOptions.icons.warning,
position: trackPosition,
queueCommand: formatSlashCommand('queue', translator),
count: queue.tracks.data.length
})
)
.setColor(this.embedOptions.colors.warning)
]
});
}
private async handleSkipToNextTrack(logger: Logger, interaction: ChatInputCommandInteraction, queue: GuildQueue) {
private async handleSkipToNextTrack(
logger: Logger,
interaction: ChatInputCommandInteraction,
queue: GuildQueue,
translator: TFunction
) {
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
return await this.handleNoTracksInQueueAndNoCurrentTrack(logger, interaction);
return await this.handleNoTracksInQueueAndNoCurrentTrack(logger, interaction, translator);
}
const skippedTrack: Track = queue.currentTrack!;
queue.node.skip();
logger.debug('Skipped current track.');
return await this.respondWithSuccessEmbed(skippedTrack, interaction);
return await this.respondWithSuccessEmbed(skippedTrack, interaction, translator);
}
private async handleNoTracksInQueueAndNoCurrentTrack(logger: Logger, interaction: ChatInputCommandInteraction) {
private async handleNoTracksInQueueAndNoCurrentTrack(
logger: Logger,
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
logger.debug('No tracks in queue and no current track.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
'The queue is empty, add some tracks with **`/play`**!'
translator('commands.skip.emptyQueue', {
icon: this.embedOptions.icons.warning,
playCommand: formatSlashCommand('play', translator)
})
)
.setColor(this.embedOptions.colors.warning)
]
});
}
private async respondWithSuccessEmbed(skippedTrack: Track, interaction: ChatInputCommandInteraction) {
private async respondWithSuccessEmbed(
skippedTrack: Track,
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.skipped} Skipped track**\n` +
`${this.getDisplayTrackDurationAndUrl(skippedTrack)}`
translator('commands.skip.skippedTrack', {
icon: this.embedOptions.icons.skipped
}) +
'\n' +
this.getDisplayTrackDurationAndUrl(skippedTrack, translator)
)
.setThumbnail(this.getTrackThumbnailUrl(skippedTrack))
.setColor(this.embedOptions.colors.success)
+7 -4
View File
@@ -4,7 +4,8 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { formatSlashCommand } from '../../../common/formattingUtils';
class StopCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -15,6 +16,7 @@ class StopCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -37,9 +39,10 @@ class StopCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Stopped playing**\n` +
'Stopped playing audio and cleared the track queue.\n\n' +
'To play more music, use the **`/play`** command!'
translator('commands.stop.stoppedPlaying', {
icon: this.embedOptions.icons.success,
playCommand: formatSlashCommand('play', translator)
})
)
.setColor(this.embedOptions.colors.success)
]
+35 -15
View File
@@ -5,7 +5,8 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
import { checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class VolumeCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -20,6 +21,7 @@ class VolumeCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -32,15 +34,20 @@ class VolumeCommand extends BaseSlashCommandInteraction {
const volume: number = interaction.options.getInteger('percentage')!;
if (!volume && volume !== 0) {
return await this.handleShowCurrentVolume(queue, logger, interaction);
return await this.handleShowCurrentVolume(queue, logger, interaction, translator);
} else if (volume > 100 || volume < 0) {
return await this.handleInvalidVolumeInput(volume, logger, interaction);
return await this.handleInvalidVolumeInput(volume, logger, interaction, translator);
} else {
return await this.handleValidVolumeInput(volume, queue, logger, interaction);
return await this.handleValidVolumeInput(volume, queue, logger, interaction, translator);
}
}
private async handleShowCurrentVolume(queue: GuildQueue, logger: Logger, interaction: ChatInputCommandInteraction) {
private async handleShowCurrentVolume(
queue: GuildQueue,
logger: Logger,
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
const currentVolume: number = queue.node.volume;
logger.debug('No volume input was provided, showing current volume.');
@@ -52,15 +59,22 @@ class VolumeCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${currentVolumeIcon} Playback volume**\n` +
`The playback volume is currently set to **\`${currentVolume}%\`**.`
translator('commands.volume.volumeInformation', {
icon: currentVolumeIcon,
volume: currentVolume
})
)
.setColor(this.embedOptions.colors.info)
]
});
}
private async handleInvalidVolumeInput(volume: number, logger: Logger, interaction: ChatInputCommandInteraction) {
private async handleInvalidVolumeInput(
volume: number,
logger: Logger,
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
logger.debug('Volume specified was higher than 100% or lower than 0%.');
logger.debug('Responding with warning embed.');
@@ -68,8 +82,10 @@ class VolumeCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
`You cannot set the volume to **\`${volume}%\`**, please pick a value betwen **\`1%\`** and **\`100%\`**.`
translator('commands.volume.invalidVolumeRange', {
icon: this.embedOptions.icons.warning,
wrongVolume: volume
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -80,7 +96,8 @@ class VolumeCommand extends BaseSlashCommandInteraction {
volume: number,
queue: GuildQueue,
logger: Logger,
interaction: ChatInputCommandInteraction
interaction: ChatInputCommandInteraction,
translator: TFunction
) {
queue.node.setVolume(volume);
logger.debug(`Set volume to ${volume}%.`);
@@ -92,8 +109,9 @@ class VolumeCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.volumeMuted} Audio muted**\n` +
`Playback audio has been muted, because volume was set to **\`${volume}%\`**.`
translator('commands.volume.volumeMuted', {
icon: this.embedOptions.icons.volumeMuted
})
)
.setColor(this.embedOptions.colors.success)
]
@@ -106,8 +124,10 @@ class VolumeCommand extends BaseSlashCommandInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.volumeChanged} Volume changed**\n` +
`Playback volume has been changed to **\`${volume}%\`**.`
translator('commands.volume.volumeChanged', {
icon: this.embedOptions.icons.volumeChanged,
volume
})
)
.setColor(this.embedOptions.colors.success)
]
+24 -7
View File
@@ -4,7 +4,8 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class GuildsCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -16,6 +17,7 @@ class GuildsCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
await this.runValidators({ interaction, executionId }, [checkValidGuildId]);
@@ -27,7 +29,12 @@ class GuildsCommand extends BaseSlashCommandInteraction {
const guildListFormatted = this.formatGuildListAsString(shardGuilds);
const totalMemberCount = this.calculateTotalMemberCount(shardGuilds);
let embedDescription = this.buildEmbedDescription(totalGuildCount, guildListFormatted, totalMemberCount);
let embedDescription = this.buildEmbedDescription(
totalGuildCount,
guildListFormatted,
totalMemberCount,
translator
);
if (embedDescription.length >= 4000) {
logger.debug('Embed description is too long, truncating.');
@@ -71,13 +78,23 @@ class GuildsCommand extends BaseSlashCommandInteraction {
private buildEmbedDescription(
totalGuildCount: number,
guildListFormattedString: string,
totalMemberCount: number
totalMemberCount: number,
translator: TFunction
): string {
const topGuildsString = totalGuildCount < 25 ? `Top ${totalGuildCount} guilds` : 'Top 25 guilds';
const guildCount = Math.max(totalGuildCount, 25);
return (
`**${this.embedOptions.icons.bot} ${topGuildsString} by member count (${totalGuildCount} total)**\n` +
`${guildListFormattedString}\n\n` +
`**Total members:** **\`${totalMemberCount}\`**`
translator('commands.guilds.topGuildsByMemberCount', {
icon: this.embedOptions.icons.bot,
count: guildCount,
totalCount: totalGuildCount
}) +
'\n' +
guildListFormattedString +
'\n' +
'\n' +
translator('commands.guilds.totalMembers', {
count: totalMemberCount
})
);
}
}
+21 -10
View File
@@ -10,7 +10,8 @@ import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { ExtendedClient } from '../../../types/clientTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkValidGuildId } from '../../../utils/validation/systemCommandValidator';
import { localizeCommand } from '../../../common/localeUtil';
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
import { TFunction } from 'i18next';
class ReloadCommand extends BaseSlashCommandInteraction {
constructor() {
@@ -22,16 +23,17 @@ class ReloadCommand extends BaseSlashCommandInteraction {
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
await this.runValidators({ interaction, executionId }, [checkValidGuildId]);
try {
await this.reloadInteractionsAcrossShards(logger, executionId, client!);
} catch (error) {
return await this.handleReloadError(logger, interaction, executionId, error);
return await this.handleReloadError(logger, interaction, executionId, error, translator);
}
return await this.respondWithSuccessEmbed(logger, interaction, client!);
return await this.respondWithSuccessEmbed(logger, interaction, client!, translator);
}
private async reloadInteractionsAcrossShards(logger: Logger, executionId: string, client: ExtendedClient) {
@@ -49,7 +51,8 @@ class ReloadCommand extends BaseSlashCommandInteraction {
logger: Logger,
interaction: ChatInputCommandInteraction,
executionId: string,
error: Error | unknown
error: Error | unknown,
translator: TFunction
) {
logger.error(error, 'Failed to reload interaction module across shards.');
@@ -58,8 +61,9 @@ class ReloadCommand extends BaseSlashCommandInteraction {
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.error} Oops!**\n` +
'_Hmm.._ It seems I am unable to reload interaction module across shards.'
translator('commands.reload.unableToReload', {
icon: this.embedOptions.icons.error
})
)
.setColor(this.embedOptions.colors.error)
.setFooter({ text: `Execution ID: ${executionId}` })
@@ -70,10 +74,11 @@ class ReloadCommand extends BaseSlashCommandInteraction {
private async respondWithSuccessEmbed(
logger: Logger,
interaction: ChatInputCommandInteraction,
client: ExtendedClient
client: ExtendedClient,
translator: TFunction
) {
const commands = this.getCommands(client);
const embedDescription = this.buildEmbedDescription(commands);
const embedDescription = this.buildEmbedDescription(commands, translator);
logger.debug('Responding with success embed.');
return await interaction.editReply({
@@ -102,8 +107,14 @@ class ReloadCommand extends BaseSlashCommandInteraction {
return params;
}
private buildEmbedDescription(commands: string[] | undefined): string {
return `**${this.embedOptions.icons.bot} Reloaded commands**\n` + commands?.join('\n');
private buildEmbedDescription(commands: string[] | undefined, translator: TFunction): string {
return (
translator('commands.reload.reloadedCommands', {
icon: this.embedOptions.icons.bot
}) +
'\n' +
commands?.join('\n')
);
}
}
@@ -4,6 +4,8 @@ import { BaseComponentInteraction } from '../../classes/interactions';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { TFunction } from 'i18next';
import { useServerTranslator } from '../../common/localeUtil';
class ActionPauseResumeButton extends BaseComponentInteraction {
constructor() {
@@ -13,6 +15,7 @@ class ActionPauseResumeButton extends BaseComponentInteraction {
async execute(params: BaseComponentParams): BaseComponentReturnType {
const { executionId, interaction, referenceId } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -41,7 +44,7 @@ class ActionPauseResumeButton extends BaseComponentInteraction {
}
logger.debug('Responding with success embed.');
return await this.handleSuccess(interaction, currentTrack, queue);
return await this.handleSuccess(interaction, currentTrack, queue, translator);
}
private async handleNoQueue(interaction: MessageComponentInteraction) {
@@ -70,14 +73,19 @@ class ActionPauseResumeButton extends BaseComponentInteraction {
});
}
private async handleSuccess(interaction: MessageComponentInteraction, track: Track, queue: GuildQueue) {
private async handleSuccess(
interaction: MessageComponentInteraction,
track: Track,
queue: GuildQueue,
translator: TFunction
) {
const successEmbed = new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.pauseResumed} ${
queue.node.isPaused() ? 'Paused Track' : 'Resumed track'
}**\n ${this.getDisplayTrackDurationAndUrl(queue.currentTrack!)}\n\n` +
`${this.getDisplayRepeatMode(queue.repeatMode, 'success')}`
}**\n ${this.getDisplayTrackDurationAndUrl(queue.currentTrack!, translator)}\n\n` +
`${this.getDisplayRepeatMode(queue.repeatMode, translator, 'success')}`
)
.setThumbnail(track.thumbnail)
.setColor(this.embedOptions.colors.success);
@@ -5,6 +5,9 @@ import { BaseComponentParams, BaseComponentReturnType } from '../../types/intera
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { Logger } from 'pino';
import { TFunction } from 'i18next';
import { useServerTranslator } from '../../common/localeUtil';
import { formatSlashCommand } from '../../common/formattingUtils';
class ActionPreviousButton extends BaseComponentInteraction {
constructor() {
@@ -14,6 +17,7 @@ class ActionPreviousButton extends BaseComponentInteraction {
async execute(params: BaseComponentParams): BaseComponentReturnType {
const { executionId, interaction, referenceId } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
const history: GuildQueueHistory = useHistory(interaction.guild!.id)!;
@@ -33,32 +37,39 @@ class ActionPreviousButton extends BaseComponentInteraction {
return await this.handleAlreadySkipped(interaction);
}
return await this.handleBackToPreviousTrack(logger, interaction, history);
return await this.handleBackToPreviousTrack(logger, interaction, history, translator);
}
private async handleBackToPreviousTrack(
logger: Logger,
interaction: MessageComponentInteraction,
history: GuildQueueHistory
history: GuildQueueHistory,
translator: TFunction
) {
if (history.tracks.data.length === 0) {
return await this.handleNoTracksInHistory(logger, interaction);
return await this.handleNoTracksInHistory(logger, interaction, translator);
}
await history.back();
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
const currentTrack: Track = queue.currentTrack!;
logger.debug('Recovered track from history.');
return await this.handleSuccess(interaction, currentTrack);
return await this.handleSuccess(interaction, currentTrack, translator);
}
private async handleNoTracksInHistory(logger: Logger, interaction: MessageComponentInteraction) {
private async handleNoTracksInHistory(
logger: Logger,
interaction: MessageComponentInteraction,
translator: TFunction
) {
logger.debug('No tracks in history.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.warning} Oops!**\n` +
'The history is empty, add some tracks with **`/play`**!'
translator('commands.back.trackHistoryEmpty', {
icon: this.embedOptions.icons.warning,
playCommand: formatSlashCommand('play', translator)
})
)
.setColor(this.embedOptions.colors.warning)
]
@@ -91,12 +102,16 @@ class ActionPreviousButton extends BaseComponentInteraction {
});
}
private async handleSuccess(interaction: MessageComponentInteraction, recoveredTrack: Track) {
private async handleSuccess(
interaction: MessageComponentInteraction,
recoveredTrack: Track,
translator: TFunction
) {
const successEmbed = new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.back} Recovered track**\n` +
`${this.getDisplayTrackDurationAndUrl(recoveredTrack)}`
`${this.getDisplayTrackDurationAndUrl(recoveredTrack, translator)}`
)
.setThumbnail(recoveredTrack.thumbnail)
.setColor(this.embedOptions.colors.success);
@@ -4,6 +4,8 @@ import { BaseComponentInteraction } from '../../classes/interactions';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { TFunction } from 'i18next';
import { useServerTranslator } from '../../common/localeUtil';
class ActionSkipButton extends BaseComponentInteraction {
constructor() {
@@ -13,6 +15,7 @@ class ActionSkipButton extends BaseComponentInteraction {
async execute(params: BaseComponentParams): BaseComponentReturnType {
const { executionId, interaction, referenceId } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -36,7 +39,7 @@ class ActionSkipButton extends BaseComponentInteraction {
logger.debug('Skipped the track.');
logger.debug('Responding with success embed.');
return await this.handleSuccess(interaction, skippedTrack, queue);
return await this.handleSuccess(interaction, skippedTrack, queue, translator);
}
private async handleNoQueue(interaction: MessageComponentInteraction) {
@@ -65,13 +68,18 @@ class ActionSkipButton extends BaseComponentInteraction {
});
}
private async handleSuccess(interaction: MessageComponentInteraction, skippedTrack: Track, queue: GuildQueue) {
private async handleSuccess(
interaction: MessageComponentInteraction,
skippedTrack: Track,
queue: GuildQueue,
translator: TFunction
) {
const successEmbed = new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.skipped} Skipped track**\n` +
`${this.getDisplayTrackDurationAndUrl(skippedTrack)}\n\n` +
`${this.getDisplayRepeatMode(queue.repeatMode, 'success')}`
`${this.getDisplayTrackDurationAndUrl(skippedTrack, translator)}\n\n` +
`${this.getDisplayRepeatMode(queue.repeatMode, translator, 'success')}`
)
.setThumbnail(skippedTrack.thumbnail)
.setColor(this.embedOptions.colors.success);
@@ -5,6 +5,7 @@ import { BaseComponentInteraction } from '../../classes/interactions';
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { useServerTranslator } from '../../common/localeUtil';
class FiltersDisableButtonComponent extends BaseComponentInteraction {
constructor() {
@@ -14,6 +15,7 @@ class FiltersDisableButtonComponent extends BaseComponentInteraction {
async execute(params: BaseComponentParams): BaseComponentReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
@@ -31,8 +33,9 @@ class FiltersDisableButtonComponent extends BaseComponentInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Disabled filters**\n` +
'All audio filters have been disabled.'
translator('commands.filters.allFiltersDisabled', {
icon: this.embedOptions.icons.success
})
)
.setColor(this.embedOptions.colors.success)
],
@@ -12,6 +12,8 @@ import {
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
import { checkQueueExists } from '../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
import { useServerTranslator } from '../../common/localeUtil';
import { TFunction } from 'i18next';
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
const biquadFilterOptions: BiquadFilterOptions = config.get('biquadFilterOptions');
@@ -25,6 +27,7 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
async execute(params: BaseComponentParams): BaseComponentReturnType {
const { executionId, interaction, referenceId } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const translator = useServerTranslator(interaction);
const filterType = referenceId;
logger.debug('Received select menu interaction.');
@@ -41,16 +44,34 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
this.resetFilters(queue, logger);
if (selectMenuInteraction.values.length === 0) {
return await this.replyWithDisabledFiltersEmbed(logger, selectMenuInteraction);
return await this.replyWithDisabledFiltersEmbed(logger, selectMenuInteraction, translator);
}
switch (filterType) {
case 'ffmpeg':
return await this.handleFfmpegFilterToggle(logger, selectMenuInteraction, queue, filterType);
return await this.handleFfmpegFilterToggle(
logger,
selectMenuInteraction,
queue,
filterType,
translator
);
case 'biquad':
return await this.handleBiquadFilterToggle(logger, selectMenuInteraction, queue, filterType);
return await this.handleBiquadFilterToggle(
logger,
selectMenuInteraction,
queue,
filterType,
translator
);
case 'equalizer':
return await this.handleEqualizerFilterToggle(logger, selectMenuInteraction, queue, filterType);
return await this.handleEqualizerFilterToggle(
logger,
selectMenuInteraction,
queue,
filterType,
translator
);
default:
logger.warn(`Unknown filter type '${filterType}'.`);
return;
@@ -61,37 +82,40 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
logger: Logger,
selectMenuInteraction: StringSelectMenuInteraction,
queue: GuildQueue,
filterType: string
filterType: string,
translator: TFunction
): Promise<Message> {
this.addFfmpegNormalizerIfRequired(selectMenuInteraction);
this.toggleFfmpegFilters(selectMenuInteraction, queue, logger);
logger.debug('Responding with success embed.');
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType);
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType, translator);
}
private async handleBiquadFilterToggle(
logger: Logger,
selectMenuInteraction: StringSelectMenuInteraction,
queue: GuildQueue,
filterType: string
filterType: string,
translator: TFunction
): Promise<Message> {
this.toggleBiquadFilter(selectMenuInteraction, queue, logger);
logger.debug('Responding with success embed.');
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType);
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType, translator);
}
private async handleEqualizerFilterToggle(
logger: Logger,
selectMenuInteraction: StringSelectMenuInteraction,
queue: GuildQueue,
filterType: string
filterType: string,
translator: TFunction
): Promise<Message> {
this.toggleEqualizerFilter(selectMenuInteraction, queue, logger);
logger.debug('Responding with success embed.');
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType);
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType, translator);
}
private toggleFfmpegFilters(
@@ -172,25 +196,33 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
private sendFiltersToggledSuccessEmbed(
logger: Logger,
interaction: StringSelectMenuInteraction,
filterType: string
filterType: string,
translator: TFunction
): Promise<Message> {
logger.debug('Responding with success embed.');
return interaction.editReply({
embeds: [this.buildSuccessEmbed(interaction, filterType)],
embeds: [this.buildSuccessEmbed(interaction, filterType, translator)],
components: []
});
}
private buildSuccessEmbed(selectMenuInteraction: StringSelectMenuInteraction, filterType: string): EmbedBuilder {
private buildSuccessEmbed(
selectMenuInteraction: StringSelectMenuInteraction,
filterType: string,
translator: TFunction
): EmbedBuilder {
const availableFilters: FilterOption[] = this.getAvailableFilters(filterType);
const enabledFilters: string = this.getEnabledFilters(selectMenuInteraction, availableFilters);
return new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(selectMenuInteraction))
.setDescription(
`**${this.embedOptions.icons.success} Filters toggled**\n` +
`Now using these ${filterType} filters:\n` +
`${enabledFilters}`
translator('commands.filters.nowUsingFilters', {
icon: this.embedOptions.icons.success,
mode: filterType
}) +
'\n' +
enabledFilters
)
.setColor(this.embedOptions.colors.success);
}
@@ -243,7 +275,8 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
private async replyWithDisabledFiltersEmbed(
logger: Logger,
interaction: StringSelectMenuInteraction
interaction: StringSelectMenuInteraction,
translator: TFunction
): Promise<Message> {
logger.debug('Responding with success embed.');
return await interaction.editReply({
@@ -251,8 +284,9 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
new EmbedBuilder()
.setAuthor(this.getEmbedUserAuthor(interaction))
.setDescription(
`**${this.embedOptions.icons.success} Disabled filters**\n` +
'All audio filters have been disabled.'
translator('commands.filters.allFiltersDisabled', {
icon: this.embedOptions.icons.success
})
)
.setColor(this.embedOptions.colors.success)
],