mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-03 23:37:09 +01:00 
			
		
		
		
	Basic message relaying via WS
This commit is contained in:
		
							
								
								
									
										1
									
								
								discordbot/titanembeds/socketio/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								discordbot/titanembeds/socketio/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
from .socketiointerface import SocketIOInterface
 | 
			
		||||
							
								
								
									
										26
									
								
								discordbot/titanembeds/socketio/socketiointerface.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								discordbot/titanembeds/socketio/socketiointerface.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
import socketio
 | 
			
		||||
from titanembeds.utils import get_message_author, get_message_mentions
 | 
			
		||||
 | 
			
		||||
class SocketIOInterface:
 | 
			
		||||
    def __init__(self, bot, redis_uri):
 | 
			
		||||
        self.io = socketio.AsyncRedisManager(redis_uri, write_only=True, channel='flask-socketio')
 | 
			
		||||
        self.bot = bot
 | 
			
		||||
    
 | 
			
		||||
    async def on_message(self, message):
 | 
			
		||||
        if message.server:
 | 
			
		||||
            edit_ts = message.edited_timestamp
 | 
			
		||||
            if not edit_ts:
 | 
			
		||||
                edit_ts = None
 | 
			
		||||
            else:
 | 
			
		||||
                edit_ts = str(edit_ts)
 | 
			
		||||
            msg = {
 | 
			
		||||
                "id": message.id,
 | 
			
		||||
                "channel_id": message.channel.id,
 | 
			
		||||
                "content": message.content,
 | 
			
		||||
                "author": get_message_author(message),
 | 
			
		||||
                "timestamp": str(message.timestamp),
 | 
			
		||||
                "edited_timestamp": edit_ts,
 | 
			
		||||
                "mentions": get_message_mentions(message.mentions),
 | 
			
		||||
                "attachments": message.attachments,
 | 
			
		||||
            }
 | 
			
		||||
            await self.io.emit('MESSAGE_CREATE', data=msg, room=message.server.id, namespace='/gateway')
 | 
			
		||||
		Reference in New Issue
	
	Block a user