mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-03 23:37:09 +01:00 
			
		
		
		
	Send message to channel when connection to database changes
This commit is contained in:
		@@ -39,9 +39,21 @@ class Titan(discord.Client):
 | 
			
		||||
        await self.wait_until_ready()
 | 
			
		||||
        while not self.database_connected:
 | 
			
		||||
            await asyncio.sleep(1) # Wait until db is connected
 | 
			
		||||
        last_db_conn_status = False
 | 
			
		||||
        while not self.is_closed:
 | 
			
		||||
            try:
 | 
			
		||||
                await self.database.send_webserver_heartbeat()
 | 
			
		||||
            await asyncio.sleep(60)
 | 
			
		||||
                self.database_connected = True
 | 
			
		||||
            except:
 | 
			
		||||
                self.database_connected = False
 | 
			
		||||
            if last_db_conn_status != self.database_connected and config.get("errorreporting-channelid"):
 | 
			
		||||
                error_channel = self.get_channel(config["errorreporting-channelid"])
 | 
			
		||||
                if self.database_connected:
 | 
			
		||||
                    await self.send_message(error_channel, "Titan has obtained connection to the database!")
 | 
			
		||||
                else:
 | 
			
		||||
                    await self.send_message(error_channel, "Titan has lost connection to the database! Don't panic!! We'll sort this out... hopefully soon.")
 | 
			
		||||
                last_db_conn_status = self.database_connected
 | 
			
		||||
            await asyncio.sleep(4)
 | 
			
		||||
 | 
			
		||||
    def run(self):
 | 
			
		||||
        try:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user