From ba08a370236b1a02290ebed683a9b3409b461fab Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:29:48 +1100 Subject: [PATCH] Move server join date from guildMemberRemove to guildBanAdd --- src/client.ts | 1 + src/events/guildBanAdd.ts | 5 ++++- src/events/guildMemberRemove.ts | 6 ++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client.ts b/src/client.ts index a37e197..c1bfd3e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -43,6 +43,7 @@ export default class TClient extends Discord.Client { public ytChannels: YouTubeChannelsSvc = new YouTubeChannelsSvc(); public repeatedMessages: IRepeatedMessages = {}; public crosspostSpam: ICrosspostSpam = {}; + public memberJoinDates: Map = new Map(); constructor() { super({ diff --git a/src/events/guildBanAdd.ts b/src/events/guildBanAdd.ts index 161061e..40a32aa 100644 --- a/src/events/guildBanAdd.ts +++ b/src/events/guildBanAdd.ts @@ -6,14 +6,17 @@ export default class GuildBanAdd { const banLog = (await member.guild.fetchAuditLogs({ limit: 1, type: Discord.AuditLogEvent.MemberBanAdd })).entries.first(); if (!banLog) return console.log(`Member was banned from ${member.guild.name} but no audit log for this member.`) const {executor, target, reason } = banLog; + const members_joindate = client.memberJoinDates.get(member.user.id); if (target.id === member.user.id) { const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048})) .setTitle(`Member Banned: ${target.username}`).addFields( {name: '🔹 Moderator', value: `<@${executor.id}>\n\`${executor.id}\``}, + {name: '🔹 Server Join Date', value: members_joindate ? `\n` : '*Unknown timestamp*'}, {name: '🔹 Reason', value: reason === null ? 'Reason unspecified': reason} ); if (!await client.userLevels.fetchUser(member.user.id)) embed.setFooter({text: 'Rank data has been wiped.'}); - (client.channels.resolve(client.config.dcServer.channels.logs) as Discord.TextChannel).send({embeds: [embed]}) + (client.channels.resolve(client.config.dcServer.channels.logs) as Discord.TextChannel).send({embeds: [embed]}); + client.memberJoinDates.delete(member.user.id); } else console.log(`User was banned from "${member.guild.name}" but no audit log could be fetched.`) } } diff --git a/src/events/guildMemberRemove.ts b/src/events/guildMemberRemove.ts index f354d24..47ed70a 100644 --- a/src/events/guildMemberRemove.ts +++ b/src/events/guildMemberRemove.ts @@ -4,10 +4,8 @@ export default class GuildMemberRemove { static async run(client:TClient, member:Discord.GuildMember) { if (!client.config.botSwitches.logs) return; if (!member.joinedTimestamp || member.guild?.id != client.config.dcServer.id) return; - if (client.guilds.cache.get(client.config.dcServer.id).bans.cache.has(member.id)) { - (client.channels.resolve(client.config.dcServer.channels.logs) as Discord.TextChannel).send(`**${member.user.username}**'s join date is `) - return await client.userLevels.deleteUser(member.id); - }; + client.memberJoinDates.set(member.user.id, `${Math.round(member.joinedTimestamp/1000)}`); + if (client.guilds.cache.get(client.config.dcServer.id).bans.cache.has(member.id)) return await client.userLevels.deleteUser(member.id); let isBot = 'Bot'; if (!member.user.bot) isBot = 'Member'; const levelData = await client.userLevels.fetchUser(member.id);