Disable relay on guilds I'm no longer in
This commit is contained in:
		
							parent
							
								
									6afa5af5de
								
							
						
					
					
						commit
						2c82f2607f
					
				
							
								
								
									
										3
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								main.js
									
									
									
									
									
								
							| @ -33,9 +33,10 @@ client.once('ready', async () => { | |||||||
| 	fn.collectionBuilders.setvalidCommands(client); | 	fn.collectionBuilders.setvalidCommands(client); | ||||||
| 	await fn.collectionBuilders.guildInfos(client); | 	await fn.collectionBuilders.guildInfos(client); | ||||||
| 	await fn.collectionBuilders.messageCollectors(client); | 	await fn.collectionBuilders.messageCollectors(client); | ||||||
|  | 	const serverCount = client.guilds.cache.size; | ||||||
| 	// checkRateLimits();
 | 	// checkRateLimits();
 | ||||||
| 	console.log('Ready!'); | 	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') { | 	if (isDev == 'false') { | ||||||
| 		client.channels.fetch(statusChannelId).then(channel => { | 		client.channels.fetch(statusChannelId).then(channel => { | ||||||
| 			channel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`); | 			channel.send(`${new Date().toISOString()} -- \nStartup Sequence Complete <@481933290912350209>`); | ||||||
|  | |||||||
| @ -63,11 +63,11 @@ module.exports = { | |||||||
|             return this; |             return this; | ||||||
|         } |         } | ||||||
|         setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId, enabled) { |         setReminders(waterMessage, fruitMessage, reminderChannelId, watchChannelId, enabled) { | ||||||
|             if (waterMessage) this.waterMessage = waterMessage; |             this.waterMessage = waterMessage === undefined ? this.waterMessage : waterMessage | ||||||
|             if (fruitMessage) this.fruitMessage = fruitMessage; |             this.fruitMessage = fruitMessage === undefined ? this.fruitMessage : fruitMessage; | ||||||
|             if (reminderChannelId) this.reminderChannelId = reminderChannelId; |             this.reminderChannelId = reminderChannelId === undefined ? this.reminderChannelId : reminderChannelId | ||||||
|             if (watchChannelId) this.watchChannelId = watchChannelId; |             this.watchChannelId = watchChannelId === undefined ? this.watchChannelId : watchChannelId; | ||||||
|             if (enabled) this.notificationsEnabled = enabled; |             this.notificationsEnabled = enabled === undefined ? this.notificationsEnabled : enabled; | ||||||
|             return this; |             return this; | ||||||
|         } |         } | ||||||
|         setRoles(waterRoleId, fruitRoleId) { |         setRoles(waterRoleId, fruitRoleId) { | ||||||
|  | |||||||
| @ -91,7 +91,17 @@ const functions = { | |||||||
| 			const { guildInfos, messageCollectors } = client; | 			const { guildInfos, messageCollectors } = client; | ||||||
| 			// Iterate over each guild info
 | 			// Iterate over each guild info
 | ||||||
| 			await guildInfos.forEach(async guildInfo => { | 			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); | 				await this.end(client, guildInfo); | ||||||
| 			} | 			} | ||||||
| 			// Make sure guildInfo is what we expect, the watch channel isnt blank, and notifications are enabled
 | 			// 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
 | 				// 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
 | 				// Fetch the Channel
 | ||||||
| 				const channel = await guild.channels.fetch(guildInfo.watchChannelId); | 				const channel = await guild.channels.fetch(guildInfo.watchChannelId); | ||||||
| 				// Create the filter function
 | 				// Create the filter function
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user