[feat] auto rmeove tg downloaded file trash
commit [authored] by: @xtaodada
This commit is contained in:
parent
ff3d27e4eb
commit
d9c6b9692b
@ -1,5 +1,22 @@
|
|||||||
|
from os import remove
|
||||||
|
|
||||||
QUEUE = {}
|
QUEUE = {}
|
||||||
|
|
||||||
|
|
||||||
|
def clean_trash(file_name: str, cid: int, clear_all: bool = False):
|
||||||
|
for i in QUEUE:
|
||||||
|
chat_queue = QUEUE[i][1:] if (i == cid and (not clear_all)) else QUEUE[i]
|
||||||
|
for f in chat_queue:
|
||||||
|
if f[1] == file_name:
|
||||||
|
file_name = None
|
||||||
|
break
|
||||||
|
if file_name:
|
||||||
|
try:
|
||||||
|
remove(file_name)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def add_to_queue(chat_id, songname, link, ref, type, quality):
|
def add_to_queue(chat_id, songname, link, ref, type, quality):
|
||||||
if chat_id in QUEUE:
|
if chat_id in QUEUE:
|
||||||
chat_queue = QUEUE[chat_id]
|
chat_queue = QUEUE[chat_id]
|
||||||
@ -8,6 +25,7 @@ def add_to_queue(chat_id, songname, link, ref, type, quality):
|
|||||||
else:
|
else:
|
||||||
QUEUE[chat_id] = [[songname, link, ref, type, quality]]
|
QUEUE[chat_id] = [[songname, link, ref, type, quality]]
|
||||||
|
|
||||||
|
|
||||||
def get_queue(chat_id):
|
def get_queue(chat_id):
|
||||||
if chat_id in QUEUE:
|
if chat_id in QUEUE:
|
||||||
chat_queue = QUEUE[chat_id]
|
chat_queue = QUEUE[chat_id]
|
||||||
@ -15,6 +33,7 @@ def get_queue(chat_id):
|
|||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def pop_an_item(chat_id):
|
def pop_an_item(chat_id):
|
||||||
if chat_id in QUEUE:
|
if chat_id in QUEUE:
|
||||||
chat_queue = QUEUE[chat_id]
|
chat_queue = QUEUE[chat_id]
|
||||||
@ -23,8 +42,12 @@ def pop_an_item(chat_id):
|
|||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def clear_queue(chat_id):
|
def clear_queue(chat_id):
|
||||||
if chat_id in QUEUE:
|
if chat_id in QUEUE:
|
||||||
|
for i in QUEUE[chat_id]:
|
||||||
|
if "t.me" in i[2]:
|
||||||
|
clean_trash(i[1], chat_id, True)
|
||||||
QUEUE.pop(chat_id)
|
QUEUE.pop(chat_id)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user