diff --git a/base/JaBa.js b/base/JaBa.js index 0e63f617..d7544346 100644 --- a/base/JaBa.js +++ b/base/JaBa.js @@ -9,15 +9,7 @@ const BaseEvent = require("./BaseEvent.js"), BaseCommand = require("./BaseCommand.js"), path = require("path"), fs = require("fs").promises, - mongoose = require("mongoose"), - moment = require("moment"); - -moment.relativeTimeThreshold("ss", 5); -moment.relativeTimeThreshold("s", 60); -moment.relativeTimeThreshold("m", 60); -moment.relativeTimeThreshold("h", 60); -moment.relativeTimeThreshold("d", 24); -moment.relativeTimeThreshold("M", 12); + mongoose = require("mongoose"); class JaBa extends Client { constructor(options) { @@ -249,56 +241,6 @@ class JaBa extends Client { return language(key, args); } - /** - * Beautify date - * @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); - if (format === "" || format === null) format = languageData.defaultMomentFormat; - - return moment(new Date(date)) - .locale(languageData.moment) - .format(format); - } - - /** - * Convert given time - * @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); - const m = moment(time).locale(languageData.moment); - - return (type ? m.toNow(noPrefix) : m.fromNow(noPrefix)); - } - - /** - * Get noun for number - * @param {Number} number Number - * @param {String} one String for one - * @param {String} two String for two - * @param {String} five String for five - * @returns - */ - getNoun(number, one, two, five) { - let n = Math.abs(number); - n %= 100; - if (n >= 5 && n <= 20) return five; - n %= 10; - if (n === 1) return one; - if (n >= 2 && n <= 4) return two; - - return five; - } - /** * Find or create user in DB * @param {Array} param0 { id: User ID } diff --git a/commands/Economy/bank.js b/commands/Economy/bank.js index ca3b8b76..153d154d 100644 --- a/commands/Economy/bank.js +++ b/commands/Economy/bank.js @@ -49,7 +49,7 @@ class Bank extends BaseCommand { if (choice === "deposit") { const credits = interaction.options.getString("credits") === "all" ? data.memberData.money : interaction.options.getString("credits"); if (isNaN(credits) || credits < 1) return interaction.error("misc:OPTION_NAN_ALL"); - if (data.memberData.money < credits) return interaction.error("economy/bank:NOT_ENOUGH_CREDIT", { money: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }); + if (data.memberData.money < credits) return interaction.error("economy/bank:NOT_ENOUGH_CREDIT", { money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }); data.memberData.money -= credits; data.memberData.bankSold += credits; @@ -64,12 +64,12 @@ class Bank extends BaseCommand { data.memberData.transactions.push(info); interaction.success("economy/bank:SUCCESS_DEP", { - money: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, }); } else { const credits = interaction.options.getString("credits") === "all" ? data.memberData.bankSold : interaction.options.getString("credits"); if (isNaN(credits) || credits < 1) return interaction.error("misc:OPTION_NAN_ALL"); - if (data.memberData.bankSold < credits) return interaction.error("economy/bank:NOT_ENOUGH_BANK", { money: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }); + if (data.memberData.bankSold < credits) return interaction.error("economy/bank:NOT_ENOUGH_BANK", { money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }); const info = { user: interaction.translate("economy/transactions:BANK"), @@ -85,7 +85,7 @@ class Bank extends BaseCommand { await data.memberData.save(); interaction.success("economy/bank:SUCCESS_WD", { - money: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, }); } } diff --git a/commands/Economy/birthdate.js b/commands/Economy/birthdate.js index b7aceb62..6f11f61d 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.printDate(d), + date: client.functions.printDate(d), }); } diff --git a/commands/Economy/money.js b/commands/Economy/money.js index 5223d68f..0239f8da 100644 --- a/commands/Economy/money.js +++ b/commands/Economy/money.js @@ -65,17 +65,17 @@ class Money extends BaseCommand { .addFields([ { name: interaction.translate("economy/profile:CASH"), - value: `**${memberData.money}** ${client.getNoun(memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + value: `**${memberData.money}** ${client.functions.getNoun(memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, inline: true, }, { name: interaction.translate("economy/profile:BANK"), - value: `**${memberData.bankSold}** ${client.getNoun(memberData.bankSold, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + value: `**${memberData.bankSold}** ${client.functions.getNoun(memberData.bankSold, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, inline: true, }, { name: interaction.translate("economy/profile:GLOBAL"), - value: `**${globalMoney}** ${client.getNoun(globalMoney, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + value: `**${globalMoney}** ${client.functions.getNoun(globalMoney, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, inline: true, }, ]) diff --git a/commands/Economy/number.js b/commands/Economy/number.js index e3331a3e..92e8296d 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.convertTime(gameCreatedAt, false, false, data.guildData.language); + const time = client.functions.convertTime(gameCreatedAt, false, false, data.guildData.language); interaction.channel.send({ content: interaction.translate("economy/number:GAME_STATS", { winner: msg.author.toString(), @@ -74,7 +74,7 @@ class Number extends BaseCommand { interaction.channel.send({ content: interaction.translate("economy/number:WON", { winner: msg.author.username, - credits: `**${won}** ${client.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + credits: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, }), }); diff --git a/commands/Economy/pay.js b/commands/Economy/pay.js index 33b2401f..2fa68ca5 100644 --- a/commands/Economy/pay.js +++ b/commands/Economy/pay.js @@ -47,7 +47,7 @@ class Pay extends BaseCommand { const amount = interaction.options.getInteger("amount"); if (amount <= 0) return interaction.error("misc:MORE_THAN_ZERO"); if (amount > data.memberData.money) return interaction.error("economy/pay:ENOUGH_MONEY", { - amount: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDITS:1"), interaction.translate("misc:NOUNS:CREDITS:2"), interaction.translate("misc:NOUNS:CREDITS:5"))}`, + amount: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDITS:1"), interaction.translate("misc:NOUNS:CREDITS:2"), interaction.translate("misc:NOUNS:CREDITS:5"))}`, }); const memberData = await client.findOrCreateMember({ @@ -79,7 +79,7 @@ class Pay extends BaseCommand { interaction.success("economy/pay:SUCCESS", { user: member.toString(), - amount: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + amount: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, }); } } diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index 265320df..97a94d26 100644 --- a/commands/Economy/profile.js +++ b/commands/Economy/profile.js @@ -79,22 +79,22 @@ class Profile extends BaseCommand { }, { name: interaction.translate("economy/profile:CASH"), - value: `**${memberData.money}** ${client.getNoun(memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + value: `**${memberData.money}** ${client.functions.getNoun(memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, inline: true, }, { name: interaction.translate("economy/profile:BANK"), - value: `**${memberData.bankSold}** ${client.getNoun(memberData.bankSold, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + value: `**${memberData.bankSold}** ${client.functions.getNoun(memberData.bankSold, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, inline: true, }, { name: interaction.translate("economy/profile:GLOBAL"), - value: `**${globalMoney}** ${client.getNoun(globalMoney, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + value: `**${globalMoney}** ${client.functions.getNoun(globalMoney, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, inline: true, }, { name: interaction.translate("economy/profile:REPUTATION"), - value: `**${userData.rep}** ${client.getNoun(userData.rep, interaction.translate("misc:NOUNS:POINTS:1"), interaction.translate("misc:NOUNS:POINTS:2"), interaction.translate("misc:NOUNS:POINTS:5"))}`, + value: `**${userData.rep}** ${client.functions.getNoun(userData.rep, interaction.translate("misc:NOUNS:POINTS:1"), interaction.translate("misc:NOUNS:POINTS:2"), interaction.translate("misc:NOUNS:POINTS:5"))}`, inline: true, }, { @@ -109,12 +109,12 @@ class Profile extends BaseCommand { }, { name: interaction.translate("economy/profile:REGISTERED"), - value: client.printDate(new Date(memberData.registeredAt)), + value: client.functions.printDate(new Date(memberData.registeredAt)), inline: true, }, { name: interaction.translate("economy/profile:BIRTHDATE"), - value: (!userData.birthdate ? interaction.translate("common:NOT_DEFINED") : client.printDate(new Date(userData.birthdate))), + value: (!userData.birthdate ? interaction.translate("common:NOT_DEFINED") : client.functions.printDate(new Date(userData.birthdate))), inline: true, }, { diff --git a/commands/Economy/rep.js b/commands/Economy/rep.js index 10dc1b9e..e4d12886 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.convertTime(isInCooldown, true, true, data.guildData.language), + time: client.functions.convertTime(isInCooldown, true, true, data.guildData.language), }); } diff --git a/commands/Economy/rob.js b/commands/Economy/rob.js index 44a479bb..abb50ef1 100644 --- a/commands/Economy/rob.js +++ b/commands/Economy/rob.js @@ -60,8 +60,8 @@ class Rob extends BaseCommand { const potentiallyLose = Math.floor(amount * 1.5); if (potentiallyLose > data.memberData.money) return interaction.error("economy/rob:NOT_ENOUGH_AUTHOR", { - moneyMin: `**${potentiallyLose}** ${client.getNoun(potentiallyLose, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, - moneyCurrent: `**${data.memberData.money}** ${client.getNoun(data.memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + moneyMin: `**${potentiallyLose}** ${client.functions.getNoun(potentiallyLose, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + moneyCurrent: `**${data.memberData.money}** ${client.functions.getNoun(data.memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, }); const itsAWon = Math.floor(client.functions.randomNum(0, 100) < 25); @@ -75,7 +75,7 @@ class Rob extends BaseCommand { await memberData.save(); interaction.replyT("economy/rob:ROB_WON_" + randomNum, { - money: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, user: member.toString(), }); @@ -89,8 +89,8 @@ class Rob extends BaseCommand { randomNum = client.functions.randomNum(1, 2); interaction.replyT("economy/rob:ROB_LOSE_" + randomNum, { - fine: `**${potentiallyLose}** ${client.getNoun(potentiallyLose, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, - offset: `**${won}** ${client.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + fine: `**${potentiallyLose}** ${client.functions.getNoun(potentiallyLose, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + offset: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, user: member.toString(), }); diff --git a/commands/Economy/slots.js b/commands/Economy/slots.js index 0d6e24cd..42b36ad2 100644 --- a/commands/Economy/slots.js +++ b/commands/Economy/slots.js @@ -39,7 +39,7 @@ class Slots extends BaseCommand { await interaction.deferReply(); const amount = interaction.options.getInteger("amount"); - if (amount > data.memberData.money) return interaction.error("economy/slots:NOT_ENOUGH", { money: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }, { edit: true }); + if (amount > data.memberData.money) return interaction.error("economy/slots:NOT_ENOUGH", { money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }, { edit: true }); const fruits = ["🍎", "🍐", "🍌", "πŸ‡", "πŸ‰", "πŸ’", "πŸ“"]; @@ -95,8 +95,8 @@ class Slots extends BaseCommand { const credits = getCredits(amount, true); interaction.followUp({ content: "**!! Π”Π–Π•ΠšΠŸΠžΠ’ !!**\n" + interaction.translate("economy/slots:VICTORY", { - money: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, - won: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + won: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, user: interaction.member.toString(), }), }); @@ -140,8 +140,8 @@ class Slots extends BaseCommand { const credits = getCredits(amount, false); interaction.followUp({ content: interaction.translate("economy/slots:VICTORY", { - money: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, - won: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + won: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, user: interaction.member.toString(), }), }); @@ -177,7 +177,7 @@ class Slots extends BaseCommand { msg += "| : : : **" + (interaction.translate("common:DEFEAT").toUpperCase()) + "** : : : |"; interaction.followUp({ content: interaction.translate("economy/slots:DEFEAT", { - money: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, user: interaction.member.toString(), }), }); diff --git a/commands/Economy/transactions.js b/commands/Economy/transactions.js index 20ecc5c8..dcdfef27 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.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(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 4ab3a73f..aea84c5d 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.convertTime(isInCooldown, true, true, data.guildData.language), + time: client.functions.convertTime(isInCooldown, true, true, data.guildData.language), }); } if (Date.now() > data.memberData.cooldowns.work + (24 * 60 * 60 * 1000)) data.memberData.workStreak = 0; @@ -69,7 +69,7 @@ class Work extends BaseCommand { { name: interaction.translate("economy/work:SALARY"), value: interaction.translate("economy/work:SALARY_CONTENT", { - won: `**${won}** ${client.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + won: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, }), }, { @@ -89,7 +89,7 @@ class Work extends BaseCommand { { name: interaction.translate("economy/work:SALARY"), value: interaction.translate("economy/work:SALARY_CONTENT", { - won: `**${won}** ${client.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, + won: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`, }), }, { diff --git a/commands/General/boosters.js b/commands/General/boosters.js index 6838f008..55ea2090 100644 --- a/commands/General/boosters.js +++ b/commands/General/boosters.js @@ -36,7 +36,9 @@ class Boosters extends BaseCommand { let currentPage = 0; const boosters = (await interaction.guild.members.fetch()).filter(m => m.premiumSince); - const embeds = generateBoostersEmbeds(interaction, boosters); + if (boosters.size === 0) return interaction.error("general/boosters:NO_BOOSTERS", null, { edit: true }); + + const embeds = generateBoostersEmbeds(client, interaction, boosters); const row = new ActionRowBuilder() .addComponents( @@ -143,11 +145,12 @@ class Boosters extends BaseCommand { /** * + * @param {import("../../base/JaBa")} client * @param {import("discord.js").ChatInputCommandInteraction} interaction * @param {Array} boosters * @returns */ -function generateBoostersEmbeds(interaction, boosters) { +function generateBoostersEmbeds(client, interaction, boosters) { const embeds = []; let k = 10; @@ -156,7 +159,7 @@ function generateBoostersEmbeds(interaction, boosters) { let j = i; k += 10; - const info = current.map(member => `${++j}. ${member.toString()} | ${interaction.translate("general/boosters:BOOSTER_SINCE")}: **${interaction.client.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(member.premiumSince, null, interaction.guild.data.locale)}**`).join("\n"); const embed = new EmbedBuilder() .setColor(interaction.client.config.embed.color) diff --git a/commands/General/minecraft.js b/commands/General/minecraft.js index 6bfc60f6..9df0b71c 100644 --- a/commands/General/minecraft.js +++ b/commands/General/minecraft.js @@ -71,7 +71,7 @@ class Minecraft extends BaseCommand { }, { name: interaction.translate("general/minecraft:FIELD_CONNECTED"), - value: `**${(res.raw.players ? res.raw.players.online : res.players.length)}** ${client.getNoun((res.raw.players ? res.raw.players.online : res.players.length), interaction.translate("misc:NOUNS:PLAYERS:1"), interaction.translate("misc:NOUNS:PLAYERS:2"), interaction.translate("misc:NOUNS:PLAYERS:5"))} / **${(res.raw.players ? res.raw.players.max : res.maxplayers)}** ${client.getNoun((res.raw.players ? res.raw.players.max : res.maxplayers), interaction.translate("misc:NOUNS:PLAYERS:1"), interaction.translate("misc:NOUNS:PLAYERS:2"), interaction.translate("misc:NOUNS:PLAYERS:5"))}`, + value: `**${(res.raw.players ? res.raw.players.online : res.players.length)}** ${client.functions.getNoun((res.raw.players ? res.raw.players.online : res.players.length), interaction.translate("misc:NOUNS:PLAYERS:1"), interaction.translate("misc:NOUNS:PLAYERS:2"), interaction.translate("misc:NOUNS:PLAYERS:5"))} / **${(res.raw.players ? res.raw.players.max : res.maxplayers)}** ${client.functions.getNoun((res.raw.players ? res.raw.players.max : res.maxplayers), interaction.translate("misc:NOUNS:PLAYERS:1"), interaction.translate("misc:NOUNS:PLAYERS:2"), interaction.translate("misc:NOUNS:PLAYERS:5"))}`, }, { name: interaction.translate("general/minecraft:FIELD_IP"), diff --git a/commands/General/report.js b/commands/General/report.js index 872517cb..a38e33a4 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.printDate(new Date(Date.now())), + value: client.functions.printDate(new Date(Date.now())), }, { name: interaction.translate("common:AUTHOR"), diff --git a/commands/General/serverinfo.js b/commands/General/serverinfo.js index 33e4c6c1..7aa39210 100644 --- a/commands/General/serverinfo.js +++ b/commands/General/serverinfo.js @@ -55,13 +55,13 @@ class Serverinfo extends BaseCommand { }, { name: client.customEmojis.calendar + interaction.translate("common:CREATION"), - value: client.printDate(guild.createdAt), + value: client.functions.printDate(guild.createdAt), inline: true, }, { name: client.customEmojis.users + interaction.translate("common:MEMBERS"), - value: `${guild.members.cache.filter(m => !m.user.bot).size} ${client.getNoun(guild.members.cache.filter(m => !m.user.bot).size, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}` + - "\n" + `${guild.members.cache.filter(m => m.user.bot).size} ${client.getNoun(guild.members.cache.filter(m => m.user.bot).size, interaction.translate("misc:NOUNS:BOTS:1"), interaction.translate("misc:NOUNS:BOTS:2"), interaction.translate("misc:NOUNS:BOTS:5"))}`, + value: `${guild.members.cache.filter(m => !m.user.bot).size} ${client.functions.getNoun(guild.members.cache.filter(m => !m.user.bot).size, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}` + + "\n" + `${guild.members.cache.filter(m => m.user.bot).size} ${client.functions.getNoun(guild.members.cache.filter(m => m.user.bot).size, interaction.translate("misc:NOUNS:BOTS:1"), interaction.translate("misc:NOUNS:BOTS:2"), interaction.translate("misc:NOUNS:BOTS:5"))}`, inline: true, }, { @@ -86,9 +86,9 @@ class Serverinfo extends BaseCommand { }, { name: client.customEmojis.channels + interaction.translate("common:CHANNELS"), - value: `${guild.channels.cache.filter(c => c.type === ChannelType.GuildText).size} ${client.getNoun(guild.channels.cache.filter(c => c.type === ChannelType.GuildText).size, interaction.translate("misc:NOUNS:TEXT:1"), interaction.translate("misc:NOUNS:TEXT:2"), interaction.translate("misc:NOUNS:TEXT:5"))}` + - "\n" + `${guild.channels.cache.filter(c => c.type === ChannelType.GuildVoice).size} ${client.getNoun(guild.channels.cache.filter(c => c.type === ChannelType.GuildVoice).size, interaction.translate("misc:NOUNS:VOICE:1"), interaction.translate("misc:NOUNS:VOICE:2"), interaction.translate("misc:NOUNS:VOICE:5"))}` + - "\n" + `${guild.channels.cache.filter(c => c.type === ChannelType.GuildCategory).size} ${client.getNoun(guild.channels.cache.filter(c => c.type === ChannelType.GuildCategory).size, interaction.translate("misc:NOUNS:CATEGORY:1"), interaction.translate("misc:NOUNS:CATEGORY:2"), interaction.translate("misc:NOUNS:CATEGORY:5"))}`, + value: `${guild.channels.cache.filter(c => c.type === ChannelType.GuildText).size} ${client.functions.getNoun(guild.channels.cache.filter(c => c.type === ChannelType.GuildText).size, interaction.translate("misc:NOUNS:TEXT:1"), interaction.translate("misc:NOUNS:TEXT:2"), interaction.translate("misc:NOUNS:TEXT:5"))}` + + "\n" + `${guild.channels.cache.filter(c => c.type === ChannelType.GuildVoice).size} ${client.functions.getNoun(guild.channels.cache.filter(c => c.type === ChannelType.GuildVoice).size, interaction.translate("misc:NOUNS:VOICE:1"), interaction.translate("misc:NOUNS:VOICE:2"), interaction.translate("misc:NOUNS:VOICE:5"))}` + + "\n" + `${guild.channels.cache.filter(c => c.type === ChannelType.GuildCategory).size} ${client.functions.getNoun(guild.channels.cache.filter(c => c.type === ChannelType.GuildCategory).size, interaction.translate("misc:NOUNS:CATEGORY:1"), interaction.translate("misc:NOUNS:CATEGORY:2"), interaction.translate("misc:NOUNS:CATEGORY:5"))}`, inline: true, }, ]) diff --git a/commands/General/stats.js b/commands/General/stats.js index 0dbd3e89..d51ab96a 100644 --- a/commands/General/stats.js +++ b/commands/General/stats.js @@ -70,13 +70,13 @@ class Stats extends BaseCommand { { name: client.customEmojis.status.online + " " + interaction.translate("general/stats:ONLINE_TITLE"), value: interaction.translate("general/stats:ONLINE_CONTENT", { - time: client.convertTime(Date.now() + client.uptime, true, true, data.guildData.language), + time: client.functions.convertTime(Date.now() + client.uptime, true, true, data.guildData.language), }), }, { name: client.customEmojis.voice + " " + interaction.translate("general/stats:MUSIC_TITLE"), value: interaction.translate("general/stats:MUSIC_CONTENT", { - count: `${client.player.queues.size} ${client.getNoun(client.player.queues.size, interaction.translate("misc:NOUNS:SERVERS:1"), interaction.translate("misc:NOUNS:SERVERS:2"), interaction.translate("misc:NOUNS:SERVERS:5"))}`, + count: `${client.player.queues.size} ${client.functions.getNoun(client.player.queues.size, interaction.translate("misc:NOUNS:SERVERS:1"), interaction.translate("misc:NOUNS:SERVERS:2"), interaction.translate("misc:NOUNS:SERVERS:5"))}`, }), }, { diff --git a/commands/General/suggest.js b/commands/General/suggest.js index 634738a8..5f6f1668 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.printDate(new Date(Date.now())), + value: client.functions.printDate(new Date(Date.now())), }, { name: interaction.translate("common:AUTHOR"), diff --git a/commands/General/userinfo.js b/commands/General/userinfo.js index 42dcad1b..aa674eba 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.printDate(member.user.createdAt), + value: client.functions.printDate(member.user.createdAt), inline: true, }, { name: client.customEmojis.calendar2 + " " + interaction.translate("common:JOINED"), - value: client.printDate(member.joinedAt), + value: client.functions.printDate(member.joinedAt), inline: true, }, { diff --git a/commands/Moderation/clear.js b/commands/Moderation/clear.js index 59ddae7a..ce034080 100644 --- a/commands/Moderation/clear.js +++ b/commands/Moderation/clear.js @@ -124,12 +124,12 @@ class Clear extends BaseCommand { if (member || user_id) { interaction.replyT("moderation/clear:CLEARED_MEMBER", { - amount: `**${option}** ${client.getNoun(option, interaction.translate("misc:NOUNS:MESSAGES:1"), interaction.translate("misc:NOUNS:MESSAGES:2"), interaction.translate("misc:NOUNS:MESSAGES:5"))}`, + amount: `**${option}** ${client.functions.getNoun(option, interaction.translate("misc:NOUNS:MESSAGES:1"), interaction.translate("misc:NOUNS:MESSAGES:2"), interaction.translate("misc:NOUNS:MESSAGES:5"))}`, user: (member?.user.tag || user_id), }, { edit: true }); } else { interaction.replyT("moderation/clear:CLEARED", { - amount: `**${option}** ${client.getNoun(option, interaction.translate("misc:NOUNS:MESSAGES:1"), interaction.translate("misc:NOUNS:MESSAGES:2"), interaction.translate("misc:NOUNS:MESSAGES:5"))}`, + amount: `**${option}** ${client.functions.getNoun(option, interaction.translate("misc:NOUNS:MESSAGES:1"), interaction.translate("misc:NOUNS:MESSAGES:2"), interaction.translate("misc:NOUNS:MESSAGES:5"))}`, }, { edit: true }); } } diff --git a/commands/Moderation/warn.js b/commands/Moderation/warn.js index 0fbf89ce..2fead199 100644 --- a/commands/Moderation/warn.js +++ b/commands/Moderation/warn.js @@ -125,7 +125,7 @@ class Warn extends BaseCommand { interaction.followUp({ content: interaction.translate("moderation/setwarns:AUTO_BAN", { user: member.user.tag, - count: `${banCount} ${client.getNoun(banCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`, + count: `${banCount} ${client.functions.getNoun(banCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`, }), }); } @@ -154,7 +154,7 @@ class Warn extends BaseCommand { interaction.followUp({ content: interaction.translate("moderation/setwarns:AUTO_KICK", { user: member.user.tag, - count: `${kickCount} ${client.getNoun(kickCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`, + count: `${kickCount} ${client.functions.getNoun(kickCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`, }), }); } diff --git a/commands/Music/queue.js b/commands/Music/queue.js index 2d434183..a79e6772 100644 --- a/commands/Music/queue.js +++ b/commands/Music/queue.js @@ -169,7 +169,7 @@ function generateQueueEmbeds(interaction, queue) { queue.repeatMode === QueueRepeatMode.AUTOPLAY ? interaction.translate("music/nowplaying:AUTOPLAY") : queue.repeatMode === QueueRepeatMode.QUEUE ? interaction.translate("music/nowplaying:QUEUE") : queue.repeatMode === QueueRepeatMode.TRACK ? interaction.translate("music/nowplaying:TRACK") : interaction.translate("common:DISABLED") - }\`\n${interaction.translate("music/queue:DURATION")}: \`${interaction.client.convertTime(Date.now() + queue.totalTime, false, true, interaction.guild.data.language)}\`\n[${currentTrack.title}](${currentTrack.url})\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requestedBy}\n\n**${interaction.translate("music/queue:NEXT")}**\n${interaction.translate("music/queue:NO_QUEUE")}`) + }\`\n${interaction.translate("music/queue:DURATION")}: \`${interaction.client.functions.convertTime(Date.now() + queue.totalTime, false, true, interaction.guild.data.language)}\`\n[${currentTrack.title}](${currentTrack.url})\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requestedBy}\n\n**${interaction.translate("music/queue:NEXT")}**\n${interaction.translate("music/queue:NO_QUEUE")}`) .setTimestamp(); embeds.push(embed); @@ -191,7 +191,7 @@ function generateQueueEmbeds(interaction, queue) { queue.repeatMode === QueueRepeatMode.AUTOPLAY ? interaction.translate("music/nowplaying:AUTOPLAY") : queue.repeatMode === QueueRepeatMode.QUEUE ? interaction.translate("music/nowplaying:QUEUE") : queue.repeatMode === QueueRepeatMode.TRACK ? interaction.translate("music/nowplaying:TRACK") : interaction.translate("common:DISABLED") - }\`\n${interaction.translate("music/queue:DURATION")}: \`${interaction.client.convertTime(Date.now() + queue.node.streamTime, false, true, interaction.guild.data.language)}\`\n[${currentTrack.title}](${currentTrack.url})\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requestedBy}\n\n**${interaction.translate("music/queue:NEXT")}**\n${info}`) + }\`\n${interaction.translate("music/queue:DURATION")}: \`${interaction.client.functions.convertTime(Date.now() + queue.node.streamTime, false, true, interaction.guild.data.language)}\`\n[${currentTrack.title}](${currentTrack.url})\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requestedBy}\n\n**${interaction.translate("music/queue:NEXT")}**\n${info}`) .setTimestamp(); embeds.push(embed); } diff --git a/commands/Music/seek.js b/commands/Music/seek.js index 20a9c3fa..18b79e86 100644 --- a/commands/Music/seek.js +++ b/commands/Music/seek.js @@ -44,7 +44,7 @@ class Seek extends BaseCommand { queue.node.seek(time * 1000); interaction.success("music/seek:SUCCESS", { - time: `**${time}** ${client.getNoun(time, interaction.translate("misc:NOUNS:SECONDS:1"), interaction.translate("misc:NOUNS:SECONDS:2"), interaction.translate("misc:NOUNS:SECONDS:5"))}`, + time: `**${time}** ${client.functions.getNoun(time, interaction.translate("misc:NOUNS:SECONDS:1"), interaction.translate("misc:NOUNS:SECONDS:2"), interaction.translate("misc:NOUNS:SECONDS:5"))}`, }); } } diff --git a/commands/Owner/servers.js b/commands/Owner/servers.js index af07dbc9..f4be6742 100644 --- a/commands/Owner/servers.js +++ b/commands/Owner/servers.js @@ -47,10 +47,6 @@ class Servers extends BaseCommand { .setCustomId("servers_next_page") .setStyle(ButtonStyle.Primary) .setEmoji("➑️"), - new ButtonBuilder() - .setCustomId("servers_jump_page") - .setStyle(ButtonStyle.Secondary) - .setEmoji("↗️"), new ButtonBuilder() .setCustomId("servers_stop") .setStyle(ButtonStyle.Danger) @@ -90,37 +86,6 @@ class Servers extends BaseCommand { components: [row], }); } - } else if (i.customId === "servers_jump_page") { - i.deferUpdate(); - - const msg = await interaction.followUp({ - content: interaction.translate("misc:JUMP_TO_PAGE", { - length: embeds.length, - }), - fetchReply: true, - }); - - const filter = res => { - return res.author.id === interaction.user.id && !isNaN(res.content); - }; - - interaction.channel.awaitMessages({ filter, max: 1, time: (10 * 1000) }).then(collected => { - if (embeds[collected.first().content - 1]) { - currentPage = collected.first().content - 1; - interaction.editReply({ - content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`, - embeds: [embeds[currentPage]], - components: [row], - }); - - if (collected.first().deletable) collected.first().delete(); - if (msg.deletable) msg.delete(); - } else { - if (collected.first().deletable) collected.first().delete(); - if (msg.deletable) msg.delete(); - return; - } - }); } else if (i.customId === "servers_stop") { i.deferUpdate(); collector.stop(); @@ -155,7 +120,7 @@ function generateServersEmbeds(interaction, servers) { let j = i; k += 10; - const info = current.map(server => `${++j}. ${server.name} | ${server.memberCount} ${interaction.client.getNoun(server.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`).join("\n"); + const info = current.map(server => `${++j}. ${server.name} | ${server.memberCount} ${interaction.client.functions.getNoun(server.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`).join("\n"); const embed = new EmbedBuilder() .setColor(interaction.client.config.embed.color) diff --git a/dashboard/app.js b/dashboard/app.js index b58b403b..ede14cff 100644 --- a/dashboard/app.js +++ b/dashboard/app.js @@ -43,8 +43,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.printDate(date, null, req.locale); - req.convertTime = (time) => req.client.convertTime(time, "to", true, 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); } next(); }) diff --git a/events/Guild/guildCreate.js b/events/Guild/guildCreate.js index 057a87d8..cc6958cf 100644 --- a/events/Guild/guildCreate.js +++ b/events/Guild/guildCreate.js @@ -55,7 +55,7 @@ class GuildCreate extends BaseEvent { iconURL: guild.iconURL(), }) .setColor("#32CD32") - .setDescription(`Π—Π°ΡˆΡ‘Π» Π½Π° сСрвСр **${guild.name}**. На Π½Ρ‘ΠΌ **${users}** ${client.getNoun(users, client.translate("misc:NOUNS:USERS:1"), client.translate("misc:NOUNS:USERS:2"), client.translate("misc:NOUNS:USERS:5"))} ΠΈ **${bots}** ${client.getNoun(bots, client.translate("misc:NOUNS:BOTS:1"), client.translate("misc:NOUNS:BOTS:2"), client.translate("misc:NOUNS:BOTS:5"))}`); + .setDescription(`Π—Π°ΡˆΡ‘Π» Π½Π° сСрвСр **${guild.name}**. На Π½Ρ‘ΠΌ **${users}** ${client.functions.getNoun(users, client.translate("misc:NOUNS:USERS:1"), client.translate("misc:NOUNS:USERS:2"), client.translate("misc:NOUNS:USERS:5"))} ΠΈ **${bots}** ${client.functions.getNoun(bots, client.translate("misc:NOUNS:BOTS:1"), client.translate("misc:NOUNS:BOTS:2"), client.translate("misc:NOUNS:BOTS:5"))}`); client.channels.cache.get(client.config.support.logs).send({ embeds: [embed], }); diff --git a/events/Guild/guildMemberRemove.js b/events/Guild/guildMemberRemove.js index 26f45838..c6a9b716 100644 --- a/events/Guild/guildMemberRemove.js +++ b/events/Guild/guildMemberRemove.js @@ -90,7 +90,7 @@ class GuildMemberRemove extends BaseEvent { // Draw membercount ctx.font = "22px RubikMonoOne"; - ctx.fillText(`${member.guild.memberCount} ${client.getNoun(member.guild.memberCount, client.translate("misc:NOUNS:MEMBERS:1", null, member.guild.data.language), client.translate("misc:NOUNS:MEMBERS:2", null, member.guild.data.language), client.translate("misc:NOUNS:MEMBERS:5", null, member.guild.data.language))}`, 40, canvas.height - 35); + ctx.fillText(`${member.guild.memberCount} ${client.functions.getNoun(member.guild.memberCount, client.translate("misc:NOUNS:MEMBERS:1", null, member.guild.data.language), client.translate("misc:NOUNS:MEMBERS:2", null, member.guild.data.language), client.translate("misc:NOUNS:MEMBERS:5", null, member.guild.data.language))}`, 40, canvas.height - 35); // Draw # for discriminator ctx.fillStyle = "#FFFFFF"; diff --git a/events/ready.js b/events/ready.js index 505abcfd..cf8c7490 100644 --- a/events/ready.js +++ b/events/ready.js @@ -37,17 +37,14 @@ class Ready extends BaseEvent { const checkReminds = require("../helpers/checkReminds"); checkReminds.init(client); - const cleanup = require("../helpers/cleanup"); - cleanup.init(client); - if (client.config.dashboard.enabled) client.dashboard.init(client); const version = require("../package.json").version; const status = [ { name: "help", type: ActivityType.Watching }, - { name: `${commands.length} ${client.getNoun(commands.length, client.translate("misc:NOUNS:COMMANDS:1"), client.translate("misc:NOUNS:COMMANDS:2"), client.translate("misc:NOUNS:COMMANDS:5"))}`, type: ActivityType.Listening }, - { name: `${tServers} ${client.getNoun(tServers, client.translate("misc:NOUNS:SERVER:1"), client.translate("misc:NOUNS:SERVER:2"), client.translate("misc:NOUNS:SERVER:5"))}`, type: ActivityType.Watching }, - { name: `${tUsers} ${client.getNoun(tUsers, client.translate("misc:NOUNS:USERS:1"), client.translate("misc:NOUNS:USERS:2"), client.translate("misc:NOUNS:USERS:5"))}`, type: ActivityType.Watching }, + { name: `${commands.length} ${client.functions.getNoun(commands.length, client.translate("misc:NOUNS:COMMANDS:1"), client.translate("misc:NOUNS:COMMANDS:2"), client.translate("misc:NOUNS:COMMANDS:5"))}`, type: ActivityType.Listening }, + { name: `${tServers} ${client.functions.getNoun(tServers, client.translate("misc:NOUNS:SERVER:1"), client.translate("misc:NOUNS:SERVER:2"), client.translate("misc:NOUNS:SERVER:5"))}`, type: ActivityType.Watching }, + { name: `${tUsers} ${client.functions.getNoun(tUsers, client.translate("misc:NOUNS:USERS:1"), client.translate("misc:NOUNS:USERS:2"), client.translate("misc:NOUNS:USERS:5"))}`, type: ActivityType.Watching }, ]; let i = 0; diff --git a/helpers/autoUpdateDocs.js b/helpers/autoUpdateDocs.js index cb78b3c0..5e659bdd 100644 --- a/helpers/autoUpdateDocs.js +++ b/helpers/autoUpdateDocs.js @@ -14,7 +14,7 @@ module.exports.update = function (client) { if (!categories.includes(cmd.category)) categories.push(cmd.category); }); - let text = `# JaBa ΠΈΠΌΠ΅Π΅Ρ‚ **${commands.length} ${client.getNoun(commands.length, "ΠΊΠΎΠΌΠ°Π½Π΄Π°", "ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹", "ΠΊΠΎΠΌΠ°Π½Π΄")}** Π² **${categories.length} ${client.getNoun(categories.length, "ΠΊΠ°Ρ‚Π΅Π³ΠΎΡ€ΠΈΠΈ", "катСгориях", "катСгориях")}**! \n\n#### Π‘ΠΎΠ΄Π΅Ρ€ΠΆΠΈΠΌΠΎΠ΅ Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ \n**НазваниС**: НазваниС ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ \n**ОписаниС**: ОписаниС ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ \n**ИспользованиС**: ИспользованиС ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ( [] - ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ, () - Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ ) \n**Π Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΎ использованиС**: Π“Π΄Π΅ ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ \n\n`; + let text = `# JaBa ΠΈΠΌΠ΅Π΅Ρ‚ **${commands.length} ${client.functions.getNoun(commands.length, "ΠΊΠΎΠΌΠ°Π½Π΄Π°", "ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹", "ΠΊΠΎΠΌΠ°Π½Π΄")}** Π² **${categories.length} ${client.functions.getNoun(categories.length, "ΠΊΠ°Ρ‚Π΅Π³ΠΎΡ€ΠΈΠΈ", "катСгориях", "катСгориях")}**! \n\n#### Π‘ΠΎΠ΄Π΅Ρ€ΠΆΠΈΠΌΠΎΠ΅ Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ \n**НазваниС**: НазваниС ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ \n**ОписаниС**: ОписаниС ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ \n**ИспользованиС**: ИспользованиС ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ( [] - ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ, () - Π½Π΅ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ ) \n**Π Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΎ использованиС**: Π“Π΄Π΅ ΠΌΠΎΠΆΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ \n\n`; // categories.sort(function(a, b) { // const aCmdsSize = commands.filter(cmd => cmd.category === a).size; @@ -29,7 +29,7 @@ module.exports.update = function (client) { ]; const cmds = [...new Map(commands.filter(cmd => cmd.category === cat).map(v => [v.constructor.name, v])).values()]; - text += `### ${cat} (${cmds.length} ${client.getNoun(cmds.length, "ΠΊΠΎΠΌΠ°Π½Π΄Π°", "ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹", "ΠΊΠΎΠΌΠ°Π½Π΄")})\n\n`; + text += `### ${cat} (${cmds.length} ${client.functions.getNoun(cmds.length, "ΠΊΠΎΠΌΠ°Π½Π΄Π°", "ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹", "ΠΊΠΎΠΌΠ°Π½Π΄")})\n\n`; cmds.sort(function (a, b) { if (a.command.name < b.command.name) return -1; else return 1; diff --git a/helpers/birthdays.js b/helpers/birthdays.js index 022d51d5..d417d488 100644 --- a/helpers/birthdays.js +++ b/helpers/birthdays.js @@ -49,7 +49,7 @@ module.exports.init = async function (client) { value: client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", { name: user.username, user: user.id, - age: `**${age}** ${client.getNoun(age, client.translate("misc:NOUNS:AGE:1"), client.translate("misc:NOUNS:AGE:2"), client.translate("misc:NOUNS:AGE:5"))}`, + age: `**${age}** ${client.functions.getNoun(age, client.translate("misc:NOUNS:AGE:1"), client.translate("misc:NOUNS:AGE:2"), client.translate("misc:NOUNS:AGE:5"))}`, }), }, ]); diff --git a/helpers/extenders.js b/helpers/extenders.js index 8b40b2cb..8574ec58 100644 --- a/helpers/extenders.js +++ b/helpers/extenders.js @@ -15,14 +15,14 @@ BaseInteraction.prototype.replyT = function (key, args, options = {}) { else return this.reply({ content: string, ephemeral: options.ephemeral || false }); }; -BaseInteraction.prototype.error = function (key, args, options = {}) { - options.prefixEmoji = "error"; +BaseInteraction.prototype.success = function (key, args, options = {}) { + options.prefixEmoji = "success"; return this.replyT(key, args, options); }; -BaseInteraction.prototype.success = function (key, args, options = {}) { - options.prefixEmoji = "success"; +BaseInteraction.prototype.error = function (key, args, options = {}) { + options.prefixEmoji = "error"; return this.replyT(key, args, options); }; @@ -42,14 +42,14 @@ Message.prototype.replyT = function (key, args, options = {}) { else return this.reply({ content: string, allowedMentions: { repliedUser: options.mention ? true : false } }); }; -Message.prototype.error = function (key, args, options = {}) { - options.prefixEmoji = "error"; - - return this.replyT(key, args, options); -}; - Message.prototype.success = function (key, args, options = {}) { options.prefixEmoji = "success"; + return this.replyT(key, args, options); +}; + +Message.prototype.error = function (key, args, options = {}) { + options.prefixEmoji = "error"; + return this.replyT(key, args, options); }; \ No newline at end of file diff --git a/helpers/functions.js b/helpers/functions.js index 9e834672..baeead2e 100644 --- a/helpers/functions.js +++ b/helpers/functions.js @@ -1,4 +1,12 @@ const { PermissionsBitField, ChannelType } = require("discord.js"); +const moment = require("moment"); + +moment.relativeTimeThreshold("ss", 5); +moment.relativeTimeThreshold("s", 60); +moment.relativeTimeThreshold("m", 60); +moment.relativeTimeThreshold("h", 60); +moment.relativeTimeThreshold("d", 24); +moment.relativeTimeThreshold("M", 12); module.exports = { /** @@ -20,7 +28,7 @@ module.exports = { * @param {Function} callback * @returns {Promise} */ - async asyncForEach (collection, callback) { + async asyncForEach(collection, callback) { const allPromises = collection.map(async key => { await callback(key); }); @@ -77,4 +85,54 @@ module.exports = { return Math.floor(Math.random() * (max - min + 1) + min); }, + + /** + * Beautify date + * @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); + if (format === "" || format === null) format = languageData.defaultMomentFormat; + + return moment(new Date(date)) + .locale(languageData.moment) + .format(format); + }, + + /** + * Convert given time + * @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); + const m = moment(time).locale(languageData.moment); + + return (type ? m.toNow(noPrefix) : m.fromNow(noPrefix)); + }, + + /** + * Get noun for number + * @param {Number} number Number + * @param {String} one String for one + * @param {String} two String for two + * @param {String} five String for five + * @returns + */ + getNoun(number, one, two, five) { + let n = Math.abs(number); + n %= 100; + if (n >= 5 && n <= 20) return five; + n %= 10; + if (n === 1) return one; + if (n >= 2 && n <= 4) return two; + + return five; + }, }; \ No newline at end of file diff --git a/languages/ru-RU/general/boosters.json b/languages/ru-RU/general/boosters.json index bde2f20c..e596ac5d 100644 --- a/languages/ru-RU/general/boosters.json +++ b/languages/ru-RU/general/boosters.json @@ -3,5 +3,6 @@ "USAGE": "", "EXAMPLES": "boosters", "BOOSTERS_LIST": "Бписок бустСров", + "NO_BOOSTERS": "Бусты ΠΎΡ‚ΡΡƒΡ‚ΡΡ‚Π²ΡƒΡŽΡ‚", "BOOSTER_SINCE": "Буст с" } \ No newline at end of file diff --git a/languages/uk-UA/general/boosters.json b/languages/uk-UA/general/boosters.json index 728cfbcd..4018bae6 100644 --- a/languages/uk-UA/general/boosters.json +++ b/languages/uk-UA/general/boosters.json @@ -3,5 +3,6 @@ "USAGE": "", "EXAMPLES": "boosters", "BOOSTERS_LIST": "Бписок бустСрів", + "NO_BOOSTERS": "Бусти відсутні", "BOOSTER_SINCE": "Буст Π·" } \ No newline at end of file