mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-03 23:37:09 +01:00 
			
		
		
		
	Realtime updating channel list
This commit is contained in:
		@@ -171,34 +171,41 @@ class Titan(discord.Client):
 | 
			
		||||
    async def on_server_update(self, guildbefore, guildafter):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
        await self.database.update_guild(guildafter)
 | 
			
		||||
        await self.socketio.on_guild_update(guildafter)
 | 
			
		||||
 | 
			
		||||
    async def on_server_role_create(self, role):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
        if role.name == self.user.name and role.managed:
 | 
			
		||||
            await asyncio.sleep(2)
 | 
			
		||||
        await self.database.update_guild(role.server)
 | 
			
		||||
        await self.socketio.on_guild_role_create(role)
 | 
			
		||||
 | 
			
		||||
    async def on_server_role_delete(self, role):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
        if role.server.me not in role.server.members:
 | 
			
		||||
            return
 | 
			
		||||
        await self.database.update_guild(role.server)
 | 
			
		||||
        await self.socketio.on_guild_role_delete(role)
 | 
			
		||||
 | 
			
		||||
    async def on_server_role_update(self, rolebefore, roleafter):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
        await self.database.update_guild(roleafter.server)
 | 
			
		||||
        await self.socketio.on_guild_role_update(role)
 | 
			
		||||
 | 
			
		||||
    async def on_channel_delete(self, channel):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
        await self.database.update_guild(channel.server)
 | 
			
		||||
        await self.socketio.on_channel_delete(channel)
 | 
			
		||||
 | 
			
		||||
    async def on_channel_create(self, channel):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
        await self.database.update_guild(channel.server)
 | 
			
		||||
        await self.socketio.on_channel_create(channel)
 | 
			
		||||
 | 
			
		||||
    async def on_channel_update(self, channelbefore, channelafter):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
        await self.database.update_guild(channelafter.server)
 | 
			
		||||
        await self.socketio.on_channel_update(channelafter)
 | 
			
		||||
 | 
			
		||||
    async def on_member_join(self, member):
 | 
			
		||||
        await self.wait_until_dbonline()
 | 
			
		||||
 
 | 
			
		||||
@@ -110,4 +110,61 @@ class SocketIOInterface:
 | 
			
		||||
    
 | 
			
		||||
    async def on_guild_emojis_update(self, emojis):
 | 
			
		||||
        emotes = self.get_formatted_emojis(emojis)
 | 
			
		||||
        await self.io.emit('GUILD_EMOJIS_UPDATE', data=emotes, room=str("GUILD_"+emojis[0].server.id), namespace='/gateway')
 | 
			
		||||
        await self.io.emit('GUILD_EMOJIS_UPDATE', data=emotes, room=str("GUILD_"+emojis[0].server.id), namespace='/gateway')
 | 
			
		||||
    
 | 
			
		||||
    def get_formatted_guild(self, guild):
 | 
			
		||||
        guil = {
 | 
			
		||||
            "id": guild.id,
 | 
			
		||||
            "name": guild.name,
 | 
			
		||||
            "icon": guild.icon,
 | 
			
		||||
            "icon_url": guild.icon_url,
 | 
			
		||||
        }
 | 
			
		||||
        return guil
 | 
			
		||||
    
 | 
			
		||||
    async def on_guild_update(self, guild):
 | 
			
		||||
        guildobj = self.get_formatted_guild(guild)
 | 
			
		||||
        await self.io.emit('GUILD_UPDATE', data=guildobj, room=str("GUILD_"+guild.id), namespace='/gateway')
 | 
			
		||||
    
 | 
			
		||||
    def get_formatted_channel(self, channel):
 | 
			
		||||
        chan = {
 | 
			
		||||
            "id": channel.id,
 | 
			
		||||
            "guild_id": channel.server.id,
 | 
			
		||||
        }
 | 
			
		||||
        return chan
 | 
			
		||||
    
 | 
			
		||||
    async def on_channel_delete(self, channel):
 | 
			
		||||
        if str(channel.type) != "text":
 | 
			
		||||
            return
 | 
			
		||||
        chan = self.get_formatted_channel(channel)
 | 
			
		||||
        await self.io.emit('CHANNEL_DELETE', data=chan, room=str("GUILD_"+channel.server.id), namespace='/gateway')
 | 
			
		||||
    
 | 
			
		||||
    async def on_channel_create(self, channel):
 | 
			
		||||
        if str(channel.type) != "text":
 | 
			
		||||
            return
 | 
			
		||||
        chan = self.get_formatted_channel(channel)
 | 
			
		||||
        await self.io.emit('CHANNEL_CREATE', data=chan, room=str("GUILD_"+channel.server.id), namespace='/gateway')
 | 
			
		||||
    
 | 
			
		||||
    async def on_channel_update(self, channel):
 | 
			
		||||
        if str(channel.type) != "text":
 | 
			
		||||
            return
 | 
			
		||||
        chan = self.get_formatted_channel(channel)
 | 
			
		||||
        await self.io.emit('CHANNEL_UPDATE', data=chan, room=str("GUILD_"+channel.server.id), namespace='/gateway')
 | 
			
		||||
    
 | 
			
		||||
    def get_formatted_role(self, role):
 | 
			
		||||
        rol = {
 | 
			
		||||
            "id": role.id,
 | 
			
		||||
            "guild_id": role.server.id,
 | 
			
		||||
        }
 | 
			
		||||
        return rol
 | 
			
		||||
    
 | 
			
		||||
    async def on_guild_role_create(self, role):
 | 
			
		||||
        rol = self.get_formatted_role(role)
 | 
			
		||||
        await self.io.emit('GUILD_ROLE_CREATE', data=rol, room=str("GUILD_"+role.server.id), namespace='/gateway')
 | 
			
		||||
 | 
			
		||||
    async def on_guild_role_update(self, role):
 | 
			
		||||
        rol = self.get_formatted_role(role)
 | 
			
		||||
        await self.io.emit('GUILD_ROLE_UPDATE', data=rol, room=str("GUILD_"+role.server.id), namespace='/gateway')
 | 
			
		||||
    
 | 
			
		||||
    async def on_guild_role_delete(self, role):
 | 
			
		||||
        rol = self.get_formatted_role(role)
 | 
			
		||||
        await self.io.emit('GUILD_ROLE_DELETE', data=rol, room=str("GUILD_"+role.server.id), namespace='/gateway')
 | 
			
		||||
		Reference in New Issue
	
	Block a user