- Fetch invites every 5 minutes
- Add fail-safe to sending join messages (Don't want that happening again)
This commit is contained in:
parent
24ce1d2e96
commit
795d75655c
37
index.js
37
index.js
|
@ -41,23 +41,28 @@ client.on('ready', async () => {
|
||||||
client.invites = [];
|
client.invites = [];
|
||||||
// Update Invites
|
// Update Invites
|
||||||
console.log(`${colors.cyan("[INFO]")} Fetching Invites...`);
|
console.log(`${colors.cyan("[INFO]")} Fetching Invites...`);
|
||||||
await client.guilds.cache.forEach(guild => { //on bot start, fetch all guilds and fetch all invites to store
|
const fetchInvites = () => {
|
||||||
thisGuild = []
|
await client.guilds.cache.forEach(guild => { //on bot start, fetch all guilds and fetch all invites to store
|
||||||
guild.invites.fetch().then(guildInvites => {
|
thisGuild = []
|
||||||
guildInvites.each(guildInvite => {
|
guild.invites.fetch().then(guildInvites => {
|
||||||
client.invites[guildInvite.code] = guildInvite.uses
|
guildInvites.each(guildInvite => {
|
||||||
thisGuild.push(guildInvite.code)
|
client.invites[guildInvite.code] = guildInvite.uses
|
||||||
|
thisGuild.push(guildInvite.code)
|
||||||
|
})
|
||||||
|
}).then(() => {
|
||||||
|
console.log(`${colors.cyan("[INFO]")} Fetched ${thisGuild.length} Invites for ${colors.green(guild.name)}`);
|
||||||
|
})
|
||||||
|
guild.fetchVanityData().then(vanityData => {
|
||||||
|
client.invites[vanityData.code] = vanityData.uses
|
||||||
|
}).catch(err => {
|
||||||
|
// Do nothing
|
||||||
})
|
})
|
||||||
}).then(() => {
|
|
||||||
console.log(`${colors.cyan("[INFO]")} Fetched ${thisGuild.length} Invites for ${colors.green(guild.name)}`);
|
|
||||||
})
|
|
||||||
guild.fetchVanityData().then(vanityData => {
|
|
||||||
client.invites[vanityData.code] = vanityData.uses
|
|
||||||
}).catch(err => {
|
|
||||||
// Do nothing
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
fetchInvites();
|
||||||
|
// Set interval to update invites every 5 minutes, just in case something desyncs
|
||||||
|
setInterval(fetchInvites, 300000);
|
||||||
|
|
||||||
|
|
||||||
// Register commands
|
// Register commands
|
||||||
|
@ -152,9 +157,11 @@ client.on('guildMemberAdd', async (member) => { // We're just gonna always send
|
||||||
client.channels.fetch(row.channel.toString()).then(channel => {
|
client.channels.fetch(row.channel.toString()).then(channel => {
|
||||||
if (!channel) return; // They probably set perms wrong
|
if (!channel) return; // They probably set perms wrong
|
||||||
member.guild.invites.fetch().then(async guildInvites => { //get all guild invites
|
member.guild.invites.fetch().then(async guildInvites => { //get all guild invites
|
||||||
|
sent = false;
|
||||||
guildInvites.forEach(invite => { //basically a for loop over the invites
|
guildInvites.forEach(invite => { //basically a for loop over the invites
|
||||||
|
|
||||||
if (invite.uses != client.invites[invite.code]) { //if it doesn't match what we stored:
|
if (invite.uses != client.invites[invite.code]) { //if it doesn't match what we stored:
|
||||||
|
if (sent) return console.log(`${colors.red("[ERROR]")} Something VERY bad has happened, and we seem to have lost track of invites.\nCurrent Invite Table:\n${JSON.stringify(client.invites, null, 2)}`); //if we already sent a message, this is a fail safe to prevent spam
|
||||||
channel.send({
|
channel.send({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
color: 0x00ff00,
|
color: 0x00ff00,
|
||||||
|
|
Loading…
Reference in a new issue