mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
Back transcription
This commit is contained in:
3 files changed
+51
-21
No files matched your search
+5
-1
@@ -13,7 +13,11 @@
|
|||||||
"description": "The position in history to go back to."
|
"description": "The position in history to go back to."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"trackPositionHigherThanQueueLength": "{{icon}} **Oops!**\nThere are only **{{count}}** tracks in the history. You cannot go back to track **{{backPosition}}**.\n\nView tracks added in the history with {{historyCommand}}.",
|
||||||
|
"trackPositionHigherThanQueueLength_one": "{{icon}} **Oops!**\nThere is only **1** track in the history. You cannot go back to track **{{backPosition}}**.\n\nView tracks added in the history with {{historyCommand}}.",
|
||||||
|
"trackHistoryEmpty": "{{icon}} **Oops!**\nThe history is empty, add some tracks with {{playCommand}}!",
|
||||||
|
"trackRecovered": "{{icon}} **Recovered track**\n{{track}}"
|
||||||
},
|
},
|
||||||
"filters": {
|
"filters": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|||||||
Vendored
+5
-1
@@ -14,7 +14,11 @@ interface Resources {
|
|||||||
"description": "The position in history to go back to."
|
"description": "The position in history to go back to."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"trackPositionHigherThanQueueLength": "{{icon}} **Oops!**\nThere are only **{{count}}** tracks in the history. You cannot go back to track **{{backPosition}}**.\n\nView tracks added in the history with {{historyCommand}}.",
|
||||||
|
"trackPositionHigherThanQueueLength_one": "{{icon}} **Oops!**\nThere is only **1** track in the history. You cannot go back to track **{{backPosition}}**.\n\nView tracks added in the history with {{historyCommand}}.",
|
||||||
|
"trackHistoryEmpty": "{{icon}} **Oops!**\nThe history is empty, add some tracks with {{playCommand}}!",
|
||||||
|
"trackRecovered": "{{icon}} **Recovered track**\n{{track}}"
|
||||||
},
|
},
|
||||||
"filters": {
|
"filters": {
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../typ
|
|||||||
import { checkHistoryExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
import { checkHistoryExists, checkQueueCurrentTrack } from '../../../utils/validation/queueValidator';
|
||||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||||
import { Logger } from 'pino';
|
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 BackCommand extends BaseSlashCommandInteraction {
|
class BackCommand extends BaseSlashCommandInteraction {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -20,6 +22,7 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||||
const { executionId, interaction } = params;
|
const { executionId, interaction } = params;
|
||||||
const logger = this.getLogger(this.name, executionId, interaction);
|
const logger = this.getLogger(this.name, executionId, interaction);
|
||||||
|
const translator = useServerTranslator(interaction);
|
||||||
|
|
||||||
const history: GuildQueueHistory = useHistory(interaction.guild!.id)!;
|
const history: GuildQueueHistory = useHistory(interaction.guild!.id)!;
|
||||||
|
|
||||||
@@ -33,9 +36,9 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
const backToTrackInput: number = interaction.options.getInteger('position')!;
|
const backToTrackInput: number = interaction.options.getInteger('position')!;
|
||||||
|
|
||||||
if (backToTrackInput) {
|
if (backToTrackInput) {
|
||||||
return await this.handleBackToTrackPosition(logger, interaction, history, backToTrackInput);
|
return await this.handleBackToTrackPosition(logger, interaction, history, backToTrackInput, translator);
|
||||||
} else {
|
} else {
|
||||||
return await this.handleBackToPreviousTrack(logger, interaction, history);
|
return await this.handleBackToPreviousTrack(logger, interaction, history, translator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,20 +46,22 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
history: GuildQueueHistory,
|
history: GuildQueueHistory,
|
||||||
backtoTrackPosition: number
|
backtoTrackPosition: number,
|
||||||
|
translator: TFunction
|
||||||
) {
|
) {
|
||||||
if (backtoTrackPosition > history.tracks.data.length) {
|
if (backtoTrackPosition > history.tracks.data.length) {
|
||||||
return await this.handleTrackPositionHigherThanQueueLength(
|
return await this.handleTrackPositionHigherThanQueueLength(
|
||||||
backtoTrackPosition,
|
backtoTrackPosition,
|
||||||
history,
|
history,
|
||||||
logger,
|
logger,
|
||||||
interaction
|
interaction,
|
||||||
|
translator
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await history.back();
|
await history.back();
|
||||||
const recoveredTrack: Track = history.currentTrack! ?? history.tracks.data[backtoTrackPosition - 1];
|
const recoveredTrack: Track = history.currentTrack! ?? history.tracks.data[backtoTrackPosition - 1];
|
||||||
logger.debug('Went back to specified track position in history.');
|
logger.debug('Went back to specified track position in history.');
|
||||||
return await this.respondWithSuccessEmbed(recoveredTrack, interaction);
|
return await this.respondWithSuccessEmbed(recoveredTrack, interaction, translator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,16 +69,20 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
backToTrackPosition: number,
|
backToTrackPosition: number,
|
||||||
history: GuildQueueHistory,
|
history: GuildQueueHistory,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction
|
interaction: ChatInputCommandInteraction,
|
||||||
|
translator: TFunction
|
||||||
) {
|
) {
|
||||||
logger.debug('Specified track position was higher than total tracks.');
|
logger.debug('Specified track position was higher than total tracks.');
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**${this.embedOptions.icons.warning} Oops!**\n` +
|
translator('commands.back.trackPositionHigherThanQueueLength', {
|
||||||
`There are only **\`${history.tracks.data.length}\`** tracks in the history. You cannot go back to track **\`${backToTrackPosition}\`**.\n\n` +
|
icon: this.embedOptions.icons.warning,
|
||||||
'View tracks added in the history with **`/history`**.'
|
count: history.tracks.data.length,
|
||||||
|
backPosition: backToTrackPosition,
|
||||||
|
historyCommand: formatSlashCommand('history', translator)
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setColor(this.embedOptions.colors.warning)
|
.setColor(this.embedOptions.colors.warning)
|
||||||
]
|
]
|
||||||
@@ -83,40 +92,53 @@ class BackCommand extends BaseSlashCommandInteraction {
|
|||||||
private async handleBackToPreviousTrack(
|
private async handleBackToPreviousTrack(
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
history: GuildQueueHistory
|
history: GuildQueueHistory,
|
||||||
|
translator: TFunction
|
||||||
) {
|
) {
|
||||||
if (history.tracks.data.length === 0) {
|
if (history.tracks.data.length === 0) {
|
||||||
return await this.handleNoTracksInHistory(logger, interaction);
|
return await this.handleNoTracksInHistory(logger, interaction, translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
await history.back();
|
await history.back();
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
const currentTrack: Track = queue.currentTrack!;
|
const currentTrack: Track = queue.currentTrack!;
|
||||||
logger.debug('Recovered track from history.');
|
logger.debug('Recovered track from history.');
|
||||||
return await this.respondWithSuccessEmbed(currentTrack, interaction);
|
return await this.respondWithSuccessEmbed(currentTrack, interaction, translator);
|
||||||
}
|
}
|
||||||
private async handleNoTracksInHistory(logger: Logger, interaction: ChatInputCommandInteraction) {
|
private async handleNoTracksInHistory(
|
||||||
|
logger: Logger,
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
translator: TFunction
|
||||||
|
) {
|
||||||
logger.debug('No tracks in history.');
|
logger.debug('No tracks in history.');
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**${this.embedOptions.icons.warning} Oops!**\n` +
|
translator('commands.back.trackHistoryEmpty', {
|
||||||
'The history is empty, add some tracks with **`/play`**!'
|
icon: this.embedOptions.icons.warning,
|
||||||
|
playCommand: formatSlashCommand('play', translator)
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setColor(this.embedOptions.colors.warning)
|
.setColor(this.embedOptions.colors.warning)
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async respondWithSuccessEmbed(recoveredTrack: Track, interaction: ChatInputCommandInteraction) {
|
private async respondWithSuccessEmbed(
|
||||||
|
recoveredTrack: Track,
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
translator: TFunction
|
||||||
|
) {
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setAuthor(this.getEmbedUserAuthor(interaction))
|
.setAuthor(this.getEmbedUserAuthor(interaction))
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**${this.embedOptions.icons.back} Recovered track**\n` +
|
translator('commands.back.trackRecovered', {
|
||||||
`${this.getDisplayTrackDurationAndUrl(recoveredTrack)}`
|
icon: this.embedOptions.icons.back,
|
||||||
|
track: this.getDisplayTrackDurationAndUrl(recoveredTrack)
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.setThumbnail(this.getTrackThumbnailUrl(recoveredTrack))
|
.setThumbnail(this.getTrackThumbnailUrl(recoveredTrack))
|
||||||
.setColor(this.embedOptions.colors.success)
|
.setColor(this.embedOptions.colors.success)
|
||||||
|
|||||||
Reference in new issue
Block a user