Skip to content

Commit

Permalink
added /cleantasks
Browse files Browse the repository at this point in the history
  • Loading branch information
EDM115 committed Aug 27, 2023
1 parent dc82929 commit 632d0fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion unzipper/helpers/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ async def remove_expired_tasks(firststart=False):
value = firststart
while True:
ongoing_tasks = await get_ongoing_tasks()
current_time = time()

for task in ongoing_tasks:
if value:
Expand All @@ -106,6 +105,7 @@ async def remove_expired_tasks(firststart=False):
except:
pass
else:
current_time = time()
start_time = task["start_time"]
type = task["type"]
time_gap = current_time - start_time
Expand Down
4 changes: 4 additions & 0 deletions unzipper/modules/bot_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ class Messages:

NOT_CLEANED = "An error happened during /cleanall 😕"

ERASE_TASKS = "Deleting {} tasks… Please wait"

ERASE_TASKS_SUCCESS = "Successfully deleted {} tasks ✅"

LOG_SENT = "Log file sent to {}"

DELETED_FOLDER = "Deleted {} folder successfully"
Expand Down
20 changes: 20 additions & 0 deletions unzipper/modules/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
count_banned_users,
count_users,
del_banned_user,
del_ongoing_task,
del_user,
get_merge_task,
get_ongoing_tasks,
Expand Down Expand Up @@ -482,6 +483,25 @@ async def del_everything(_, message: Message):
await cleaner.edit(Messages.NOT_CLEANED)


@Client.on_message(
filters.private & filters.command("cleantasks") & filters.user(Config.BOT_OWNER)
)
async def del_tasks(_, message: Message):
ongoing_tasks = await get_ongoing_tasks()
number = len(ongoing_tasks)
cleaner = await message.reply(Messages.ERASE_TASKS.format(number))

for task in ongoing_tasks:
user_id = task["user_id"]
await del_ongoing_task(user_id)
try:
shutil.rmtree(f"{Config.DOWNLOAD_LOCATION}/{user_id}")
except:
pass

await cleaner.edit(Messages.ERASE_TASKS_SUCCESS.format(number))


async def send_logs(user_id):
with open("unzip-log.txt", "rb") as doc_f:
try:
Expand Down

0 comments on commit 632d0fa

Please sign in to comment.