From 2b1bf5d1c2ec533d9e873b61f5ae34c594776ec8 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Mon, 25 Mar 2024 22:23:02 +1100 Subject: [PATCH] Remove old code and rename variable --- src/events/guildMemberAdd.ts | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/events/guildMemberAdd.ts b/src/events/guildMemberAdd.ts index bed63e9..025bf4f 100644 --- a/src/events/guildMemberAdd.ts +++ b/src/events/guildMemberAdd.ts @@ -3,35 +3,24 @@ import TClient from '../client.js'; export default class GuildMemberAdd { static async run(client:TClient, member:Discord.GuildMember){ if (member.partial || member.guild?.id != client.config.dcServer.id) return; - const index = member.guild.memberCount; - /* const suffix = (index=>{ - const numbers = index.toString().split('').reverse(); // eg 1850 --> [0,5,8,1] - if (numbers[1] === '1') return 'th'; // this is some -teen - else { - if (numbers[0] === '1') return 'st'; - else if (numbers[0] === '2') return 'nd'; - else if (numbers[0] === '3') return 'rd'; - else return 'th'; - } - })(index); */ - - const suffix = {// Trial run, just discovered Intl.PluralRules this morning (as of March 24th) when I was browsing MDN Docs. + const memberCount = member.guild.memberCount; + const suffix = { one: 'st', two: 'nd', few: 'rd', other: 'th' - }[new Intl.PluralRules('en', {type: 'ordinal'}).select(index)]; + }[new Intl.PluralRules('en', {type: 'ordinal'}).select(memberCount)]; let isBot = 'Bot'; if (!member.user.bot) isBot = 'Member'; if (!client.config.botSwitches.logs) return; - (client.channels.resolve(client.config.dcServer.channels.welcome) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setThumbnail(member.user.displayAvatarURL({size: 2048}) || member.user.defaultAvatarURL).setTitle(`Welcome to ${member.guild.name}, ${member.user.username}!`).setFooter({text: `${index}${suffix} member`})]}); + (client.channels.resolve(client.config.dcServer.channels.welcome) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setThumbnail(member.user.displayAvatarURL({size: 2048}) || member.user.defaultAvatarURL).setTitle(`Welcome to ${member.guild.name}, ${member.user.username}!`).setFooter({text: `${memberCount}${suffix} member`})]}); const newInvites = await member.guild.invites.fetch(); const usedInvite = newInvites.find((inv:Discord.Invite)=>client.invites.get(inv.code)?.uses < inv.uses); newInvites.forEach((inv:Discord.Invite)=>client.invites.set(inv.code,{uses: inv.uses, creator: inv.inviterId, channel: inv.channel.name})); (client.channels.resolve(client.config.dcServer.channels.bot_log) as Discord.TextChannel).send({embeds: [ - new client.embed().setColor(client.config.embedColorGreen).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048})).setTitle(`${isBot} Joined: ${member.user.username}`).setFooter({text: `Total members: ${index}${suffix} | ID: ${member.user.id}`}).addFields( + new client.embed().setColor(client.config.embedColorGreen).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048})).setTitle(`${isBot} Joined: ${member.user.username}`).setFooter({text: `Total members: ${memberCount}${suffix} | ID: ${member.user.id}`}).addFields( {name: '🔹 Account Creation Date', value: `\n`}, {name: '🔹 Invite Data:', value: usedInvite ? `Invite: \`${usedInvite.code}\`\nCreated by: **${usedInvite.inviter?.username}**\nChannel: **#${usedInvite.channel.name}**` : 'No invite data could be fetched.'} )]});