mirror of
				https://github.com/TitanEmbeds/Titan.git
				synced 2025-11-04 07:47:10 +01:00 
			
		
		
		
	Firing delete message twice fix
This commit is contained in:
		@@ -2,6 +2,7 @@ from config import config
 | 
				
			|||||||
from titanembeds.database import DatabaseInterface
 | 
					from titanembeds.database import DatabaseInterface
 | 
				
			||||||
from titanembeds.commands import Commands
 | 
					from titanembeds.commands import Commands
 | 
				
			||||||
from titanembeds.socketio import SocketIOInterface
 | 
					from titanembeds.socketio import SocketIOInterface
 | 
				
			||||||
 | 
					from collections import deque
 | 
				
			||||||
import discord
 | 
					import discord
 | 
				
			||||||
import aiohttp
 | 
					import aiohttp
 | 
				
			||||||
import asyncio
 | 
					import asyncio
 | 
				
			||||||
@@ -22,6 +23,8 @@ class Titan(discord.Client):
 | 
				
			|||||||
        self.command = Commands(self, self.database)
 | 
					        self.command = Commands(self, self.database)
 | 
				
			||||||
        self.socketio = SocketIOInterface(self, config["redis-uri"])
 | 
					        self.socketio = SocketIOInterface(self, config["redis-uri"])
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					        self.delete_list = [] # List of msg ids to prevent duplicate delete
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _cleanup(self):
 | 
					    def _cleanup(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.loop.run_until_complete(self.logout())
 | 
					            self.loop.run_until_complete(self.logout())
 | 
				
			||||||
@@ -107,6 +110,7 @@ class Titan(discord.Client):
 | 
				
			|||||||
        await self.socketio.on_message_update(message_after)
 | 
					        await self.socketio.on_message_update(message_after)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def on_message_delete(self, message):
 | 
					    async def on_message_delete(self, message):
 | 
				
			||||||
 | 
					        self.delete_list.append(message.id)
 | 
				
			||||||
        await self.database.delete_message(message)
 | 
					        await self.database.delete_message(message)
 | 
				
			||||||
        await self.socketio.on_message_delete(message)
 | 
					        await self.socketio.on_message_delete(message)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -199,7 +203,6 @@ class Titan(discord.Client):
 | 
				
			|||||||
        if msg["op"] != 0:
 | 
					        if msg["op"] != 0:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
        action = msg["t"]
 | 
					        action = msg["t"]
 | 
				
			||||||
        await asyncio.sleep(1)
 | 
					 | 
				
			||||||
        if action == "MESSAGE_UPDATE":
 | 
					        if action == "MESSAGE_UPDATE":
 | 
				
			||||||
            if not self.in_messages_cache(msg["d"]["id"]):
 | 
					            if not self.in_messages_cache(msg["d"]["id"]):
 | 
				
			||||||
                channel = self.get_channel(msg["d"]["channel_id"])
 | 
					                channel = self.get_channel(msg["d"]["channel_id"])
 | 
				
			||||||
@@ -207,13 +210,18 @@ class Titan(discord.Client):
 | 
				
			|||||||
                await self.on_message_edit(None, message)
 | 
					                await self.on_message_edit(None, message)
 | 
				
			||||||
        if action == "MESSAGE_DELETE":
 | 
					        if action == "MESSAGE_DELETE":
 | 
				
			||||||
            if not self.in_messages_cache(msg["d"]["id"]):
 | 
					            if not self.in_messages_cache(msg["d"]["id"]):
 | 
				
			||||||
 | 
					                await asyncio.sleep(1)
 | 
				
			||||||
                await self.process_raw_message_delete(msg["d"]["id"], msg["d"]["channel_id"])
 | 
					                await self.process_raw_message_delete(msg["d"]["id"], msg["d"]["channel_id"])
 | 
				
			||||||
        if action == "MESSAGE_DELETE_BULK":
 | 
					        if action == "MESSAGE_DELETE_BULK":
 | 
				
			||||||
 | 
					            await asyncio.sleep(1)
 | 
				
			||||||
            for msgid in msg["d"]["ids"]:
 | 
					            for msgid in msg["d"]["ids"]:
 | 
				
			||||||
                if not self.in_messages_cache(msgid):
 | 
					                if not self.in_messages_cache(msgid):
 | 
				
			||||||
                    await self.process_raw_message_delete(msgid, msg["d"]["channel_id"])
 | 
					                    await self.process_raw_message_delete(msgid, msg["d"]["channel_id"])
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    async def process_raw_message_delete(self, msg_id, channel_id):
 | 
					    async def process_raw_message_delete(self, msg_id, channel_id):
 | 
				
			||||||
 | 
					        if msg_id in self.delete_list:
 | 
				
			||||||
 | 
					            self.delete_list.remove(msg_id)
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
        channel = self.get_channel(channel_id)
 | 
					        channel = self.get_channel(channel_id)
 | 
				
			||||||
        msg = discord.Message(channel=channel, reactions=[], id=msg_id, type=0, timestamp="2017-01-15T02:59:58", content="What fun is there in making sense?") # Procreate a fake message object
 | 
					        msg = discord.Message(channel=channel, reactions=[], id=msg_id, type=0, timestamp="2017-01-15T02:59:58", content="What fun is there in making sense?") # Procreate a fake message object
 | 
				
			||||||
        await self.on_message_delete(msg)
 | 
					        await self.on_message_delete(msg)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user