mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 06:28:54 +00:00
Choice locallization support and finalize other commands
This commit is contained in:
16 files changed
+277
-179
No files matched your search
@@ -89,6 +89,7 @@ module.exports.embedOptions = {
|
||||
nextTrack: '⏭️',
|
||||
previousTrack: '⏮️',
|
||||
pauseResumeTrack: '⏯️',
|
||||
paused: '⏸',
|
||||
shuffleQueue: '🔀',
|
||||
loop: '🔁',
|
||||
loopAction: '🔁',
|
||||
|
||||
+46
-12
@@ -26,7 +26,13 @@
|
||||
"options": {
|
||||
"type": {
|
||||
"name": "type",
|
||||
"description": "Audio filter type to use."
|
||||
"description": "Audio filter type to use.",
|
||||
"choices": {
|
||||
"ffmpeg": "FFmpeg",
|
||||
"biquad": "Biquad",
|
||||
"equalizer": "Equalizer",
|
||||
"disable": "Disable"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -93,7 +99,13 @@
|
||||
"options": {
|
||||
"mode": {
|
||||
"name": "mode",
|
||||
"description": "Loop mode: Track, queue, autoplay or disabled."
|
||||
"description": "Loop mode: Track, queue, autoplay or disabled.",
|
||||
"choices": {
|
||||
"0": "Off",
|
||||
"1": "Track",
|
||||
"2": "Queue",
|
||||
"3": "Autoplay"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -102,13 +114,7 @@
|
||||
"modeChanged": "{{icon}} **Loop mode changed**\nChanging loop mode from **`{{fromName}}`** to **`{{toName}}`**.",
|
||||
"willAutoplay": "When the queue is empty, similar tracks will start playing!",
|
||||
"willNoLongerPlay": "The {{mode}} will no longer play on repeat!",
|
||||
"willNowPlay": "The {{mode}} will now play on repeat!",
|
||||
"repeatMode": {
|
||||
"off": "disabled",
|
||||
"track": "track",
|
||||
"queue": "queue",
|
||||
"autoplay": "autoplay"
|
||||
}
|
||||
"willNowPlay": "The {{mode}} will now play on repeat!"
|
||||
},
|
||||
"lyrics": {
|
||||
"metadata": {
|
||||
@@ -148,7 +154,16 @@
|
||||
"metadata": {
|
||||
"name": "nowplaying",
|
||||
"description": "Show information about the current track."
|
||||
}
|
||||
},
|
||||
"embedFields": {
|
||||
"author": "**Artist**",
|
||||
"plays": "**Plays**",
|
||||
"source": "**Track source**"
|
||||
},
|
||||
"otherTracksInQueue_one": "1 other track in the queue...",
|
||||
"otherTracksInQueue": "{{count}} other tracks in the queue...",
|
||||
"playCount_zero": "Unknown",
|
||||
"playCount": "{{count, number}}"
|
||||
},
|
||||
"pause": {
|
||||
"metadata": {
|
||||
@@ -156,7 +171,8 @@
|
||||
"description": "Toggle pause for the current track."
|
||||
},
|
||||
"pauseConfirmation": "{{icon}} **Paused track**",
|
||||
"resumeConfirmation": "{{icon}} **Resumed track**"
|
||||
"resumeConfirmation": "{{icon}} **Resumed track**",
|
||||
"directSource": "Direct source"
|
||||
},
|
||||
"play": {
|
||||
"metadata": {
|
||||
@@ -227,7 +243,16 @@
|
||||
"options": {
|
||||
"sort": {
|
||||
"name": "sort",
|
||||
"description": "What to sort the shards by."
|
||||
"description": "What to sort the shards by.",
|
||||
"choices": {
|
||||
"none": "None (Shard ID)",
|
||||
"memory": "Memory usage",
|
||||
"connections": "Voice Connections",
|
||||
"tracks": "Tracks",
|
||||
"listeners": "Listeners",
|
||||
"guilds": "Guilds",
|
||||
"members": "Members"
|
||||
}
|
||||
},
|
||||
"page": {
|
||||
"name": "page",
|
||||
@@ -306,13 +331,22 @@
|
||||
"footerPageNumber_one": "Page {{page}} of {{pageCount}} (1 track)",
|
||||
"footerPageNumber": "Page {{page}} of {{pageCount}} ({{count}} tracks)",
|
||||
"loopingInfo": "{{icon}} **Looping**\nLoop mode is set to **`{{loopMode}}`**. You can change it with {{loopCommand}}.",
|
||||
"nowPausedTitle": "{{icon}} **Currently paused**",
|
||||
"nowPlayingTitle": "{{icon}} **Now playing**",
|
||||
"playingLive": "{{icon}} **`LIVE`** - Playing continuously from live source.",
|
||||
"queueRepeatMode": {
|
||||
"off": "Disabled",
|
||||
"track": "Track",
|
||||
"queue": "Queue",
|
||||
"autoplay": "Autoplay"
|
||||
},
|
||||
"requestedBy": "**Requested by:** {{user}}",
|
||||
"unavailableAuthor": "Unavailable",
|
||||
"unavailableDuration": "_No duration available._",
|
||||
"unavailableRequestedBy": "Unavailable",
|
||||
"unavailableTrackTitle": "Title unavailable",
|
||||
"unavailableTrackUrl": "**Unavailable**",
|
||||
"unavailableSource": "Unavailable",
|
||||
"voiceChannelInfo": "Channel: {{channel}} ({{bitrate}}kbps)"
|
||||
},
|
||||
"statistics": {
|
||||
|
||||
Vendored
+46
-12
@@ -27,7 +27,13 @@ interface Resources {
|
||||
"options": {
|
||||
"type": {
|
||||
"name": "type",
|
||||
"description": "Audio filter type to use."
|
||||
"description": "Audio filter type to use.",
|
||||
"choices": {
|
||||
"ffmpeg": "FFmpeg",
|
||||
"biquad": "Biquad",
|
||||
"equalizer": "Equalizer",
|
||||
"disable": "Disable"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -94,7 +100,13 @@ interface Resources {
|
||||
"options": {
|
||||
"mode": {
|
||||
"name": "mode",
|
||||
"description": "Loop mode: Track, queue, autoplay or disabled."
|
||||
"description": "Loop mode: Track, queue, autoplay or disabled.",
|
||||
"choices": {
|
||||
"0": "Off",
|
||||
"1": "Track",
|
||||
"2": "Queue",
|
||||
"3": "Autoplay"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -103,13 +115,7 @@ interface Resources {
|
||||
"modeChanged": "{{icon}} **Loop mode changed**\nChanging loop mode from **`{{fromName}}`** to **`{{toName}}`**.",
|
||||
"willAutoplay": "When the queue is empty, similar tracks will start playing!",
|
||||
"willNoLongerPlay": "The {{mode}} will no longer play on repeat!",
|
||||
"willNowPlay": "The {{mode}} will now play on repeat!",
|
||||
"repeatMode": {
|
||||
"off": "disabled",
|
||||
"track": "track",
|
||||
"queue": "queue",
|
||||
"autoplay": "autoplay"
|
||||
}
|
||||
"willNowPlay": "The {{mode}} will now play on repeat!"
|
||||
},
|
||||
"lyrics": {
|
||||
"metadata": {
|
||||
@@ -149,7 +155,16 @@ interface Resources {
|
||||
"metadata": {
|
||||
"name": "nowplaying",
|
||||
"description": "Show information about the current track."
|
||||
}
|
||||
},
|
||||
"embedFields": {
|
||||
"author": "**Artist**",
|
||||
"plays": "**Plays**",
|
||||
"source": "**Track source**"
|
||||
},
|
||||
"otherTracksInQueue_one": "1 other track in the queue...",
|
||||
"otherTracksInQueue": "{{count}} other tracks in the queue...",
|
||||
"playCount_zero": "Unknown",
|
||||
"playCount": "{{count, number}}"
|
||||
},
|
||||
"pause": {
|
||||
"metadata": {
|
||||
@@ -157,7 +172,8 @@ interface Resources {
|
||||
"description": "Toggle pause for the current track."
|
||||
},
|
||||
"pauseConfirmation": "{{icon}} **Paused track**",
|
||||
"resumeConfirmation": "{{icon}} **Resumed track**"
|
||||
"resumeConfirmation": "{{icon}} **Resumed track**",
|
||||
"directSource": "Direct source"
|
||||
},
|
||||
"play": {
|
||||
"metadata": {
|
||||
@@ -228,7 +244,16 @@ interface Resources {
|
||||
"options": {
|
||||
"sort": {
|
||||
"name": "sort",
|
||||
"description": "What to sort the shards by."
|
||||
"description": "What to sort the shards by.",
|
||||
"choices": {
|
||||
"none": "None (Shard ID)",
|
||||
"memory": "Memory usage",
|
||||
"connections": "Voice Connections",
|
||||
"tracks": "Tracks",
|
||||
"listeners": "Listeners",
|
||||
"guilds": "Guilds",
|
||||
"members": "Members"
|
||||
}
|
||||
},
|
||||
"page": {
|
||||
"name": "page",
|
||||
@@ -307,13 +332,22 @@ interface Resources {
|
||||
"footerPageNumber_one": "Page {{page}} of {{pageCount}} (1 track)",
|
||||
"footerPageNumber": "Page {{page}} of {{pageCount}} ({{count}} tracks)",
|
||||
"loopingInfo": "{{icon}} **Looping**\nLoop mode is set to **`{{loopMode}}`**. You can change it with {{loopCommand}}.",
|
||||
"nowPausedTitle": "{{icon}} **Currently paused**",
|
||||
"nowPlayingTitle": "{{icon}} **Now playing**",
|
||||
"playingLive": "{{icon}} **`LIVE`** - Playing continuously from live source.",
|
||||
"queueRepeatMode": {
|
||||
"off": "Disabled",
|
||||
"track": "Track",
|
||||
"queue": "Queue",
|
||||
"autoplay": "Autoplay"
|
||||
},
|
||||
"requestedBy": "**Requested by:** {{user}}",
|
||||
"unavailableAuthor": "Unavailable",
|
||||
"unavailableDuration": "_No duration available._",
|
||||
"unavailableRequestedBy": "Unavailable",
|
||||
"unavailableTrackTitle": "Title unavailable",
|
||||
"unavailableTrackUrl": "**Unavailable**",
|
||||
"unavailableSource": "Unavailable",
|
||||
"voiceChannelInfo": "Channel: {{channel}} ({{bitrate}}kbps)"
|
||||
},
|
||||
"statistics": {
|
||||
|
||||
@@ -27,7 +27,6 @@ import {
|
||||
} from '../types/interactionTypes';
|
||||
import { Validator, ValidatorParams } from '../types/utilTypes';
|
||||
import { TFunction } from 'i18next';
|
||||
import { formatSlashCommand } from '../common/formattingUtils';
|
||||
|
||||
abstract class BaseInteraction {
|
||||
embedOptions: EmbedOptions;
|
||||
@@ -162,34 +161,6 @@ abstract class BaseInteraction {
|
||||
return progressBar;
|
||||
}
|
||||
|
||||
protected getDisplayRepeatMode(repeatMode: number, translator: TFunction, state: string = 'info'): string {
|
||||
let loopModeUserString: string;
|
||||
let icon: string;
|
||||
|
||||
switch (repeatMode) {
|
||||
case 1:
|
||||
loopModeUserString = 'track';
|
||||
icon = state === 'info' ? this.embedOptions.icons.loop : this.embedOptions.icons.looping;
|
||||
break;
|
||||
case 2:
|
||||
loopModeUserString = 'queue';
|
||||
icon = state === 'info' ? this.embedOptions.icons.loop : this.embedOptions.icons.looping;
|
||||
break;
|
||||
case 3:
|
||||
loopModeUserString = 'autoplay';
|
||||
icon = state === 'info' ? this.embedOptions.icons.autoplay : this.embedOptions.icons.autoplaying;
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
return translator('musicPlayerCommon.loopingInfo', {
|
||||
icon,
|
||||
loopMode: loopModeUserString,
|
||||
loopCommand: formatSlashCommand('loop', translator)
|
||||
});
|
||||
}
|
||||
|
||||
abstract execute(
|
||||
params: BaseInteractionParams
|
||||
): Promise<Message<boolean> | ApplicationCommandOptionChoiceData | void>;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { QueueRepeatMode } from 'discord-player';
|
||||
import { TFunction } from 'i18next';
|
||||
import { EmbedOptions } from '../types/configTypes';
|
||||
|
||||
export function formatDuration(durationMs: number): string {
|
||||
const durationDate: Date = new Date(0);
|
||||
@@ -26,3 +28,45 @@ export function formatSlashCommand(commandName: string, translator: TFunction):
|
||||
});
|
||||
return `**\`/${translatedName}\`**`;
|
||||
}
|
||||
|
||||
export function formatRepeatMode(repeatMode: QueueRepeatMode, translator: TFunction): string {
|
||||
switch (repeatMode) {
|
||||
case QueueRepeatMode.AUTOPLAY:
|
||||
return translator('musicPlayerCommon.queueRepeatMode.autoplay');
|
||||
case QueueRepeatMode.OFF:
|
||||
return translator('musicPlayerCommon.queueRepeatMode.off');
|
||||
case QueueRepeatMode.TRACK:
|
||||
return translator('musicPlayerCommon.queueRepeatMode.track');
|
||||
case QueueRepeatMode.QUEUE:
|
||||
return translator('musicPlayerCommon.queueRepeatMode.queue');
|
||||
}
|
||||
}
|
||||
|
||||
export function formatRepeatModeDetailed(
|
||||
repeatMode: QueueRepeatMode,
|
||||
embedOptions: EmbedOptions,
|
||||
translator: TFunction,
|
||||
state: string = 'info'
|
||||
) {
|
||||
let icon: string;
|
||||
|
||||
switch (repeatMode) {
|
||||
case QueueRepeatMode.TRACK:
|
||||
icon = state === 'info' ? embedOptions.icons.loop : embedOptions.icons.looping;
|
||||
break;
|
||||
case QueueRepeatMode.QUEUE:
|
||||
icon = state === 'info' ? embedOptions.icons.loop : embedOptions.icons.looping;
|
||||
break;
|
||||
case QueueRepeatMode.AUTOPLAY:
|
||||
icon = state === 'info' ? embedOptions.icons.autoplay : embedOptions.icons.autoplaying;
|
||||
break;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
return translator('musicPlayerCommon.loopingInfo', {
|
||||
icon,
|
||||
loopMode: formatRepeatMode(repeatMode, translator),
|
||||
loopCommand: formatSlashCommand('loop', translator)
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
import assert from 'assert';
|
||||
import { APIApplicationCommandOption, BaseInteraction, Locale, SlashCommandBuilder } from 'discord.js';
|
||||
import {
|
||||
APIApplicationCommandOption,
|
||||
ApplicationCommandOptionType,
|
||||
BaseInteraction,
|
||||
Locale,
|
||||
SlashCommandBuilder
|
||||
} from 'discord.js';
|
||||
import { lstatSync, readdirSync } from 'fs';
|
||||
import i18n from 'i18next';
|
||||
import i18nextFsBackend, { FsBackendOptions } from 'i18next-fs-backend';
|
||||
@@ -20,6 +26,9 @@ translatorInstance.use(i18nextFsBackend).init<FsBackendOptions>({
|
||||
backend: {
|
||||
loadPath: join(localeDir, '{{lng}}', '{{ns}}.json'),
|
||||
addPath: join(localeDir, '{{lng}}', '{{ns}}.missing.json')
|
||||
},
|
||||
interpolation: {
|
||||
escapeValue: false
|
||||
}
|
||||
});
|
||||
|
||||
@@ -41,6 +50,7 @@ type CommandMetadata = {
|
||||
{
|
||||
name?: string;
|
||||
description?: string;
|
||||
choices?: Record<string, string>;
|
||||
}
|
||||
>;
|
||||
};
|
||||
@@ -85,6 +95,29 @@ export function localizeCommand(command: Omit<SlashCommandBuilder, 'addSubcomman
|
||||
|
||||
option.name_localizations = {};
|
||||
option.description_localizations = {};
|
||||
if (
|
||||
(option.type === ApplicationCommandOptionType.String ||
|
||||
option.type === ApplicationCommandOptionType.Integer) &&
|
||||
option.choices
|
||||
) {
|
||||
assert(
|
||||
englishOptionData.choices,
|
||||
`Option ${option.name} in /${command.name} must have choice localizations.`
|
||||
);
|
||||
for (const choice of option.choices) {
|
||||
choice.name_localizations = {};
|
||||
assert(
|
||||
choice.value !== undefined && choice.value !== null,
|
||||
`Choice in option ${option.name} in /${command.name} must have a value.`
|
||||
);
|
||||
const stringifiedValue = choice.value.toString();
|
||||
assert(
|
||||
englishOptionData.choices[stringifiedValue],
|
||||
`Choice ${choice.value} of option ${option.name} in /${command.name} must have an English localization.`
|
||||
);
|
||||
choice.name = englishOptionData.choices[stringifiedValue];
|
||||
}
|
||||
}
|
||||
for (const locale of DISCORD_LOCALES) {
|
||||
const localeOptionData = (
|
||||
translatorInstance.getResource(locale, 'bot', metadataKey) as CommandMetadata | undefined
|
||||
@@ -98,6 +131,15 @@ export function localizeCommand(command: Omit<SlashCommandBuilder, 'addSubcomman
|
||||
if (localeOptionData.description) {
|
||||
option.description_localizations[locale] = localeOptionData.description;
|
||||
}
|
||||
if (localeOptionData.choices && option.type === ApplicationCommandOptionType.String && option.choices) {
|
||||
for (const choice of option.choices) {
|
||||
const localizedChoice = localeOptionData.choices[choice.value];
|
||||
if (!localizedChoice) {
|
||||
continue;
|
||||
}
|
||||
choice.name_localizations![locale] = localizedChoice;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ const equalizerFilterOptions: EqualizerFilterOptions = config.get('equalizerFilt
|
||||
|
||||
class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
// TODO: Localize choices
|
||||
// TODO: Implement system for localized filter names and descriptions
|
||||
const data = localizeCommand(
|
||||
new SlashCommandBuilder()
|
||||
@@ -45,10 +44,10 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
.setName('type')
|
||||
.setRequired(false)
|
||||
.addChoices(
|
||||
{ name: 'FFmpeg', value: 'ffmpeg' },
|
||||
{ name: 'Biquad', value: 'biquad' },
|
||||
{ name: 'Equalizer', value: 'equalizer' },
|
||||
{ name: 'Disable', value: 'disable' }
|
||||
{ value: 'ffmpeg', name: ' ' },
|
||||
{ value: 'biquad', name: ' ' },
|
||||
{ value: 'equalizer', name: ' ' },
|
||||
{ value: 'disable', name: ' ' }
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ import { checkHistoryExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
import { TFunction } from 'i18next';
|
||||
import { formatSlashCommand } from '../../../common/formattingUtils';
|
||||
import { formatRepeatModeDetailed, formatSlashCommand } from '../../../common/formattingUtils';
|
||||
|
||||
class HistoryCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -130,24 +130,18 @@ class HistoryCommand extends BaseSlashCommandInteraction {
|
||||
new EmbedBuilder()
|
||||
.setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator))
|
||||
.setDescription(
|
||||
translator('musicPlayerCommon.nowPlayingTitle', {
|
||||
`${translator('musicPlayerCommon.nowPlayingTitle', {
|
||||
icon: this.embedOptions.icons.audioPlaying
|
||||
}) +
|
||||
'\n' +
|
||||
this.getFormattedTrackUrl(currentTrack, translator) +
|
||||
'\n' +
|
||||
translator('musicPlayerCommon.requestedBy', {
|
||||
})}\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', {
|
||||
})}\n` +
|
||||
`${this.getDisplayQueueProgressBar(queue, translator)}\n\n` +
|
||||
`${formatRepeatModeDetailed(queue.repeatMode, this.embedOptions, translator)}\n` +
|
||||
`${translator('commands.history.tracksInHistoryTitle', {
|
||||
icon: this.embedOptions.icons.queue
|
||||
}) +
|
||||
'\n' +
|
||||
})}\n` +
|
||||
historyTracksListString
|
||||
)
|
||||
.setThumbnail(this.getTrackThumbnailUrl(currentTrack))
|
||||
|
||||
@@ -13,10 +13,10 @@ import { checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
import { TFunction } from 'i18next';
|
||||
import { formatRepeatMode } from '../../../common/formattingUtils';
|
||||
|
||||
class LoopCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
// TODO: Add choice localization support
|
||||
const data = localizeCommand(
|
||||
new SlashCommandBuilder()
|
||||
.setName('loop')
|
||||
@@ -25,10 +25,10 @@ class LoopCommand extends BaseSlashCommandInteraction {
|
||||
.setName('mode')
|
||||
.setRequired(false)
|
||||
.addChoices(
|
||||
{ name: 'Track', value: QueueRepeatMode.TRACK },
|
||||
{ name: 'Queue', value: QueueRepeatMode.QUEUE },
|
||||
{ name: 'Autoplay', value: QueueRepeatMode.AUTOPLAY },
|
||||
{ name: 'Disabled', value: QueueRepeatMode.OFF }
|
||||
{ value: QueueRepeatMode.TRACK, name: ' ' },
|
||||
{ value: QueueRepeatMode.QUEUE, name: ' ' },
|
||||
{ value: QueueRepeatMode.AUTOPLAY, name: ' ' },
|
||||
{ value: QueueRepeatMode.OFF, name: ' ' }
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -79,7 +79,7 @@ class LoopCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
const repeatModeEmbedIcon =
|
||||
currentRepeatMode === 3 ? this.embedOptions.icons.autoplay : this.embedOptions.icons.loop;
|
||||
const repeatModeEmbedName = this.getRepeatModeEmbedName(currentRepeatMode, translator);
|
||||
const repeatModeEmbedName = formatRepeatMode(currentRepeatMode, translator);
|
||||
|
||||
logger.debug('Responding with info embed.');
|
||||
return await interaction.editReply({
|
||||
@@ -102,7 +102,7 @@ class LoopCommand extends BaseSlashCommandInteraction {
|
||||
currentRepeatMode: QueueRepeatMode,
|
||||
translator: TFunction
|
||||
): Promise<Message> {
|
||||
const repeatModeEmbedName = this.getRepeatModeEmbedName(currentRepeatMode, translator);
|
||||
const repeatModeEmbedName = formatRepeatMode(currentRepeatMode, translator);
|
||||
logger.debug(`Loop mode is already set to '${repeatModeEmbedName}'.`);
|
||||
logger.debug('Responding with warning embed.');
|
||||
return await interaction.editReply({
|
||||
@@ -127,7 +127,7 @@ class LoopCommand extends BaseSlashCommandInteraction {
|
||||
toRepeatMode: QueueRepeatMode,
|
||||
translator: TFunction
|
||||
): Promise<Message> {
|
||||
const newRepeatModeEmbedName = this.getRepeatModeEmbedName(toRepeatMode, translator);
|
||||
const newRepeatModeEmbedName = formatRepeatMode(toRepeatMode, translator);
|
||||
const getChangedRepeatModeEmbedReply = this.getChangedRepeatModeEmbedReply(
|
||||
fromRepeatMode,
|
||||
toRepeatMode,
|
||||
@@ -148,24 +148,13 @@ class LoopCommand extends BaseSlashCommandInteraction {
|
||||
});
|
||||
}
|
||||
|
||||
private getRepeatModeEmbedName(repeatMode: QueueRepeatMode, translator: TFunction): string {
|
||||
const repeatModeEmbedString: { [key in QueueRepeatMode]: string } = {
|
||||
[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,
|
||||
translator: TFunction
|
||||
): string {
|
||||
const fromRepeatModeEmbedName = this.getRepeatModeEmbedName(fromRepeatMode, translator);
|
||||
const toRepeatModeEmbedName = this.getRepeatModeEmbedName(toRepeatMode, translator);
|
||||
const fromRepeatModeEmbedName = formatRepeatMode(fromRepeatMode, translator);
|
||||
const toRepeatModeEmbedName = formatRepeatMode(toRepeatMode, translator);
|
||||
|
||||
let repeatModeIcon = this.embedOptions.icons.looping;
|
||||
let newRepeatModeMessage: string = translator('commands.loop.willNowPlay', {
|
||||
|
||||
@@ -15,6 +15,8 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType, TrackMetadata } fro
|
||||
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
import { TFunction } from 'i18next';
|
||||
import { formatRepeatModeDetailed } from '../../../common/formattingUtils';
|
||||
|
||||
class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
@@ -40,8 +42,12 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
const currentTrack: Track = queue.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 displayTrackPlayingStatus: string = this.getDisplayTrackPlayingStatus(queue, translator);
|
||||
const displayQueueRepeatMode: string = formatRepeatModeDetailed(
|
||||
queue.repeatMode,
|
||||
this.embedOptions,
|
||||
translator
|
||||
);
|
||||
const displayEmbedProgressBar: string = this.getDisplayQueueProgressBar(queue, translator);
|
||||
|
||||
const components: APIMessageActionRowComponent[] = [];
|
||||
@@ -69,9 +75,11 @@ class NowPlayingCommand 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> = {
|
||||
@@ -87,13 +95,17 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
.setDescription(
|
||||
`${displayTrackPlayingStatus}\n` +
|
||||
`${displayTrackUrl}\n` +
|
||||
`**Requested by:** ${displayTrackRequestedBy}\n` +
|
||||
`${translator('musicPlayerCommon.requestedBy', {
|
||||
user: displayTrackRequestedBy
|
||||
})}\n` +
|
||||
`${displayEmbedProgressBar}\n\n ` +
|
||||
`${displayQueueRepeatMode}\n\n`
|
||||
)
|
||||
.addFields(this.getEmbedFields(currentTrack))
|
||||
.addFields(this.getEmbedFields(currentTrack, translator))
|
||||
.setFooter({
|
||||
text: tracksInQueueCount ? `${tracksInQueueCount} other tracks in the queue...` : ' '
|
||||
text: tracksInQueueCount
|
||||
? translator('commands.nowplaying.otherTracksInQueue', { count: tracksInQueueCount })
|
||||
: ' '
|
||||
})
|
||||
.setThumbnail(this.getTrackThumbnailUrl(queue.currentTrack!))
|
||||
.setColor(this.embedOptions.colors.info)
|
||||
@@ -102,37 +114,34 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
});
|
||||
}
|
||||
|
||||
private getDisplayPlays(currentTrack: Track | undefined): string {
|
||||
private getDisplayPlays(currentTrack: Track | undefined, translator: TFunction): string {
|
||||
const trackMetadata = currentTrack?.metadata as TrackMetadata;
|
||||
|
||||
let displayPlays: string =
|
||||
(currentTrack?.views || trackMetadata?.bridge?.views || 0).toLocaleString('en-US') ?? '0';
|
||||
|
||||
if (displayPlays === '0') {
|
||||
displayPlays = 'Unavailable';
|
||||
}
|
||||
|
||||
return displayPlays;
|
||||
return translator('commands.nowplaying.playCount', {
|
||||
count: currentTrack?.views || trackMetadata?.bridge?.views || 0
|
||||
});
|
||||
}
|
||||
|
||||
private getDisplayTrackAuthor(currentTrack: Track | undefined): string {
|
||||
let author: string = currentTrack?.author ? currentTrack.author : 'Unavailable';
|
||||
if (author === 'cdn.discordapp.com') {
|
||||
author = 'Unavailable';
|
||||
private getDisplayTrackAuthor(currentTrack: Track | undefined, translator: TFunction): string {
|
||||
let author = currentTrack?.author;
|
||||
if (!author || author === 'cdn.discordapp.com') {
|
||||
author = translator('musicPlayerCommon.unavailableAuthor');
|
||||
}
|
||||
return author;
|
||||
}
|
||||
|
||||
private getTrackSourceString(currentTrack: Track): string {
|
||||
private getTrackSourceString(currentTrack: Track, translator: TFunction): string {
|
||||
const sourceStringsFormatted: Map<string, string> = new Map([
|
||||
['youtube', 'YouTube'],
|
||||
['soundcloud', 'SoundCloud'],
|
||||
['spotify', 'Spotify'],
|
||||
['apple_music', 'Apple Music'],
|
||||
['arbitrary', 'Direct source']
|
||||
['arbitrary', translator('commands.pause.directSource')]
|
||||
]);
|
||||
|
||||
return sourceStringsFormatted.get(currentTrack.raw.source!) ?? 'Unavailable';
|
||||
return (
|
||||
sourceStringsFormatted.get(currentTrack.raw.source!) ?? translator('musicPlayerCommon.unavailableSource')
|
||||
);
|
||||
}
|
||||
|
||||
private getTrackSourceIcon(currentTrack: Track): string {
|
||||
@@ -147,59 +156,38 @@ class NowPlayingCommand extends BaseSlashCommandInteraction {
|
||||
return sourceIcons.get(currentTrack.raw.source!) ?? '';
|
||||
}
|
||||
|
||||
private getDisplayTrackSource(currentTrack: Track) {
|
||||
const trackSource: string = this.getTrackSourceString(currentTrack) ?? 'Unavailable';
|
||||
private getDisplayTrackSource(currentTrack: Track, translator: TFunction) {
|
||||
const trackSource: string = this.getTrackSourceString(currentTrack, translator);
|
||||
const trackSourceIcon: string = this.getTrackSourceIcon(currentTrack) ?? '';
|
||||
|
||||
return `**${trackSourceIcon} [${trackSource}](${currentTrack.raw.url ?? currentTrack.url})**`;
|
||||
}
|
||||
|
||||
private getRepeatModeString(repeatMode: number): string {
|
||||
const loopModesFormatted: Map<number, string> = new Map([
|
||||
[0, 'disabled'],
|
||||
[1, 'track'],
|
||||
[2, 'queue'],
|
||||
[3, 'autoplay']
|
||||
]);
|
||||
|
||||
return loopModesFormatted.get(repeatMode)!;
|
||||
}
|
||||
|
||||
private getDisplayQueueRepeatMode = (queue: GuildQueue): string => {
|
||||
const repeatMode: number = queue.repeatMode;
|
||||
if (repeatMode === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const loopModeUserString: string = this.getRepeatModeString(repeatMode);
|
||||
const icon = repeatMode === 3 ? this.embedOptions.icons.autoplay : this.embedOptions.icons.loop;
|
||||
return (
|
||||
`**${icon} Looping**\n` +
|
||||
`Loop mode is set to **\`${loopModeUserString}\`**. You can change it with **\`/loop\`**.`
|
||||
);
|
||||
};
|
||||
|
||||
private getDisplayTrackPlayingStatus = (queue: GuildQueue): string => {
|
||||
private getDisplayTrackPlayingStatus = (queue: GuildQueue, translator: TFunction): string => {
|
||||
return queue.node.isPaused()
|
||||
? '**Currently Paused**'
|
||||
: `**${this.embedOptions.icons.audioPlaying} Now Playing**`;
|
||||
? translator('musicPlayerCommon.nowPausedTitle', {
|
||||
icon: this.embedOptions.icons.paused
|
||||
})
|
||||
: translator('musicPlayerCommon.nowPlayingTitle', {
|
||||
icon: this.embedOptions.icons.audioPlaying
|
||||
});
|
||||
};
|
||||
|
||||
private getEmbedFields = (currentTrack: Track): EmbedField[] => {
|
||||
private getEmbedFields = (currentTrack: Track, translator: TFunction): EmbedField[] => {
|
||||
const fields: EmbedField[] = [
|
||||
{
|
||||
name: '**Author**',
|
||||
value: this.getDisplayTrackAuthor(currentTrack),
|
||||
name: translator('commands.nowplaying.embedFields.author'),
|
||||
value: this.getDisplayTrackAuthor(currentTrack, translator),
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: '**Plays**',
|
||||
value: this.getDisplayPlays(currentTrack),
|
||||
name: translator('commands.nowplaying.embedFields.plays'),
|
||||
value: this.getDisplayPlays(currentTrack, translator),
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: '**Track source**',
|
||||
value: this.getDisplayTrackSource(currentTrack),
|
||||
name: translator('commands.nowplaying.embedFields.source'),
|
||||
value: this.getDisplayTrackSource(currentTrack, translator),
|
||||
inline: true
|
||||
}
|
||||
];
|
||||
|
||||
@@ -16,7 +16,7 @@ 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 { formatDuration } from '../../../common/formattingUtils';
|
||||
import { formatDuration, formatRepeatModeDetailed } from '../../../common/formattingUtils';
|
||||
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
import { TFunction } from 'i18next';
|
||||
|
||||
@@ -123,20 +123,18 @@ class QueueCommand extends BaseSlashCommandInteraction {
|
||||
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.queue.tracksInQueueTitle', {
|
||||
`${this.getDisplayQueueProgressBar(queue, translator)}\n\n` +
|
||||
`${formatRepeatModeDetailed(queue.repeatMode, this.embedOptions, translator)}\n` +
|
||||
`${translator('commands.queue.tracksInQueueTitle', {
|
||||
icon: this.embedOptions.icons.queue
|
||||
}) +
|
||||
'\n' +
|
||||
})}\n` +
|
||||
queueTracksListString
|
||||
)
|
||||
.setThumbnail(this.getTrackThumbnailUrl(currentTrack))
|
||||
@@ -163,8 +161,10 @@ class QueueCommand extends BaseSlashCommandInteraction {
|
||||
new EmbedBuilder()
|
||||
.setAuthor(this.getEmbedQueueAuthor(interaction, queue, translator))
|
||||
.setDescription(
|
||||
`${this.getDisplayRepeatMode(queue.repeatMode, translator)}` +
|
||||
`**${this.embedOptions.icons.queue} Tracks in queue**\n` +
|
||||
`${formatRepeatModeDetailed(queue.repeatMode, this.embedOptions, translator)}` +
|
||||
`${translator('commands.queue.tracksInQueueTitle', {
|
||||
icon: this.embedOptions.icons.queue
|
||||
})}\n` +
|
||||
queueTracksListString
|
||||
)
|
||||
.setFooter(this.getDisplayFullFooterInfo(interaction, queue, translator))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GuildQueue, useQueue } from 'discord-player';
|
||||
import { GuildQueue, QueueRepeatMode, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
@@ -27,7 +27,7 @@ class StopCommand extends BaseSlashCommandInteraction {
|
||||
]);
|
||||
|
||||
if (!queue.deleted) {
|
||||
queue.setRepeatMode(0);
|
||||
queue.setRepeatMode(QueueRepeatMode.OFF);
|
||||
queue.clear();
|
||||
queue.node.stop();
|
||||
logger.debug('Cleared and stopped the queue.');
|
||||
|
||||
@@ -14,7 +14,6 @@ import { localizeCommand } from '../../../common/localeUtil';
|
||||
|
||||
class ShardsCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
// TODO: Localize choices
|
||||
const data = localizeCommand(
|
||||
new SlashCommandBuilder()
|
||||
.setName('shards')
|
||||
@@ -23,13 +22,13 @@ class ShardsCommand extends BaseSlashCommandInteraction {
|
||||
.setName('sort')
|
||||
.setRequired(false)
|
||||
.addChoices(
|
||||
{ name: 'None (Shard ID)', value: 'none' },
|
||||
{ name: 'Memory usage', value: 'memory' },
|
||||
{ name: 'Voice Connections', value: 'connections' },
|
||||
{ name: 'Tracks', value: 'tracks' },
|
||||
{ name: 'Listeners', value: 'listeners' },
|
||||
{ name: 'Guilds', value: 'guilds' },
|
||||
{ name: 'Members', value: 'members' }
|
||||
{ value: 'none', name: ' ' },
|
||||
{ value: 'memory', name: ' ' },
|
||||
{ value: 'connections', name: ' ' },
|
||||
{ value: 'tracks', name: ' ' },
|
||||
{ value: 'listeners', name: ' ' },
|
||||
{ value: 'guilds', name: ' ' },
|
||||
{ value: 'members', name: ' ' }
|
||||
)
|
||||
)
|
||||
.addIntegerOption((option) => option.setName('page').setMinValue(1))
|
||||
|
||||
@@ -6,6 +6,7 @@ import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation
|
||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
import { TFunction } from 'i18next';
|
||||
import { useServerTranslator } from '../../common/localeUtil';
|
||||
import { formatRepeatModeDetailed } from '../../common/formattingUtils';
|
||||
|
||||
class ActionPauseResumeButton extends BaseComponentInteraction {
|
||||
constructor() {
|
||||
@@ -85,7 +86,7 @@ class ActionPauseResumeButton extends BaseComponentInteraction {
|
||||
`**${this.embedOptions.icons.pauseResumed} ${
|
||||
queue.node.isPaused() ? 'Paused Track' : 'Resumed track'
|
||||
}**\n ${this.getDisplayTrackDurationAndUrl(queue.currentTrack!, translator)}\n\n` +
|
||||
`${this.getDisplayRepeatMode(queue.repeatMode, translator, 'success')}`
|
||||
`${formatRepeatModeDetailed(queue.repeatMode, this.embedOptions, translator, 'success')}`
|
||||
)
|
||||
.setThumbnail(track.thumbnail)
|
||||
.setColor(this.embedOptions.colors.success);
|
||||
|
||||
@@ -6,6 +6,7 @@ import { checkQueueCurrentTrack, checkQueueExists } from '../../utils/validation
|
||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||
import { TFunction } from 'i18next';
|
||||
import { useServerTranslator } from '../../common/localeUtil';
|
||||
import { formatRepeatModeDetailed } from '../../common/formattingUtils';
|
||||
|
||||
class ActionSkipButton extends BaseComponentInteraction {
|
||||
constructor() {
|
||||
@@ -79,7 +80,7 @@ class ActionSkipButton extends BaseComponentInteraction {
|
||||
.setDescription(
|
||||
`**${this.embedOptions.icons.skipped} Skipped track**\n` +
|
||||
`${this.getDisplayTrackDurationAndUrl(skippedTrack, translator)}\n\n` +
|
||||
`${this.getDisplayRepeatMode(queue.repeatMode, translator, 'success')}`
|
||||
`${formatRepeatModeDetailed(queue.repeatMode, this.embedOptions, translator, 'success')}`
|
||||
)
|
||||
.setThumbnail(skippedTrack.thumbnail)
|
||||
.setColor(this.embedOptions.colors.success);
|
||||
|
||||
Vendored
+1
@@ -63,6 +63,7 @@ export type EmbedOptions = {
|
||||
nextTrack: string;
|
||||
previousTrack: string;
|
||||
pauseResumeTrack: string;
|
||||
paused: string;
|
||||
shuffleQueue: string;
|
||||
loop: string;
|
||||
loopAction: string;
|
||||
|
||||
Reference in new issue
Block a user