fix localization in nowplaying button

This commit is contained in:
Jonny_Bro (Nikita) 2024-04-30 13:13:03 +05:00
parent cd0e096e64
commit 1f0bc24cef
Signed by: jonny_bro
GPG key ID: 3F1ECC04147E9BD8
3 changed files with 28 additions and 24 deletions

View file

@ -31,14 +31,13 @@ class Nowplaying extends BaseCommand {
if (!interaction.isButton()) return; if (!interaction.isButton()) return;
if (interaction.customId.startsWith("nowp_")) { if (interaction.customId.startsWith("nowp_")) {
interaction.data = []; const locale = (await client.findOrCreateGuild(interaction.guildId)).language;
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId);
const voice = interaction.member.voice.channel; const voice = interaction.member.voice.channel;
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL"); if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { locale });
const queue = client.player.nodes.get(interaction.guildId); const queue = client.player.nodes.get(interaction.guildId);
if (!queue) return interaction.error("music/play:NOT_PLAYING"); if (!queue) return interaction.error("music/play:NOT_PLAYING", null, { locale });
const row1 = new ActionRowBuilder().addComponents( const row1 = new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId("nowp_prev_track").setStyle(ButtonStyle.Primary).setEmoji("⬅️"), new ButtonBuilder().setCustomId("nowp_prev_track").setStyle(ButtonStyle.Primary).setEmoji("⬅️"),
@ -55,11 +54,11 @@ class Nowplaying extends BaseCommand {
if (interaction.customId === "nowp_prev_track") { if (interaction.customId === "nowp_prev_track") {
await interaction.deferUpdate(); await interaction.deferUpdate();
if (queue.history.isEmpty()) return interaction.followUp({ content: interaction.translate("music/back:NO_PREV_SONG", null, "error"), ephemeral: true }); if (queue.history.isEmpty()) return interaction.followUp({ content: interaction.translate("music/back:NO_PREV_SONG", null, locale), ephemeral: true });
queue.history.back(); queue.history.back();
await interaction.followUp({ content: interaction.translate("music/back:SUCCESS"), ephemeral: true }); await interaction.followUp({ content: interaction.translate("music/back:SUCCESS", null, locale), ephemeral: true });
const embed = await updateEmbed(interaction, queue); const embed = await updateEmbed(interaction, queue);
@ -71,19 +70,19 @@ class Nowplaying extends BaseCommand {
const selectMenu = new StringSelectMenuBuilder() const selectMenu = new StringSelectMenuBuilder()
.setCustomId("nowp_select") .setCustomId("nowp_select")
.setPlaceholder(interaction.translate("common:NOTHING_SELECTED")) .setPlaceholder(interaction.translate("common:NOTHING_SELECTED", null, locale))
.addOptions( .addOptions(
new StringSelectMenuOptionBuilder() new StringSelectMenuOptionBuilder()
.setLabel(interaction.translate("music/loop:AUTOPLAY")) .setLabel(interaction.translate("music/loop:AUTOPLAY", null, locale))
.setValue("3"), .setValue("3"),
new StringSelectMenuOptionBuilder() new StringSelectMenuOptionBuilder()
.setLabel(interaction.translate("music/loop:QUEUE")) .setLabel(interaction.translate("music/loop:QUEUE", null, locale))
.setValue("2"), .setValue("2"),
new StringSelectMenuOptionBuilder() new StringSelectMenuOptionBuilder()
.setLabel(interaction.translate("music/loop:TRACK")) .setLabel(interaction.translate("music/loop:TRACK", null, locale))
.setValue("1"), .setValue("1"),
new StringSelectMenuOptionBuilder() new StringSelectMenuOptionBuilder()
.setLabel(interaction.translate("music/loop:DISABLE")) .setLabel(interaction.translate("music/loop:DISABLE", null, locale))
.setValue("0"), .setValue("0"),
); );
@ -97,10 +96,10 @@ class Nowplaying extends BaseCommand {
collected = await msg.awaitMessageComponent({ filter, time: 10 * 1000 }), collected = await msg.awaitMessageComponent({ filter, time: 10 * 1000 }),
mode = collected.values[0] === "3" ? QueueRepeatMode.AUTOPLAY : collected.values[0] === "2" ? QueueRepeatMode.QUEUE : collected.values[0] === "1" ? QueueRepeatMode.TRACK : QueueRepeatMode.OFF, mode = collected.values[0] === "3" ? QueueRepeatMode.AUTOPLAY : collected.values[0] === "2" ? QueueRepeatMode.QUEUE : collected.values[0] === "1" ? QueueRepeatMode.TRACK : QueueRepeatMode.OFF,
translated = { translated = {
"3": interaction.translate("music/loop:AUTOPLAY_ENABLED"), "3": interaction.translate("music/loop:AUTOPLAY_ENABLED", null, locale),
"2": interaction.translate("music/loop:QUEUE_ENABLED"), "2": interaction.translate("music/loop:QUEUE_ENABLED", null, locale),
"1": interaction.translate("music/loop:TRACK_ENABLED"), "1": interaction.translate("music/loop:TRACK_ENABLED", null, locale),
"0": interaction.translate("music/loop:LOOP_DISABLED"), "0": interaction.translate("music/loop:LOOP_DISABLED", null, locale),
}; };
await collected.deferUpdate(); await collected.deferUpdate();
@ -118,7 +117,7 @@ class Nowplaying extends BaseCommand {
await interaction.deferUpdate(); await interaction.deferUpdate();
await interaction.followUp({ await interaction.followUp({
content: interaction.translate("music/nowplaying:LINK"), content: interaction.translate("music/nowplaying:LINK", null, locale),
ephemeral: true, ephemeral: true,
}); });
@ -135,13 +134,13 @@ class Nowplaying extends BaseCommand {
if (collected.deletable) collected.delete(); if (collected.deletable) collected.delete();
if (!searchResult.hasTracks()) return interaction.error("music/play:NO_RESULT", { query: query }, { edit: true }); if (!searchResult.hasTracks()) return interaction.error("music/play:NO_RESULT", { query: query }, { edit: true, locale });
else queue.addTrack(searchResult); else queue.addTrack(searchResult);
await interaction.followUp({ await interaction.followUp({
content: interaction.translate("music/play:ADDED_QUEUE", { content: interaction.translate("music/play:ADDED_QUEUE", {
songName: searchResult.hasPlaylist() ? searchResult.playlist.title : searchResult.tracks[0].title, songName: searchResult.hasPlaylist() ? searchResult.playlist.title : searchResult.tracks[0].title,
}), }, locale),
}); });
const embed = await updateEmbed(interaction, queue); const embed = await updateEmbed(interaction, queue);
@ -154,7 +153,12 @@ class Nowplaying extends BaseCommand {
queue.node.skip(); queue.node.skip();
await interaction.followUp({ content: interaction.translate("music/skip:SUCCESS"), ephemeral: true }); await interaction.followUp({
content: interaction.success("music/skipto:SUCCESS", {
track: `${queue.tracks.at(0).title} - ${queue.tracks.at(0).author}`,
}, { locale }),
ephemeral: true,
});
const embed = await updateEmbed(interaction, queue); const embed = await updateEmbed(interaction, queue);
@ -169,7 +173,7 @@ class Nowplaying extends BaseCommand {
await interaction.deferUpdate(); await interaction.deferUpdate();
queue.delete(); queue.delete();
await interaction.followUp({ content: interaction.translate("music/stop:SUCCESS") }); await interaction.followUp({ content: interaction.translate("music/stop:SUCCESS", null, locale) });
row1.components.forEach(component => { row1.components.forEach(component => {
component.setDisabled(true); component.setDisabled(true);

View file

@ -52,13 +52,13 @@ class Skip extends BaseCommand {
queue.node.skipTo(queue.tracks.at(position - 1)); queue.node.skipTo(queue.tracks.at(position - 1));
interaction.success("music/skip:SUCCESS", { interaction.success("music/skip:SUCCESS", {
track: queue.tracks.at(0).title, track: `${queue.tracks.at(0).title} - ${queue.tracks.at(0).author}`,
}); });
} else return interaction.error("music/skip:ERROR", { position }); } else return interaction.error("music/skip:ERROR", { position });
} else { } else {
queue.node.skip(); queue.node.skip();
interaction.success("music/skip:SUCCESS", { interaction.success("music/skip:SUCCESS", {
track: queue.tracks.at(0).title, track: `${queue.tracks.at(0).title} - ${queue.tracks.at(0).author}`,
}); });
} }
} }

View file

@ -20,7 +20,7 @@ BaseInteraction.prototype.translate = function (key, args, locale) {
}; };
BaseInteraction.prototype.replyT = async function (key, args, options = {}) { BaseInteraction.prototype.replyT = async function (key, args, options = {}) {
const translated = this.translate(key, args, this.getLocale()); const translated = this.translate(key, args, this.getLocale() || options.locale || "en-US");
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${translated}` : translated; const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${translated}` : translated;
if (options.edit) return this.editReply({ content: string, ephemeral: options.ephemeral || false }); if (options.edit) return this.editReply({ content: string, ephemeral: options.ephemeral || false });
@ -51,7 +51,7 @@ Message.prototype.translate = function (key, args, locale) {
}; };
Message.prototype.replyT = async function (key, args, options = {}) { Message.prototype.replyT = async function (key, args, options = {}) {
const translated = this.translate(key, args, this.getLocale()); const translated = this.translate(key, args, this.getLocale() || options.locale || "en-US");
const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${translated}` : translated; const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${translated}` : translated;
if (options.edit) return this.edit({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } }); if (options.edit) return this.edit({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } });