getUsername function

This commit is contained in:
Jonny_Bro (Nikita) 2023-07-02 21:02:55 +05:00
parent 55a4734926
commit 76e8d16eb1
14 changed files with 44 additions and 34 deletions

View file

@ -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(),
})

View file

@ -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",

View file

@ -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,
},
{

View file

@ -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",

View file

@ -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(),
})

View file

@ -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,
},
{

View file

@ -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", {

View file

@ -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,
}),
});

View file

@ -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);
}

View file

@ -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";

View file

@ -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 });
});
}

View file

@ -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");

View file

@ -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;
},
};

View file

@ -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")