Skip to content

Commit

Permalink
Only allow message deletion for 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
amadejkastelic committed Sep 25, 2023
1 parent 22fd000 commit 2d5d447
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import datetime
import logging
import os
import random
Expand Down Expand Up @@ -63,19 +64,20 @@ async def on_message(self, message: discord.Message):
await new_message.delete()

async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
if reaction.emoji == '❌' and user.mentioned_in(message=reaction.message):
url = utils.find_first_url(reaction.message.content)
logging.info(f'User {user.display_name} deleted message {url}.')
await asyncio.gather(
reaction.message.clear_reaction('❌'),
reaction.message.edit(
content=f'Embed {url} deleted by {user.mention}.',
embeds=[],
attachments=[],
suppress=True,
),
)

if (
reaction.emoji == '❌'
and user.mentioned_in(message=reaction.message)
and reaction.message.created_at.replace(tzinfo=None)
>= (datetime.datetime.utcnow() - datetime.timedelta(minutes=5))
):
logging.info(f'User {user.display_name} deleted message {utils.find_first_url(reaction.message.content)}')
await reaction.message.delete()


logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s',
)

intents = discord.Intents.default()
intents.message_content = True
Expand Down

0 comments on commit 2d5d447

Please sign in to comment.