-
Notifications
You must be signed in to change notification settings - Fork 0
/
autodelete.py
47 lines (42 loc) · 1.58 KB
/
autodelete.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from datetime import timedelta, datetime
import time
import asyncio
messageList = []
class Autodelete:
def __init__(self, msg_id, channel_id, expiration_date):
self.msg_id = msg_id
self.channel_id = channel_id
self.expiration_date = expiration_date
#add message for auto deleting after one day
async def msgAddAutodelete(message, days):
message_id = message.id
expiration_day = datetime.today().weekday()
for day_count in range(days):
expiration_day = expiration_day + 1 if expiration_day < 6 else -6
messageList.append(Autodelete(message_id, message.channel.id, expiration_day))
#checks the day and deletes all messages from yesterday
async def deleteMessages(client):
today = datetime.today().weekday()
for m in messageList:
if m.expiration_date == today:
try:
await client.http.delete_message(m.channel_id, m.msg_id)
except:
pass
messageList.remove(m)
async def deleteIn(client,message,seconds=0,minutes=0,days=0):
now = datetime.now()
deletionTime = now + timedelta(days=days, minutes=minutes, seconds=seconds)
msg = Autodelete(message.id, message.channel.id, deletionTime)
if seconds > 0:
sleeptime = 1
elif minutes > 0:
sleeptime = 60
else:
sleeptime = 60*60
while True:
now = datetime.now()
if now.strftime("%d %H:%M:%S") == deletionTime.strftime("%d %H:%M:%S"):
await client.http.delete_message(msg.channel_id, msg.msg_id)
break
await asyncio.sleep(sleeptime)