From f29d72177187364798eae3da9b657cc8f56f2796 Mon Sep 17 00:00:00 2001 From: Supositware Date: Tue, 4 Apr 2023 00:45:43 +0200 Subject: [PATCH] Let user opt out of join/leave event --- events/client/guildCreate.js | 12 ++++++++++++ events/client/guildDelete.js | 12 ++++++++++++ events/client/guildMemberAdd.js | 4 ++++ events/client/guildMemberRemove.js | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/events/client/guildCreate.js b/events/client/guildCreate.js index a0b8ae8..bd77fbf 100644 --- a/events/client/guildCreate.js +++ b/events/client/guildCreate.js @@ -9,6 +9,18 @@ export default { async execute(guild, client) { const guildOwner = await client.users.fetch(guild.ownerId); + const isOptOut = await db.optout.findOne({ where: { userID: guildOwner.id } }); + + if (isOptOut) { + console.log(`A guild\n${guild.memberCount} users`); + if (statusChannel && NODE_ENV !== 'development') { + const channel = client.channels.resolve(statusChannel); + + channel.send({ content: `An anonymous guild just added me.\nI'm now in ${client.guilds.cache.size} servers!` }); + } + return; + } + console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guildOwner.username}\nOwner ID: ${guild.ownerId}`); const blacklist = await guildBlacklist.findOne({ where: { guildID:guild.id } }); diff --git a/events/client/guildDelete.js b/events/client/guildDelete.js index b9297d9..88f88ba 100644 --- a/events/client/guildDelete.js +++ b/events/client/guildDelete.js @@ -9,6 +9,18 @@ export default { async execute(guild, client) { const guildOwner = await client.users.fetch(guild.ownerId); + const isOptOut = await db.optout.findOne({ where: { userID: guildOwner.id } }); + + if (isOptOut) { + console.log(`***BOT KICKED***A guild\n${guild.memberCount} users\n***BOT KICKED***`); + if (statusChannel && NODE_ENV !== 'development') { + const channel = client.channels.resolve(statusChannel); + + channel.send({ content: `An anonymous guild just removed me.\nI'm now in ${client.guilds.cache.size} servers!` }); + } + return; + } + console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guildOwner.username}\nOwner ID: ${guild.ownerId}\n***BOT KICKED***`); const blacklist = await guildBlacklist.findOne({ where: { guildID:guild.id } }); diff --git a/events/client/guildMemberAdd.js b/events/client/guildMemberAdd.js index b06c6f8..b20bbc2 100644 --- a/events/client/guildMemberAdd.js +++ b/events/client/guildMemberAdd.js @@ -4,6 +4,10 @@ import { rand } from '../../utils/rand.js'; export default { name: 'guildMemberAdd', async execute(member, client) { + const isOptOut = await db.optout.findOne({ where: { userID: member.user.id } }); + + if (isOptOut) return; + const join = await db.joinChannel.findOne({ where: { guildID: member.guild.id } }); if (join) { diff --git a/events/client/guildMemberRemove.js b/events/client/guildMemberRemove.js index 141c5d7..a76afc9 100644 --- a/events/client/guildMemberRemove.js +++ b/events/client/guildMemberRemove.js @@ -4,6 +4,10 @@ import { rand } from '../../utils/rand.js'; export default { name: 'guildMemberRemove', async execute(member, client) { + const isOptOut = await db.optout.findOne({ where: { userID: member.user.id } }); + + if (isOptOut) return; + const leave = await db.leaveChannel.findOne({ where: { guildID: member.guild.id } }); if (leave) {