mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-24 14:07:03 +01:00
Firing delete message twice fix
This commit is contained in:
parent
46f5594763
commit
aed6192364
@ -2,6 +2,7 @@ from config import config
|
||||
from titanembeds.database import DatabaseInterface
|
||||
from titanembeds.commands import Commands
|
||||
from titanembeds.socketio import SocketIOInterface
|
||||
from collections import deque
|
||||
import discord
|
||||
import aiohttp
|
||||
import asyncio
|
||||
@ -22,6 +23,8 @@ class Titan(discord.Client):
|
||||
self.command = Commands(self, self.database)
|
||||
self.socketio = SocketIOInterface(self, config["redis-uri"])
|
||||
|
||||
self.delete_list = [] # List of msg ids to prevent duplicate delete
|
||||
|
||||
def _cleanup(self):
|
||||
try:
|
||||
self.loop.run_until_complete(self.logout())
|
||||
@ -107,6 +110,7 @@ class Titan(discord.Client):
|
||||
await self.socketio.on_message_update(message_after)
|
||||
|
||||
async def on_message_delete(self, message):
|
||||
self.delete_list.append(message.id)
|
||||
await self.database.delete_message(message)
|
||||
await self.socketio.on_message_delete(message)
|
||||
|
||||
@ -199,7 +203,6 @@ class Titan(discord.Client):
|
||||
if msg["op"] != 0:
|
||||
return
|
||||
action = msg["t"]
|
||||
await asyncio.sleep(1)
|
||||
if action == "MESSAGE_UPDATE":
|
||||
if not self.in_messages_cache(msg["d"]["id"]):
|
||||
channel = self.get_channel(msg["d"]["channel_id"])
|
||||
@ -207,13 +210,18 @@ class Titan(discord.Client):
|
||||
await self.on_message_edit(None, message)
|
||||
if action == "MESSAGE_DELETE":
|
||||
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"])
|
||||
if action == "MESSAGE_DELETE_BULK":
|
||||
await asyncio.sleep(1)
|
||||
for msgid in msg["d"]["ids"]:
|
||||
if not self.in_messages_cache(msgid):
|
||||
await self.process_raw_message_delete(msgid, msg["d"]["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)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user