diff --git a/commands/Economy/birthdate.js b/commands/Economy/birthdate.js index 6f11f61d..87989fd1 100644 --- a/commands/Economy/birthdate.js +++ b/commands/Economy/birthdate.js @@ -72,7 +72,7 @@ class Birthdate extends BaseCommand { await data.userData.save(); interaction.success("economy/birthdate:SUCCESS", { - date: client.functions.printDate(d), + date: client.functions.printDate(client, d), }); } diff --git a/commands/Economy/number.js b/commands/Economy/number.js index 92e8296d..48e4cd90 100644 --- a/commands/Economy/number.js +++ b/commands/Economy/number.js @@ -57,7 +57,7 @@ class Number extends BaseCommand { const parsedNumber = parseInt(msg.content, 10); if (parsedNumber === number) { - const time = client.functions.convertTime(gameCreatedAt, false, false, data.guildData.language); + const time = client.functions.convertTime(client, gameCreatedAt, false, false, data.guildData.language); interaction.channel.send({ content: interaction.translate("economy/number:GAME_STATS", { winner: msg.author.toString(), diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index 97a94d26..7608e42c 100644 --- a/commands/Economy/profile.js +++ b/commands/Economy/profile.js @@ -109,12 +109,12 @@ class Profile extends BaseCommand { }, { name: interaction.translate("economy/profile:REGISTERED"), - value: client.functions.printDate(new Date(memberData.registeredAt)), + value: client.functions.printDate(client, new Date(memberData.registeredAt)), inline: true, }, { name: interaction.translate("economy/profile:BIRTHDATE"), - value: (!userData.birthdate ? interaction.translate("common:NOT_DEFINED") : client.functions.printDate(new Date(userData.birthdate))), + value: (!userData.birthdate ? interaction.translate("common:NOT_DEFINED") : client.functions.printDate(client, new Date(userData.birthdate))), inline: true, }, { diff --git a/commands/Economy/rep.js b/commands/Economy/rep.js index e4d12886..2cec0a2b 100644 --- a/commands/Economy/rep.js +++ b/commands/Economy/rep.js @@ -39,7 +39,7 @@ class Rep extends BaseCommand { const isInCooldown = data.userData.cooldowns?.rep; if (isInCooldown) { if (isInCooldown > Date.now()) return interaction.error("economy/rep:COOLDOWN", { - time: client.functions.convertTime(isInCooldown, true, true, data.guildData.language), + time: client.functions.convertTime(client, isInCooldown, true, true, data.guildData.language), }); } diff --git a/commands/Economy/transactions.js b/commands/Economy/transactions.js index dcdfef27..625b669f 100644 --- a/commands/Economy/transactions.js +++ b/commands/Economy/transactions.js @@ -57,7 +57,7 @@ class Transactions extends BaseCommand { transactions.slice(-20).forEach(t => { const array = t.type === "got" ? sortedTransactions[0] : sortedTransactions[1]; - 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(t.date, "Do MMMM YYYY, HH:mm", data.guildData.language)}\n`); + 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`); }); if (transactions.length < 1) { diff --git a/commands/Economy/work.js b/commands/Economy/work.js index aea84c5d..e172e5b8 100644 --- a/commands/Economy/work.js +++ b/commands/Economy/work.js @@ -35,7 +35,7 @@ class Work extends BaseCommand { const isInCooldown = data.memberData.cooldowns?.work; if (isInCooldown) { if (isInCooldown > Date.now()) return interaction.error("economy/work:COOLDOWN", { - time: client.functions.convertTime(isInCooldown, true, true, data.guildData.language), + time: client.functions.convertTime(client, isInCooldown, true, true, data.guildData.language), }); } if (Date.now() > data.memberData.cooldowns.work + (24 * 60 * 60 * 1000)) data.memberData.workStreak = 0; diff --git a/commands/General/boosters.js b/commands/General/boosters.js index 55ea2090..c4d390ce 100644 --- a/commands/General/boosters.js +++ b/commands/General/boosters.js @@ -159,7 +159,7 @@ function generateBoostersEmbeds(client, interaction, boosters) { let j = i; k += 10; - const info = current.map(member => `${++j}. ${member.toString()} | ${interaction.translate("general/boosters:BOOSTER_SINCE")}: **${client.functions.printDate(member.premiumSince, null, interaction.guild.data.locale)}**`).join("\n"); + const info = current.map(member => `${++j}. ${member.toString()} | ${interaction.translate("general/boosters:BOOSTER_SINCE")}: **${client.functions.printDate(client, member.premiumSince, null, interaction.guild.data.locale)}**`).join("\n"); const embed = new EmbedBuilder() .setColor(interaction.client.config.embed.color) diff --git a/commands/General/report.js b/commands/General/report.js index a38e33a4..7f13b35d 100644 --- a/commands/General/report.js +++ b/commands/General/report.js @@ -59,7 +59,7 @@ class Report extends BaseCommand { .addFields([ { name: interaction.translate("common:DATE"), - value: client.functions.printDate(new Date(Date.now())), + value: client.functions.printDate(client, new Date(Date.now())), }, { name: interaction.translate("common:AUTHOR"), diff --git a/commands/General/serverinfo.js b/commands/General/serverinfo.js index 7aa39210..e0b7433b 100644 --- a/commands/General/serverinfo.js +++ b/commands/General/serverinfo.js @@ -55,7 +55,7 @@ class Serverinfo extends BaseCommand { }, { name: client.customEmojis.calendar + interaction.translate("common:CREATION"), - value: client.functions.printDate(guild.createdAt), + value: client.functions.printDate(client, guild.createdAt), inline: true, }, { diff --git a/commands/General/stats.js b/commands/General/stats.js index d51ab96a..6089dd4e 100644 --- a/commands/General/stats.js +++ b/commands/General/stats.js @@ -70,7 +70,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(Date.now() + client.uptime, true, true, data.guildData.language), + time: client.functions.convertTime(client, Date.now() + client.uptime, true, true, data.guildData.language), }), }, { diff --git a/commands/General/suggest.js b/commands/General/suggest.js index 5f6f1668..46693142 100644 --- a/commands/General/suggest.js +++ b/commands/General/suggest.js @@ -50,7 +50,7 @@ class Suggest extends BaseCommand { .addFields([ { name: interaction.translate("common:DATE"), - value: client.functions.printDate(new Date(Date.now())), + value: client.functions.printDate(client, new Date(Date.now())), }, { name: interaction.translate("common:AUTHOR"), diff --git a/commands/General/userinfo.js b/commands/General/userinfo.js index aa674eba..42a2ac48 100644 --- a/commands/General/userinfo.js +++ b/commands/General/userinfo.js @@ -67,12 +67,12 @@ class Userinfo extends BaseCommand { }, { name: client.customEmojis.calendar + " " + interaction.translate("common:CREATION"), - value: client.functions.printDate(member.user.createdAt), + value: client.functions.printDate(client, member.user.createdAt), inline: true, }, { name: client.customEmojis.calendar2 + " " + interaction.translate("common:JOINED"), - value: client.functions.printDate(member.joinedAt), + value: client.functions.printDate(client, member.joinedAt), inline: true, }, { diff --git a/dashboard/app.js b/dashboard/app.js index ac25768d..a6fbf965 100644 --- a/dashboard/app.js +++ b/dashboard/app.js @@ -45,8 +45,8 @@ module.exports.init = async(client) => { if (req.user && req.url !== "/") req.userInfos = await utils.fetchUser(req.user, req.client); if (req.user) { req.translate = req.client.translations.get(req.locale); - req.printDate = (date) => req.client.functions.printDate(date, null, req.locale); - req.convertTime = (time) => req.client.functions.convertTime(time, "to", true, req.locale); + req.printDate = (date) => req.client.functions.printDate(client, date, null, req.locale); + req.convertTime = (time) => req.client.functions.convertTime(client, time, "to", true, req.locale); } next(); }) diff --git a/helpers/functions.js b/helpers/functions.js index baeead2e..a41deb99 100644 --- a/helpers/functions.js +++ b/helpers/functions.js @@ -88,13 +88,14 @@ module.exports = { /** * Beautify date + * @param {import("../base/JaBa")} client Discord client * @param {Date} date Date * @param {String | null} format Format for moment * @param {String} locale Language * @returns {String} Beautified date */ - printDate(date, format = "", locale = this.defaultLanguage) { - const languageData = this.languages.find(language => language.name === locale); + printDate(client, date, format = "", locale = client.defaultLanguage) { + const languageData = client.languages.find(language => language.name === locale); if (format === "" || format === null) format = languageData.defaultMomentFormat; return moment(new Date(date)) @@ -104,14 +105,15 @@ module.exports = { /** * Convert given time + * @param {import("../base/JaBa")} client Discord client * @param {String} time Time * @param {Boolean} type Type (To now = true or from now = false) * @param {Boolean} noPrefix Use prefix? * @param {String} locale Language * @returns {String} Time */ - convertTime(time, type = false, noPrefix = false, locale = this.defaultLanguage) { - const languageData = this.languages.find(language => language.name === locale); + convertTime(client, time, type = false, noPrefix = false, locale = this.defaultLanguage) { + const languageData = client.languages.find(language => language.name === locale); const m = moment(time).locale(languageData.moment); return (type ? m.toNow(noPrefix) : m.fromNow(noPrefix));