Disable relay on guilds I'm no longer in

This commit is contained in:
Skylar Grant 2023-06-03 16:14:00 -04:00
parent b0d6bdcf8a
commit c4fc1a4ba6
3 changed files with 22 additions and 9 deletions

View File

@ -33,9 +33,10 @@ client.once('ready', async () => {
fn.collectionBuilders.setvalidCommands(client);
await fn.collectionBuilders.guildInfos(client);
await fn.collectionBuilders.messageCollectors(client);
const serverCount = client.guilds.cache.size;
// checkRateLimits();
console.log('Ready!');
client.user.setActivity({ name: strings.activity.name, type: ActivityType.Watching });
client.user.setActivity({ name: `${serverCount} trees grow.`, type: ActivityType.Watching });
if (isDev == 'false') {
client.channels.fetch(statusChannelId).then(channel => {
channel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`);

View File

@ -63,11 +63,11 @@ module.exports = {
return this;
}
setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId, enabled) {
if (waterMessage) this.waterMessage = waterMessage;
if (fruitMessage) this.fruitMessage = fruitMessage;
if (reminderChannelId) this.reminderChannelId = reminderChannelId;
if (watchChannelId) this.watchChannelId = watchChannelId;
if (enabled) this.notificationsEnabled = enabled;
this.waterMessage = waterMessage === undefined ? this.waterMessage : waterMessage
this.fruitMessage = fruitMessage === undefined ? this.fruitMessage : fruitMessage;
this.reminderChannelId = reminderChannelId === undefined ? this.reminderChannelId : reminderChannelId
this.watchChannelId = watchChannelId === undefined ? this.watchChannelId : watchChannelId;
this.notificationsEnabled = enabled === undefined ? this.notificationsEnabled : enabled;
return this;
}
setRoles(waterRoleId, fruitRoleId) {

View File

@ -91,7 +91,17 @@ const functions = {
const { guildInfos, messageCollectors } = client;
// Iterate over each guild info
await guildInfos.forEach(async guildInfo => {
await functions.collectors.create(client, guildInfo);
await functions.collectors.create(client, guildInfo).catch(async e => {
if (e === "ERRNOGUILD") {
guildInfo.setReminders(undefined, undefined, undefined, undefined, false);
const query = guildInfo.queryBuilder("setReminders");
await dbfn.setGuildInfo(query);
await functions.collectionBuilders.guildInfos(client);
console.log("Disabled notification relay for a guild I'm no longer in: " + guildInfo.guildId);
} else {
throw e;
}
});
});
}
},
@ -835,9 +845,11 @@ const functions = {
await this.end(client, guildInfo);
}
// Make sure guildInfo is what we expect, the watch channel isnt blank, and notifications are enabled
if (guildInfo instanceof GuildInfo && guildInfo.watchChannelId != "" && guildInfo.notificationsEnabled) {
if ((guildInfo instanceof GuildInfo && guildInfo.watchChannelId != "") && (guildInfo.notificationsEnabled == true)) {
// Fetch the Guild
const guild = await client.guilds.fetch(guildInfo.guildId).catch(e => { throw "Attempted to fetch guild I'm no longer in." });
const guild = await client.guilds.fetch(guildInfo.guildId).catch(e => {
throw "ERRNOGUILD"
});
// Fetch the Channel
const channel = await guild.channels.fetch(guildInfo.watchChannelId);
// Create the filter function