diff --git a/main.js b/main.js index 397df8a..489883f 100755 --- a/main.js +++ b/main.js @@ -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>`); diff --git a/modules/CustomClasses.js b/modules/CustomClasses.js index d1072f3..27d0997 100755 --- a/modules/CustomClasses.js +++ b/modules/CustomClasses.js @@ -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) { diff --git a/modules/functions.js b/modules/functions.js index 527186b..2f44561 100755 --- a/modules/functions.js +++ b/modules/functions.js @@ -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