diff --git a/commands/Economy/birthdate.js b/commands/Economy/birthdate.js index 56c61780..d128ac16 100644 --- a/commands/Economy/birthdate.js +++ b/commands/Economy/birthdate.js @@ -94,7 +94,7 @@ class Birthdate extends BaseCommand { await data.userData.save(); interaction.success("economy/birthdate:SUCCESS", { - date: client.functions.printDate(client, d, "Do MMMM YYYY", data.guildData.language), + date: client.functions.printDate(client, d, "Do MMMM YYYY", interaction.getLocale()), }); } } diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index 7011d8b2..9e6156ad 100644 --- a/commands/Economy/profile.js +++ b/commands/Economy/profile.js @@ -114,12 +114,12 @@ class Profile extends BaseCommand { }, { name: interaction.translate("economy/profile:REGISTERED"), - value: client.functions.printDate(client, new Date(memberData.registeredAt), null, data.guildData.language), + value: client.functions.printDate(client, new Date(memberData.registeredAt), null, interaction.getLocale()), inline: true, }, { name: interaction.translate("economy/profile:BIRTHDATE"), - value: !userData.birthdate ? interaction.translate("common:NOT_DEFINED") : client.functions.printDate(client, new Date(userData.birthdate), "Do MMMM YYYY", data.guildData.language), + value: !userData.birthdate ? interaction.translate("common:NOT_DEFINED") : client.functions.printDate(client, new Date(userData.birthdate), "Do MMMM YYYY", interaction.getLocale()), inline: true, }, { diff --git a/commands/Economy/rep.js b/commands/Economy/rep.js index 7007396f..f62f6d3c 100644 --- a/commands/Economy/rep.js +++ b/commands/Economy/rep.js @@ -49,7 +49,7 @@ class Rep extends BaseCommand { if (isInCooldown) { if (isInCooldown > Date.now()) return interaction.error("economy/rep:COOLDOWN", { - time: client.functions.convertTime(client, isInCooldown, true, false, data.guildData.language), + time: client.functions.convertTime(client, isInCooldown, true, false, interaction.getLocale()), }); } diff --git a/commands/Economy/transactions.js b/commands/Economy/transactions.js index 1e2b76b6..a0668e0f 100644 --- a/commands/Economy/transactions.js +++ b/commands/Economy/transactions.js @@ -69,7 +69,7 @@ class Transactions extends BaseCommand { array.push( `${interaction.translate("economy/transactions:T_USER_" + t.type.toUpperCase())}: ${t.user}\n${interaction.translate("economy/transactions:T_AMOUNT")}: ${t.amount}\n${interaction.translate( "economy/transactions:T_DATE", - )}: ${client.functions.printDate(client, t.date, "Do MMMM YYYY, HH:mm", data.guildData.language)}\n`, + )}: ${client.functions.printDate(client, t.date, "Do MMMM YYYY, HH:mm", interaction.getLocale())}\n`, ); }); diff --git a/commands/Economy/work.js b/commands/Economy/work.js index 78b9646f..86350bd2 100644 --- a/commands/Economy/work.js +++ b/commands/Economy/work.js @@ -39,7 +39,7 @@ class Work extends BaseCommand { if (isInCooldown) { if (isInCooldown > Date.now()) return interaction.error("economy/work:COOLDOWN", { - time: client.functions.convertTime(client, isInCooldown, true, false, data.guildData.language), + time: client.functions.convertTime(client, isInCooldown, true, false, interaction.getLocale()), }); } if (Date.now() > data.memberData.cooldowns.work + 24 * 60 * 60 * 1000) data.memberData.workStreak = 0; diff --git a/commands/Fun/number.js b/commands/Fun/number.js index c4a459b9..d0e51139 100644 --- a/commands/Fun/number.js +++ b/commands/Fun/number.js @@ -60,7 +60,7 @@ class Number extends BaseCommand { const parsedNumber = parseInt(msg.content, 10); if (parsedNumber === number) { - const time = client.functions.convertTime(client, gameCreatedAt, false, true, data.guildData.language); + const time = client.functions.convertTime(client, gameCreatedAt, false, true, interaction.getLocale()); interaction.channel.send({ content: interaction.translate("fun/number:GAME_STATS", { winner: msg.author.toString(), diff --git a/commands/General/boosters.js b/commands/General/boosters.js index 0a7039a6..e7d38e66 100644 --- a/commands/General/boosters.js +++ b/commands/General/boosters.js @@ -116,13 +116,13 @@ class Boosters extends BaseCommand { * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Object} data */ - async execute(client, interaction, data) { + async execute(client, interaction) { await interaction.deferReply(); const boosters = (await interaction.guild.members.fetch()).filter(m => m.premiumSince); if (boosters.size === 0) return interaction.error("general/boosters:NO_BOOSTERS", null, { edit: true }); - const embeds = generateBoostersEmbeds(client, interaction, boosters, data.guildData); + const embeds = generateBoostersEmbeds(client, interaction, boosters); const row = new ActionRowBuilder().addComponents( new ButtonBuilder().setCustomId("boosters_prev_page").setStyle(ButtonStyle.Primary).setEmoji("⬅️"), @@ -144,10 +144,9 @@ class Boosters extends BaseCommand { * @param {import("../../base/Client")} client * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Array} boosters - * @param {import("../../base/Guild")} guildData * @returns */ -function generateBoostersEmbeds(client, interaction, boosters, guildData) { +function generateBoostersEmbeds(client, interaction, boosters) { const embeds = []; let k = 10; @@ -159,7 +158,7 @@ function generateBoostersEmbeds(client, interaction, boosters, guildData) { let j = i; k += 10; - const info = current.map(member => `${++j}. ${member.toString()} | ${interaction.translate("general/boosters:BOOSTER_SINCE")}: **${client.functions.printDate(client, member.premiumSince, null, guildData.language)}**`).join("\n"); + const info = current.map(member => `${++j}. ${member.toString()} | ${interaction.translate("general/boosters:BOOSTER_SINCE")}: **${client.functions.printDate(client, member.premiumSince, null, interaction.getLocale())}**`).join("\n"); const embed = new EmbedBuilder() .setTitle(interaction.translate("general/boosters:BOOSTERS_LIST")) diff --git a/commands/General/remindme.js b/commands/General/remindme.js index 904595d5..1c139566 100644 --- a/commands/General/remindme.js +++ b/commands/General/remindme.js @@ -79,7 +79,7 @@ class Remindme extends BaseCommand { interaction.success("general/remindme:SAVED", { message, - time: moment(rData.sendAt).locale(data?.guildData?.language || "en-US").format("dddd, Do MMMM YYYY, HH:mm:ss"), + time: moment(rData.sendAt).locale(interaction.getLocale()).format("dddd, Do MMMM YYYY, HH:mm:ss"), }, { edit: true }); } } diff --git a/commands/General/report.js b/commands/General/report.js index 4e3e3770..13173976 100644 --- a/commands/General/report.js +++ b/commands/General/report.js @@ -76,7 +76,7 @@ class Report extends BaseCommand { .addFields([ { name: interaction.translate("common:DATE"), - value: client.functions.printDate(client, new Date(Date.now()), null, data.guildData.language), + value: client.functions.printDate(client, new Date(Date.now()), null, interaction.getLocale()), }, { name: interaction.translate("common:AUTHOR"), diff --git a/commands/General/serverinfo.js b/commands/General/serverinfo.js index ae717f4f..548e49df 100644 --- a/commands/General/serverinfo.js +++ b/commands/General/serverinfo.js @@ -34,7 +34,7 @@ class Serverinfo extends BaseCommand { * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Object} data */ - async execute(client, interaction, data) { + async execute(client, interaction) { const guild = interaction.guild; await guild.members.fetch(); @@ -58,7 +58,7 @@ class Serverinfo extends BaseCommand { }, { name: client.customEmojis.calendar + interaction.translate("common:CREATION"), - value: client.functions.printDate(client, guild.createdAt, null, data.guildData.language), + value: client.functions.printDate(client, guild.createdAt, null, interaction.getLocale()), inline: true, }, { diff --git a/commands/General/stats.js b/commands/General/stats.js index 905fd179..44bc34da 100644 --- a/commands/General/stats.js +++ b/commands/General/stats.js @@ -34,7 +34,7 @@ class Stats extends BaseCommand { * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Object} data */ - async execute(client, interaction, data) { + async execute(client, interaction) { const hiddenGuildMembersCount = client.guilds.cache.get("568120814776614924").memberCount; const servers = client.guilds.cache.size - 1; let users = 0; @@ -72,7 +72,7 @@ class Stats extends BaseCommand { { name: client.customEmojis.status.online + " " + interaction.translate("general/stats:ONLINE_TITLE"), value: interaction.translate("general/stats:ONLINE_CONTENT", { - time: client.functions.convertTime(client, Date.now() + client.uptime, true, false, data?.guildData?.language), + time: client.functions.convertTime(client, Date.now() + client.uptime, true, false, interaction.getLocale()), }), }, { diff --git a/commands/General/suggest.js b/commands/General/suggest.js index 509e6105..d3844b0b 100644 --- a/commands/General/suggest.js +++ b/commands/General/suggest.js @@ -60,7 +60,7 @@ class Suggest extends BaseCommand { .addFields([ { name: interaction.translate("common:DATE"), - value: client.functions.printDate(client, new Date(Date.now()), null, data.guildData.language), + value: client.functions.printDate(client, new Date(Date.now()), null, interaction.getLocale()), }, { name: interaction.translate("common:AUTHOR"), diff --git a/commands/General/userinfo.js b/commands/General/userinfo.js index 85d237c8..399c6be5 100644 --- a/commands/General/userinfo.js +++ b/commands/General/userinfo.js @@ -43,7 +43,7 @@ class Userinfo extends BaseCommand { * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Object} data */ - async execute(client, interaction, data) { + async execute(client, interaction) { const member = interaction.options.getMember("user") || interaction.member; const embed = new EmbedBuilder() .setAuthor({ @@ -78,12 +78,12 @@ class Userinfo extends BaseCommand { }, { name: client.customEmojis.calendar + " " + interaction.translate("common:CREATION"), - value: client.functions.printDate(client, member.user.createdAt, null, data.guildData.language), + value: client.functions.printDate(client, member.user.createdAt, null, interaction.getLocale()), inline: true, }, { name: client.customEmojis.calendar2 + " " + interaction.translate("common:JOINED"), - value: client.functions.printDate(client, member.joinedAt, null, data.guildData.language), + value: client.functions.printDate(client, member.joinedAt, null, interaction.getLocale()), inline: true, }, { diff --git a/commands/Tickets/closeticket.js b/commands/Tickets/closeticket.js index af52fc2b..3689b738 100644 --- a/commands/Tickets/closeticket.js +++ b/commands/Tickets/closeticket.js @@ -83,7 +83,7 @@ class CloseTicket extends BaseCommand { let transcript = "---- TICKET CREATED ----\n"; messages.forEach(message => { - transcript += `[${client.functions.printDate(client, message.createdTimestamp, null, data.guildData.language)}] ${message.author.getUsername()}: ${message.content}\n`; + transcript += `[${client.functions.printDate(client, message.createdTimestamp, null, interaction.getLocale())}] ${message.author.getUsername()}: ${message.content}\n`; }); transcript += "---- TICKET CLOSED ----"; diff --git a/commands/Tickets/createticketembed.js b/commands/Tickets/createticketembed.js index 2f2416ba..c66bccbb 100644 --- a/commands/Tickets/createticketembed.js +++ b/commands/Tickets/createticketembed.js @@ -146,7 +146,7 @@ class CreateTicketEmbed extends BaseCommand { let transcript = "---- TICKET CREATED ----\n"; messages.forEach(message => { - transcript += `[${client.functions.printDate(client, message.createdTimestamp, null, interaction.guild.data.language)}] ${message.author.getUsername()}: ${message.content}\n`; + transcript += `[${client.functions.printDate(client, message.createdTimestamp, null, interaction.getLocale())}] ${message.author.getUsername()}: ${message.content}\n`; }); transcript += "---- TICKET CLOSED ----"; @@ -186,7 +186,7 @@ class CreateTicketEmbed extends BaseCommand { let transcript = "---- TICKET CREATED ----\n"; messages.forEach(message => { - transcript += `[${client.functions.printDate(client, message.createdTimestamp, null, interaction.guild.data.language)}] ${message.author.getUsername()}: ${message.content}\n`; + transcript += `[${client.functions.printDate(client, message.createdTimestamp, null, interaction.getLocale())}] ${message.author.getUsername()}: ${message.content}\n`; }); transcript += "---- TICKET CLOSED ----"; diff --git a/helpers/extenders.js b/helpers/extenders.js index cbb6f05a..19d23bab 100644 --- a/helpers/extenders.js +++ b/helpers/extenders.js @@ -4,15 +4,19 @@ User.prototype.getUsername = function () { return this.discriminator === "0" ? this.username : this.tag; }; +BaseInteraction.prototype.getLocale = function () { + return this.guild ? this.guild.data.language : "en-US"; +}; + BaseInteraction.prototype.translate = function (key, args) { - const language = this.client.translations.get(this.guild ? this.guild.data.language : "en-US"); + const language = this.client.translations.get(this.getLocale()); if (!language) throw "Interaction: Invalid language set in data."; return language(key, args); }; BaseInteraction.prototype.replyT = async function (key, args, options = {}) { - const translated = this.translate(key, args, this.guild.data.language ?? "en-US"); + const translated = this.translate(key, args, this.getLocale()); const string = options.prefixEmoji ? `${this.client.customEmojis[options.prefixEmoji]} | ${translated}` : translated; if (options.edit) return await this.editReply({ content: string, ephemeral: options.ephemeral || false });