You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.7 KiB
45 lines
1.7 KiB
2 years ago
|
import asyncio
|
||
|
import traceback
|
||
|
from datetime import datetime
|
||
|
|
||
2 years ago
|
import discord
|
||
|
|
||
2 years ago
|
|
||
|
class Deletion:
|
||
|
def __init__(self, message, timestamp):
|
||
|
self.message = message
|
||
|
self.timestamp = timestamp
|
||
|
|
||
|
# This function will be called by the bot to process the message queue
|
||
|
@staticmethod
|
||
2 years ago
|
async def process_deletion_queue(
|
||
|
deletion_queue, PROCESS_WAIT_TIME, EMPTY_WAIT_TIME
|
||
|
):
|
||
2 years ago
|
while True:
|
||
|
try:
|
||
|
# If the queue is empty, sleep for a short time before checking again
|
||
|
if deletion_queue.empty():
|
||
|
await asyncio.sleep(EMPTY_WAIT_TIME)
|
||
|
continue
|
||
|
|
||
|
# Get the next message from the queue
|
||
|
deletion = await deletion_queue.get()
|
||
|
|
||
|
# Check if the current timestamp is greater than the deletion timestamp
|
||
|
if datetime.now().timestamp() > deletion.timestamp:
|
||
|
# If the deletion timestamp has passed, delete the message
|
||
2 years ago
|
# check if deletion.message is of type discord.Message
|
||
|
if isinstance(deletion.message, discord.Message):
|
||
|
await deletion.message.delete()
|
||
|
else:
|
||
|
await deletion.message.delete_original_response()
|
||
2 years ago
|
else:
|
||
|
await deletion_queue.put(deletion)
|
||
|
|
||
|
# Sleep for a short time before processing the next message
|
||
|
# This will prevent the bot from spamming messages too quickly
|
||
|
await asyncio.sleep(PROCESS_WAIT_TIME)
|
||
|
except:
|
||
|
traceback.print_exc()
|
||
2 years ago
|
pass
|