diff --git a/commands/Economy/money.js b/commands/Economy/money.js index af5a0302..7d9b800e 100644 --- a/commands/Economy/money.js +++ b/commands/Economy/money.js @@ -64,7 +64,7 @@ class Money extends BaseCommand { const embed = new EmbedBuilder() .setAuthor({ name: interaction.translate("economy/money:TITLE", { - user: client.functions.getUsername(member.user), + user: member.user.getUsername(), }), iconURL: member.user.displayAvatarURL(), }) diff --git a/commands/Economy/pay.js b/commands/Economy/pay.js index 65fc8a05..f19f6b26 100644 --- a/commands/Economy/pay.js +++ b/commands/Economy/pay.js @@ -71,7 +71,7 @@ class Pay extends BaseCommand { await memberData.save(); const info1 = { - user: client.functions.getUsername(member.user), + user: member.user.getUsername(), amount: amount, date: Date.now(), type: "send", @@ -79,7 +79,7 @@ class Pay extends BaseCommand { data.memberData.transactions.push(info1); const info2 = { - user: client.functions.getUsername(member.user), + user: member.user.getUsername(), amount: amount, date: Date.now(), type: "got", diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index 2933e106..9ca4a71c 100644 --- a/commands/Economy/profile.js +++ b/commands/Economy/profile.js @@ -127,7 +127,7 @@ class Profile extends BaseCommand { }, { name: interaction.translate("economy/profile:LOVER"), - value: (!userData.lover ? interaction.translate("common:NOT_DEFINED") : client.functions.getUsername(lover)), + value: (!userData.lover ? interaction.translate("common:NOT_DEFINED") : lover.getUsername()), inline: true, }, { diff --git a/commands/General/report.js b/commands/General/report.js index 2eae75c4..2ee0d952 100644 --- a/commands/General/report.js +++ b/commands/General/report.js @@ -60,7 +60,7 @@ class Report extends BaseCommand { const embed = new EmbedBuilder() .setAuthor({ name: interaction.translate("general/report:TITLE", { - user: client.functions.getUsername(member.user), + user: member.user.getUsername(), }), iconURL: interaction.user.displayAvatarURL({ extension: "png", diff --git a/commands/General/suggest.js b/commands/General/suggest.js index 8c22297b..be3da7f3 100644 --- a/commands/General/suggest.js +++ b/commands/General/suggest.js @@ -50,7 +50,7 @@ class Suggest extends BaseCommand { const embed = new EmbedBuilder() .setAuthor({ name: interaction.translate("general/suggest:TITLE", { - user: client.functions.getUsername(interaction.user), + user: interaction.user.getUsername(), }), iconURL: interaction.member.displayAvatarURL(), }) diff --git a/commands/General/userinfo.js b/commands/General/userinfo.js index 0e2b1a6c..ac17915b 100644 --- a/commands/General/userinfo.js +++ b/commands/General/userinfo.js @@ -44,7 +44,7 @@ class Userinfo extends BaseCommand { const member = interaction.options.getMember("user") || interaction.member; const embed = new EmbedBuilder() .setAuthor({ - name: `${client.functions.getUsername(member.user)} (${member.id})`, + name: `${member.user.getUsername()} (${member.id})`, iconURL: member.displayAvatarURL(), }) .setThumbnail(member.displayAvatarURL({ @@ -53,7 +53,7 @@ class Userinfo extends BaseCommand { .addFields([ { name: ":man: " + interaction.translate("common:USERNAME"), - value: client.functions.getUsername(member.user), + value: member.user.getUsername(), inline: true, }, { diff --git a/commands/Moderation/clear.js b/commands/Moderation/clear.js index d8473e24..445469fb 100644 --- a/commands/Moderation/clear.js +++ b/commands/Moderation/clear.js @@ -137,7 +137,7 @@ class Clear extends BaseCommand { if (member || user_id) { interaction.replyT("moderation/clear:CLEARED_MEMBER", { 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 && client.functions.getUsername(member.user) || user_id, + user: member && member.user.getUsername() || user_id, }, { edit: true }); } else { interaction.replyT("moderation/clear:CLEARED", { diff --git a/commands/Moderation/warn.js b/commands/Moderation/warn.js index f1694ad2..9b56df76 100644 --- a/commands/Moderation/warn.js +++ b/commands/Moderation/warn.js @@ -47,7 +47,7 @@ class Warn extends BaseCommand { const modal = new ModalBuilder() .setCustomId("warn_modal") - .setTitle(interaction.translate("moderation/warn:MODAL_TITLE", { nickname: client.functions.getUsername(member.user) }).normalize("NFKD")); + .setTitle(interaction.translate("moderation/warn:MODAL_TITLE", { nickname: member.user.getUsername() }).normalize("NFKD")); const reasonInput = new TextInputBuilder() .setCustomId("warn_reason") @@ -89,11 +89,11 @@ class Warn extends BaseCommand { .addFields([ { name: interaction.translate("common:USER"), - value: `\`${client.functions.getUsername(member.user)}\` (${member.user.toString()})`, + value: `\`${member.user.getUsername()}\` (${member.user.toString()})`, }, { name: interaction.translate("common:MODERATOR"), - value: `\`${client.functions.getUsername(interaction.user)}\` (${interaction.user.toString()})`, + value: `\`${interaction.user.getUsername()}\` (${interaction.user.toString()})`, }, { name: interaction.translate("common:REASON"), @@ -107,7 +107,7 @@ class Warn extends BaseCommand { member.send({ content: interaction.translate("moderation/ban:BANNED_DM", { user: member.user, - moderator: client.functions.getUsername(interaction.user), + moderator: interaction.user.getUsername(), server: interaction.guild.name, reason, }), @@ -125,7 +125,7 @@ class Warn extends BaseCommand { interaction.followUp({ content: interaction.translate("moderation/setwarns:AUTO_BAN", { - user: client.functions.getUsername(member.user), + user: member.user.getUsername(), count: `${banCount} ${client.functions.getNoun(banCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`, }), }); @@ -137,7 +137,7 @@ class Warn extends BaseCommand { member.send({ content: interaction.translate("moderation/kick:KICKED_DM", { user: member.user, - moderator: client.functions.getUsername(interaction.user), + moderator: interaction.user.getUsername(), server: interaction.guild.name, reason, }), @@ -155,7 +155,7 @@ class Warn extends BaseCommand { interaction.followUp({ content: interaction.translate("moderation/setwarns:AUTO_KICK", { - user: client.functions.getUsername(member.user), + user: member.user.getUsername(), count: `${kickCount} ${client.functions.getNoun(kickCount, interaction.translate("misc:NOUNS:WARNS:1"), interaction.translate("misc:NOUNS:WARNS:2"), interaction.translate("misc:NOUNS:WARNS:5"))}`, }), }); @@ -164,9 +164,9 @@ class Warn extends BaseCommand { */ member.send({ content: interaction.translate("moderation/warn:WARNED_DM", { - user: client.functions.getUsername(member.user), + user: member.user.getUsername(), server: interaction.guild.name, - moderator: client.functions.getUsername(interaction.user), + moderator: interaction.user.getUsername(), reason, }), }); diff --git a/events/CommandHandler.js b/events/CommandHandler.js index de46f5f0..f18a8064 100644 --- a/events/CommandHandler.js +++ b/events/CommandHandler.js @@ -55,7 +55,7 @@ class CommandHandler extends BaseEvent { interaction.user.send(args); } - client.logger.log(`User ${client.functions.getUsername(interaction.user)} used ${command.command.name} in ${interaction.guild ? interaction.guild.name : "DM"} with arguments: ${interaction.options.data.length > 0 ? interaction.options.data.map(arg => { return `${arg.name}: ${arg.value}`; }).join(", ") : "no args"}`, "cmd"); + client.logger.log(`User ${interaction.user.getUsername()} used ${command.command.name} in ${interaction.guild ? interaction.guild.name : "DM"} with arguments: ${interaction.options.data.length > 0 ? interaction.options.data.map(arg => { return `${arg.name}: ${arg.value}`; }).join(", ") : "no args"}`, "cmd"); return command.execute(client, interaction, data); } diff --git a/events/Guild/guildMemberRemove.js b/events/Guild/guildMemberRemove.js index 194b05f5..fd5f59e8 100644 --- a/events/Guild/guildMemberRemove.js +++ b/events/Guild/guildMemberRemove.js @@ -41,7 +41,7 @@ class GuildMemberRemove extends BaseEvent { if (channel) { const message = guildData.plugins.goodbye.message - .replace(/{user}/g, client.functions.getUsername(member.user)) + .replace(/{user}/g, member.user.getUsername()) .replace(/{server}/g, member.guild.name) .replace(/{membercount}/g, member.guild.memberCount); diff --git a/events/MessageHandler.js b/events/MessageHandler.js index 6f62785a..3a633438 100644 --- a/events/MessageHandler.js +++ b/events/MessageHandler.js @@ -49,7 +49,7 @@ class MessageCreate extends BaseEvent { const embed = new EmbedBuilder() .setAuthor({ name: message.translate("misc:QUOTE_TITLE", { - user: client.functions.getUsername(msg.author), + user: msg.author.getUsername(), }), iconURL: "https://wynem.com/assets/images/icons/quote.webp", }) @@ -64,7 +64,7 @@ class MessageCreate extends BaseEvent { }, ]) .setFooter({ - text: message.translate("misc:QUOTE_FOOTER", { user: client.functions.getUsername(message.author) }), + text: message.translate("misc:QUOTE_FOOTER", { user: message.author.getUsername() }), }) .setColor(client.config.embed.color) .setTimestamp(msg.createdTimestamp); @@ -116,7 +116,7 @@ class MessageCreate extends BaseEvent { id: u.id, }); - if (userData.afk) message.replyT("general/afk:IS_AFK", { user: client.functions.getUsername(u), reason: userData.afk }, { ephemeral: true }); + if (userData.afk) message.replyT("general/afk:IS_AFK", { user: u.getUsername(), reason: userData.afk }, { ephemeral: true }); }); } diff --git a/events/ready.js b/events/ready.js index 8518ef1d..c39be126 100644 --- a/events/ready.js +++ b/events/ready.js @@ -32,7 +32,7 @@ class Ready extends BaseEvent { if (client.config.dashboard.enabled) await client.dashboard.load(client); client.logger.log(`Loaded a total of ${commands.length} command(s).`, "ready"); - client.logger.log(`${client.functions.getUsername(client.user)}, ready to serve ${tUsers} members in ${tServers} servers.`, "ready"); + client.logger.log(`${client.user.getUsername()}, ready to serve ${tUsers} members in ${tServers} servers.`, "ready"); client.logger.log(`Invite Link: ${client.generateInvite({ scopes: ["bot", "applications.commands"], permissions: [ PermissionsBitField.Flags.Administrator ] })}`, "ready"); console.timeEnd("botReady"); diff --git a/helpers/extenders.js b/helpers/extenders.js index 8574ec58..bfb76961 100644 --- a/helpers/extenders.js +++ b/helpers/extenders.js @@ -1,4 +1,8 @@ -const { Message, BaseInteraction } = require("discord.js"); +const { Message, BaseInteraction, User } = require("discord.js"); + +User.prototype.getUsername = function () { + return this.discriminator === "0" ? this.username : this.tag; +}; BaseInteraction.prototype.translate = function (key, args) { const language = this.client.translations.get(this.guild ? (this.guild.data ? this.guild.data.language : "ru-RU") : "ru-RU"); diff --git a/helpers/functions.js b/helpers/functions.js index 0e328b80..9aa8c8e7 100644 --- a/helpers/functions.js +++ b/helpers/functions.js @@ -132,18 +132,10 @@ module.exports = { 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; }, - - /** - * Returns just a username if user has a new username, else returns user's tag - * @param {import("discord.js").User} user Number - * @returns - */ - getUsername(user) { - return user.discriminator === "0" ? user.username : user.tag; - }, }; \ No newline at end of file diff --git a/helpers/tictactoe.js b/helpers/tictactoe.js index 05e8f14e..018504f1 100644 --- a/helpers/tictactoe.js +++ b/helpers/tictactoe.js @@ -69,10 +69,10 @@ async function tictactoe(interaction, options = {}) { const acceptEmbed = new EmbedBuilder() .setTitle(interaction.translate("fun/tictactoe:REQUEST_WAIT", { - user: client.functions.getUsername(opponent), + user: opponent.getUsername(), })) .setAuthor({ - name: client.functions.getUsername(user), + name: user.getUsername(), iconURL: user.displayAvatarURL(), }) .setColor(options.embedColor || "#075FFF") @@ -832,7 +832,7 @@ async function tictactoe(interaction, options = {}) { const embed = new EmbedBuilder() .setTitle(interaction.translate("fun/tictactoe:NO_ANSWER_TITLE")) .setAuthor({ - name: client.functions.getUsername(user), + name: user.getUsername(), iconURL: user.displayAvatarURL(), }) .setColor(options.timeoutEmbedColor || "#C90000") @@ -851,7 +851,7 @@ async function tictactoe(interaction, options = {}) { const embed = new EmbedBuilder() .setTitle(interaction.translate("fun/tictactoe:CANCELED")) .setAuthor({ - name: client.functions.getUsername(user), + name: user.getUsername(), iconURL: user.displayAvatarURL(), }) .setColor(options.timeoutEmbedColor || "#C90000")