mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
get guild's language different way
This commit is contained in:
parent
913bdb7814
commit
707991f416
2 changed files with 31 additions and 27 deletions
|
@ -30,13 +30,12 @@ class Queue extends BaseCommand {
|
||||||
if (!interaction.isButton()) return;
|
if (!interaction.isButton()) return;
|
||||||
|
|
||||||
if (interaction.customId.startsWith("queue_")) {
|
if (interaction.customId.startsWith("queue_")) {
|
||||||
interaction.data = [];
|
const locale = (await client.findOrCreateGuild(interaction.guildId)).language;
|
||||||
interaction.data.guild = await client.findOrCreateGuild(interaction.guildId);
|
|
||||||
|
|
||||||
const player = client.lavalink.getPlayer(interaction.guildId);
|
const player = client.lavalink.getPlayer(interaction.guildId);
|
||||||
if (!player) return interaction.error("music/play:NOT_PLAYING");
|
if (!player) return interaction.error("music/play:NOT_PLAYING");
|
||||||
|
|
||||||
const { embeds, size } = generateQueueEmbeds(interaction, player);
|
const { embeds, size } = generateQueueEmbeds(interaction, player, locale);
|
||||||
|
|
||||||
let currentPage = Number(interaction.message.content.match(/\d+/g)[0]) - 1 ?? 0;
|
let currentPage = Number(interaction.message.content.match(/\d+/g)[0]) - 1 ?? 0;
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ class Queue extends BaseCommand {
|
||||||
--currentPage;
|
--currentPage;
|
||||||
|
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${size}**`,
|
content: `${interaction.translate("common:PAGE", null, locale)}: **${currentPage + 1}**/**${size}**`,
|
||||||
embeds: [embeds[currentPage]],
|
embeds: [embeds[currentPage]],
|
||||||
components: [row],
|
components: [row],
|
||||||
});
|
});
|
||||||
|
@ -66,7 +65,7 @@ class Queue extends BaseCommand {
|
||||||
currentPage++;
|
currentPage++;
|
||||||
|
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${size}**`,
|
content: `${interaction.translate("common:PAGE", null, locale)}: **${currentPage + 1}**/**${size}**`,
|
||||||
embeds: [embeds[currentPage]],
|
embeds: [embeds[currentPage]],
|
||||||
components: [row],
|
components: [row],
|
||||||
});
|
});
|
||||||
|
@ -76,7 +75,7 @@ class Queue extends BaseCommand {
|
||||||
|
|
||||||
const selectMenu = new StringSelectMenuBuilder()
|
const selectMenu = new StringSelectMenuBuilder()
|
||||||
.setCustomId("queue_select")
|
.setCustomId("queue_select")
|
||||||
.setPlaceholder(interaction.translate("common:NOTHING_SELECTED"));
|
.setPlaceholder(interaction.translate("common:NOTHING_SELECTED", null, locale));
|
||||||
|
|
||||||
for (let i = 0; i < size; i++) {
|
for (let i = 0; i < size; i++) {
|
||||||
selectMenu.addOptions(
|
selectMenu.addOptions(
|
||||||
|
@ -99,7 +98,7 @@ class Queue extends BaseCommand {
|
||||||
await collected.deferUpdate();
|
await collected.deferUpdate();
|
||||||
|
|
||||||
return interaction.editReply({
|
return interaction.editReply({
|
||||||
content: `${interaction.translate("common:PAGE")}: **${page + 1}**/**${size}**`,
|
content: `${interaction.translate("common:PAGE", null, locale)}: **${page + 1}**/**${size}**`,
|
||||||
embeds: [embeds[page]],
|
embeds: [embeds[page]],
|
||||||
components: [row],
|
components: [row],
|
||||||
});
|
});
|
||||||
|
@ -153,27 +152,28 @@ class Queue extends BaseCommand {
|
||||||
*
|
*
|
||||||
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||||
* @param {import("lavalink-client").Player} player
|
* @param {import("lavalink-client").Player} player
|
||||||
|
* @param {string} locale
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function generateQueueEmbeds(interaction, player) {
|
function generateQueueEmbeds(interaction, player, locale) {
|
||||||
const embeds = [],
|
const embeds = [],
|
||||||
currentTrack = player.queue.current,
|
currentTrack = player.queue.current,
|
||||||
translated = {
|
translated = {
|
||||||
// "3": interaction.translate("music/loop:AUTOPLAY"),
|
// "3": interaction.translate("music/loop:AUTOPLAY"),
|
||||||
"queue": interaction.translate("music/loop:QUEUE"),
|
"queue": interaction.translate("music/loop:QUEUE", null, locale),
|
||||||
"track": interaction.translate("music/loop:TRACK"),
|
"track": interaction.translate("music/loop:TRACK", null, locale),
|
||||||
"off": interaction.translate("common:DISABLED"),
|
"off": interaction.translate("common:DISABLED", null, locale),
|
||||||
};
|
};
|
||||||
|
|
||||||
let k = 10;
|
let k = 10;
|
||||||
|
|
||||||
if (!player.queue.tracks.length) {
|
if (!player.queue.tracks.length) {
|
||||||
const embed = interaction.client.embed({
|
const embed = interaction.client.embed({
|
||||||
title: interaction.translate("music/nowplaying:CURRENTLY_PLAYING"),
|
title: interaction.translate("music/nowplaying:CURRENTLY_PLAYING", null, locale),
|
||||||
thumbnail: currentTrack.info.artworkUrl || null,
|
thumbnail: currentTrack.info.artworkUrl || null,
|
||||||
description: `${interaction.translate("music/nowplaying:REPEAT")}: \`${translated[player.repeatMode]}\`\n${
|
description: `${interaction.translate("music/nowplaying:REPEAT", null, locale)}: \`${translated[player.repeatMode]}\`\n${
|
||||||
currentTrack.info.uri.startsWith("./clips") ? `${currentTrack.info.title} (clips)` : `[${currentTrack.info.title}](${currentTrack.info.uri})`
|
currentTrack.info.uri.startsWith("./clips", null, locale) ? `${currentTrack.info.title} (clips)` : `[${currentTrack.info.title}](${currentTrack.info.uri})`
|
||||||
}\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requester.toString()}\n\n**${interaction.translate("music/queue:NEXT")}**\n${interaction.translate("music/queue:NO_QUEUE")}`,
|
}\n> ${interaction.translate("music/queue:ADDED", null, locale)} ${currentTrack.requester.toString()}\n\n**${interaction.translate("music/queue:NEXT", null, locale)}**\n${interaction.translate("music/queue:NO_QUEUE", null, locale)}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
embeds.push(embed);
|
embeds.push(embed);
|
||||||
|
@ -186,14 +186,14 @@ function generateQueueEmbeds(interaction, player) {
|
||||||
let j = i;
|
let j = i;
|
||||||
k += 10;
|
k += 10;
|
||||||
|
|
||||||
const info = current.map(track => `${++j}. ${track.info.uri.startsWith("./clips") ? `${track.info.title} (clips)` : `[${track.info.title}](${track.info.uri})`}\n> ${interaction.translate("music/queue:ADDED")} ${track.requester.toString()}`).join("\n");
|
const info = current.map(track => `${++j}. ${track.info.uri.startsWith("./clips") ? `${track.info.title} (clips)` : `[${track.info.title}](${track.info.uri})`}\n> ${interaction.translate("music/queue:ADDED", null, locale)} ${track.requester.toString()}`).join("\n");
|
||||||
|
|
||||||
const embed = interaction.client.embed({
|
const embed = interaction.client.embed({
|
||||||
title: interaction.translate("music/nowplaying:CURRENTLY_PLAYING"),
|
title: interaction.translate("music/nowplaying:CURRENTLY_PLAYING", null, locale),
|
||||||
thumbnail: currentTrack.info.artworkUrl || null,
|
thumbnail: currentTrack.info.artworkUrl || null,
|
||||||
description: `${interaction.translate("music/nowplaying:REPEAT")}: \`${translated[player.repeatMode]}\`\n${
|
description: `${interaction.translate("music/nowplaying:REPEAT", null, locale)}: \`${translated[player.repeatMode]}\`\n${
|
||||||
currentTrack.info.uri.startsWith("./clips") ? `${currentTrack.info.title} (clips)` : `[${currentTrack.info.title}](${currentTrack.info.uri})`
|
currentTrack.info.uri.startsWith("./clips") ? `${currentTrack.info.title} (clips)` : `[${currentTrack.info.title}](${currentTrack.info.uri})`
|
||||||
}\n * ${interaction.translate("music/queue:ADDED")} ${currentTrack.requester.toString()}\n\n**${interaction.translate("music/queue:NEXT")}**\n${info}`,
|
}\n * ${interaction.translate("music/queue:ADDED", null, locale)} ${currentTrack.requester.toString()}\n\n**${interaction.translate("music/queue:NEXT", null, locale)}**\n${info}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
embeds.push(embed);
|
embeds.push(embed);
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
const { Message, BaseInteraction, User } = require("discord.js");
|
const { Message, BaseInteraction, User, GuildMember } = require("discord.js");
|
||||||
|
|
||||||
User.prototype.getUsername = function () {
|
User.prototype.getUsername = function () {
|
||||||
return this.discriminator === "0" ? this.username : this.tag;
|
return this.discriminator === "0" ? this.username : this.tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseInteraction.prototype.getLocale = function () {
|
GuildMember.prototype.getUsername = function () {
|
||||||
return this.data?.guild?.language ?? "en-US";
|
return this.user.discriminator === "0" ? this.user.username : this.user.tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseInteraction.prototype.translate = function (key, args) {
|
BaseInteraction.prototype.getLocale = function () {
|
||||||
const language = this.client.translations.get(this.getLocale());
|
return this.data?.guild?.language;
|
||||||
|
};
|
||||||
|
|
||||||
|
BaseInteraction.prototype.translate = function (key, args, locale) {
|
||||||
|
const language = this.client.translations.get(this.getLocale() || locale || "en-US");
|
||||||
if (!language) throw "Interaction: Invalid language set in data.";
|
if (!language) throw "Interaction: Invalid language set in data.";
|
||||||
|
|
||||||
return language(key, args);
|
return language(key, args);
|
||||||
|
@ -36,11 +40,11 @@ BaseInteraction.prototype.error = async function (key, args, options = {}) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Message.prototype.getLocale = function () {
|
Message.prototype.getLocale = function () {
|
||||||
return this.data?.guild?.language ?? "en-US";
|
return this.data?.guild?.language;
|
||||||
};
|
};
|
||||||
|
|
||||||
Message.prototype.translate = function (key, args) {
|
Message.prototype.translate = function (key, args, locale) {
|
||||||
const language = this.client.translations.get(this.getLocale());
|
const language = this.client.translations.get(this.getLocale() || locale || "en-US");
|
||||||
if (!language) throw "Message: Invalid language set in data.";
|
if (!language) throw "Message: Invalid language set in data.";
|
||||||
|
|
||||||
return language(key, args);
|
return language(key, args);
|
||||||
|
|
Loading…
Reference in a new issue