From d0aa4c82fc345d4f33693f83a4d59a13001b7800 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Thu, 26 Dec 2019 17:27:51 +0100 Subject: [PATCH] Remove any discord invite --- event/listeners/guildMemberAdd.js | 15 +++++++++++++-- event/listeners/guildMemberRemove.js | 13 +++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/event/listeners/guildMemberAdd.js b/event/listeners/guildMemberAdd.js index 21012891..f8aee88c 100644 --- a/event/listeners/guildMemberAdd.js +++ b/event/listeners/guildMemberAdd.js @@ -15,6 +15,7 @@ class guildMemberAddListener extends Listener { guild.setNickname('fart piss'); } + const join = await joinChannel.findOne({where: {guildID: guild.guild.id}}); if (join) { @@ -22,8 +23,18 @@ class guildMemberAddListener extends Listener { let welcomeMessage = join.get('message'); - welcomeMessage = welcomeMessage.replace(/\[member\]/, guild.user.username); - welcomeMessage = welcomeMessage.replace(/\[memberPing\]/, guild.user); + let invite = new RegExp(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g); + + + let username = guild.user.username; + let user = guild.user; + if (guild.guild.member(guild.user).nickname.match(invite)) { + username = username.replace(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g, '[REDACTED]'); + user = username; + } + + welcomeMessage = welcomeMessage.replace(/\[member\]/, username); + welcomeMessage = welcomeMessage.replace(/\[memberPing\]/, user); welcomeMessage = welcomeMessage.replace(/\[server\]/, guild.guild.name); let attach; diff --git a/event/listeners/guildMemberRemove.js b/event/listeners/guildMemberRemove.js index b8b6d047..d2de78b8 100644 --- a/event/listeners/guildMemberRemove.js +++ b/event/listeners/guildMemberRemove.js @@ -17,8 +17,17 @@ class guildMemberRemoveListener extends Listener { let byeMessage = leave.get('message'); - byeMessage = byeMessage.replace(/\[member\]/, guild.user.username); - byeMessage = byeMessage.replace(/\[memberPing\]/, guild.user); + let invite = new RegExp(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g); + + let username = guild.user.username; + let user = guild.user; + if (guild.guild.member(guild.user).nickname.match(invite)) { + username = username.replace(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g, '[REDACTED]'); + user = username; + } + + byeMessage = byeMessage.replace(/\[member\]/, username); + byeMessage = byeMessage.replace(/\[memberPing\]/, user); byeMessage = byeMessage.replace(/\[server\]/, guild.guild.name); let attach;