2022-08-15 17:26:11 +02:00
|
|
|
import db from '../../models/index.js';
|
|
|
|
const guildBlacklist = db.guildBlacklist;
|
2022-08-28 17:04:11 +02:00
|
|
|
import { EmbedBuilder } from 'discord.js';
|
2022-08-15 17:26:11 +02:00
|
|
|
|
2022-08-17 16:22:49 +02:00
|
|
|
const { statusChannel, NODE_ENV } = process.env;
|
2022-08-15 17:26:11 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'guildCreate',
|
|
|
|
async execute(guild, client) {
|
|
|
|
const guildOwner = await client.users.fetch(guild.ownerId);
|
|
|
|
|
2023-04-04 00:45:43 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-08-15 17:26:11 +02:00
|
|
|
console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guildOwner.username}\nOwner ID: ${guild.ownerId}`);
|
|
|
|
|
|
|
|
const blacklist = await guildBlacklist.findOne({ where: { guildID:guild.id } });
|
|
|
|
|
|
|
|
if (blacklist) {
|
|
|
|
guild.leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If stats channel settings exist, send bot stats to it
|
2022-08-17 16:22:49 +02:00
|
|
|
if (statusChannel && NODE_ENV !== 'development') {
|
2022-08-15 17:26:11 +02:00
|
|
|
const channel = client.channels.resolve(statusChannel);
|
|
|
|
const botCount = guild.members.cache.filter(member => member.user.bot).size;
|
|
|
|
console.log(guild.memberCount);
|
2022-08-28 17:04:11 +02:00
|
|
|
const addEmbed = new EmbedBuilder()
|
2022-08-15 17:26:11 +02:00
|
|
|
.setColor('#52e80d')
|
|
|
|
.setTitle('New boiz in town')
|
|
|
|
.setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4')
|
|
|
|
.setThumbnail(guild.iconURL())
|
2022-08-28 17:04:11 +02:00
|
|
|
.addFields(
|
|
|
|
{ name: 'Guild', value: `${guild.name} (${guild.id})` },
|
|
|
|
{ name: 'Total number of members', value: guild.memberCount.toString(), inline: true },
|
|
|
|
{ name: 'Number of users', value: (guild.memberCount - botCount).toString(), inline: true },
|
|
|
|
{ name: 'Number of bots', value: botCount.toString(), inline: true },
|
|
|
|
{ name: 'Owner', value: `${guildOwner.username} (${guild.ownerId})`, inline: true },
|
|
|
|
)
|
2022-08-15 17:26:11 +02:00
|
|
|
.setFooter({ text: `I'm now in ${client.guilds.cache.size} servers!` })
|
|
|
|
.setTimestamp();
|
|
|
|
|
|
|
|
if (blacklist) {
|
|
|
|
return channel.send(`${guildOwner.username} (${guild.ownerId}) tried to add me to their guild while being blacklisted!\n${guild.name} (${guild.id})`);
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.send({ embeds: [addEmbed] });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|