diff --git a/commands/Economy/money.js b/commands/Economy/money.js index b6774512..af5a0302 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: member.user.discriminator === "0" ? member.user.username : member.user.tag, + user: client.functions.getUsername(member.user), }), iconURL: member.user.displayAvatarURL(), }) diff --git a/commands/Economy/pay.js b/commands/Economy/pay.js index e0cddc39..65fc8a05 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: member.user.discriminator === "0" ? member.user.username : member.user.tag, + user: client.functions.getUsername(member.user), amount: amount, date: Date.now(), type: "send", @@ -79,7 +79,7 @@ class Pay extends BaseCommand { data.memberData.transactions.push(info1); const info2 = { - user: member.user.discriminator === "0" ? member.user.username : member.user.tag, + user: client.functions.getUsername(member.user), amount: amount, date: Date.now(), type: "got", diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js index a65ee772..2933e106 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") : lover.discriminator === "0" ? lover.username : lover.tag), + value: (!userData.lover ? interaction.translate("common:NOT_DEFINED") : client.functions.getUsername(lover)), inline: true, }, { diff --git a/commands/General/report.js b/commands/General/report.js index af87e2d2..2eae75c4 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: member.user.discriminator === "0" ? member.user.username : member.user.tag, + user: client.functions.getUsername(member.user), }), iconURL: interaction.user.displayAvatarURL({ extension: "png", diff --git a/commands/General/suggest.js b/commands/General/suggest.js index edd9651a..8c22297b 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: interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag, + user: client.functions.getUsername(interaction.user), }), iconURL: interaction.member.displayAvatarURL(), }) diff --git a/commands/General/userinfo.js b/commands/General/userinfo.js index 74143807..0e2b1a6c 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: `${member.user.discriminator === "0" ? member.user.username : member.user.tag} (${member.id})`, + name: `${client.functions.getUsername(member.user)} (${member.id})`, iconURL: member.displayAvatarURL(), }) .setThumbnail(member.displayAvatarURL({ @@ -53,7 +53,7 @@ class Userinfo extends BaseCommand { .addFields([ { name: ":man: " + interaction.translate("common:USERNAME"), - value: member.user.discriminator === "0" ? member.user.username : member.user.tag, + value: client.functions.getUsername(member.user), inline: true, }, { diff --git a/commands/Moderation/clear.js b/commands/Moderation/clear.js index 8d90c6f9..d8473e24 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?.user.discriminator === "0" ? member?.user.username : member?.user.tag || user_id), + user: member && client.functions.getUsername(member.user) || user_id, }, { edit: true }); } else { interaction.replyT("moderation/clear:CLEARED", { diff --git a/commands/Moderation/warn.js b/commands/Moderation/warn.js index 4d13ad0b..f1694ad2 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: member.user.discriminator === "0" ? member.user.username : member.user.tag }).normalize("NFKD")); + .setTitle(interaction.translate("moderation/warn:MODAL_TITLE", { nickname: client.functions.getUsername(member.user) }).normalize("NFKD")); const reasonInput = new TextInputBuilder() .setCustomId("warn_reason") @@ -89,11 +89,11 @@ class Warn extends BaseCommand { .addFields([ { name: interaction.translate("common:USER"), - value: `\`${member.user.discriminator === "0" ? member.user.username : member.user.tag}\` (${member.user.toString()})`, + value: `\`${client.functions.getUsername(member.user)}\` (${member.user.toString()})`, }, { name: interaction.translate("common:MODERATOR"), - value: `\`${interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag}\` (${interaction.user.toString()})`, + value: `\`${client.functions.getUsername(interaction.user)}\` (${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: interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag, + moderator: client.functions.getUsername(interaction.user), server: interaction.guild.name, reason, }), @@ -125,7 +125,7 @@ class Warn extends BaseCommand { interaction.followUp({ content: interaction.translate("moderation/setwarns:AUTO_BAN", { - user: member.user.discriminator === "0" ? member.user.username : member.user.tag, + user: client.functions.getUsername(member.user), 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: interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag, + moderator: client.functions.getUsername(interaction.user), server: interaction.guild.name, reason, }), @@ -155,7 +155,7 @@ class Warn extends BaseCommand { interaction.followUp({ content: interaction.translate("moderation/setwarns:AUTO_KICK", { - user: member.user.discriminator === "0" ? member.user.username : member.user.tag, + user: client.functions.getUsername(member.user), 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: member.user.discriminator === "0" ? member.user.username : member.user.tag, + user: client.functions.getUsername(member.user), server: interaction.guild.name, - moderator: interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag, + moderator: client.functions.getUsername(interaction.user), reason, }), }); diff --git a/events/CommandHandler.js b/events/CommandHandler.js index 2c9224ae..de46f5f0 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 ${interaction.user.discriminator === "0" ? interaction.user.username : interaction.user.tag} 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 ${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"); return command.execute(client, interaction, data); } diff --git a/events/Guild/guildMemberRemove.js b/events/Guild/guildMemberRemove.js index 00b5b85a..194b05f5 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, member.user.discriminator === "0" ? member.user.username : member.user.tag) + .replace(/{user}/g, client.functions.getUsername(member.user)) .replace(/{server}/g, member.guild.name) .replace(/{membercount}/g, member.guild.memberCount); @@ -96,7 +96,7 @@ class GuildMemberRemove extends BaseEvent { // Draw # for discriminator ctx.fillStyle = "#FFFFFF"; ctx.font = "70px RubikMonoOne"; - ctx.fillText("#", canvas.width - 690, canvas.height - 165); + ctx.fillText(member.user.discriminator === "0" ? "" : "#", canvas.width - 690, canvas.height - 165); // Draw title ctx.font = "45px RubikMonoOne"; diff --git a/events/MessageHandler.js b/events/MessageHandler.js index 5fee2e78..6f62785a 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: msg.author.discriminator === "0" ? msg.author.username : msg.author.tag, + user: client.functions.getUsername(msg.author), }), 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: message.author.discriminator === "0" ? message.author.username : message.author.tag }), + text: message.translate("misc:QUOTE_FOOTER", { user: client.functions.getUsername(message.author) }), }) .setColor(client.config.embed.color) .setTimestamp(msg.createdTimestamp); @@ -111,11 +111,12 @@ class MessageCreate extends BaseEvent { }, { mention: true }); } - message.mentions.users.forEach(async (u) => { + message.mentions.users.forEach(async u => { const userData = await client.findOrCreateUser({ id: u.id, }); - if (userData.afk) message.replyT("general/afk:IS_AFK", { user: u.discriminator === "0" ? u.username : u.tag, reason: userData.afk }, { ephemeral: true }); + + if (userData.afk) message.replyT("general/afk:IS_AFK", { user: client.functions.getUsername(u), reason: userData.afk }, { ephemeral: true }); }); } diff --git a/events/ready.js b/events/ready.js index d9f00bba..8518ef1d 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.user.discriminator === "0" ? client.user.username : client.user.tag}, ready to serve ${tUsers} members in ${tServers} servers.`, "ready"); + client.logger.log(`${client.functions.getUsername(client.user)}, 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/functions.js b/helpers/functions.js index a41deb99..0e328b80 100644 --- a/helpers/functions.js +++ b/helpers/functions.js @@ -37,7 +37,7 @@ module.exports = { }, /** - * Sort array by key + * Sorts array by key * @param {Array} array Array to sort * @param {Number} key Key * @returns {Array} Sorted array @@ -51,7 +51,7 @@ module.exports = { }, /** - * Shuffles array + * Shuffles the array * @param {*} pArray Array to shuffle * @returns {Array} Shuffled array */ @@ -104,7 +104,7 @@ module.exports = { }, /** - * Convert given time + * Converts given time * @param {import("../base/JaBa")} client Discord client * @param {String} time Time * @param {Boolean} type Type (To now = true or from now = false) @@ -120,7 +120,7 @@ module.exports = { }, /** - * Get noun for number + * Get a noun for number * @param {Number} number Number * @param {String} one String for one * @param {String} two String for two @@ -137,4 +137,13 @@ module.exports = { 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 be982f31..05e8f14e 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: opponent.discriminator === "0" ? opponent.username : opponent.tag, + user: client.functions.getUsername(opponent), })) .setAuthor({ - name: user.discriminator === "0" ? user.username : user.tag, + name: client.functions.getUsername(user), 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: user.discriminator === "0" ? user.username : user.tag, + name: client.functions.getUsername(user), 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: user.discriminator === "0" ? user.username : user.tag, + name: client.functions.getUsername(user), iconURL: user.displayAvatarURL(), }) .setColor(options.timeoutEmbedColor || "#C90000")