Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
anasty17
GitHub Repository: anasty17/mirror-leech-telegram-bot
Path: blob/master/bot/modules/force_start.py
1620 views
1
from .. import (
2
task_dict,
3
task_dict_lock,
4
user_data,
5
queued_up,
6
queued_dl,
7
queue_dict_lock,
8
)
9
from ..core.config_manager import Config
10
from ..helper.ext_utils.bot_utils import new_task
11
from ..helper.ext_utils.status_utils import get_task_by_gid
12
from ..helper.telegram_helper.bot_commands import BotCommands
13
from ..helper.telegram_helper.message_utils import send_message
14
from ..helper.ext_utils.task_manager import start_dl_from_queued, start_up_from_queued
15
16
17
@new_task
18
async def remove_from_queue(_, message):
19
user_id = message.from_user.id if message.from_user else message.sender_chat.id
20
msg = message.text.split()
21
status = msg[1] if len(msg) > 1 and msg[1] in ["fd", "fu"] else ""
22
if status and len(msg) > 2 or not status and len(msg) > 1:
23
gid = msg[2] if status else msg[1]
24
task = await get_task_by_gid(gid)
25
if task is None:
26
await send_message(message, f"GID: <code>{gid}</code> Not Found.")
27
return
28
elif reply_to_id := message.reply_to_message_id:
29
async with task_dict_lock:
30
task = task_dict.get(reply_to_id)
31
if task is None:
32
await send_message(message, "This is not an active task!")
33
return
34
elif len(msg) in {1, 2}:
35
msg = f"""Reply to an active Command message which was used to start the download/upload.
36
<code>/{BotCommands.ForceStartCommand[0]}</code> fd (to remove it from download queue) or fu (to remove it from upload queue) or nothing to start remove it from both download and upload queue.
37
Also send <code>/{BotCommands.ForceStartCommand[0]} GID</code> fu|fd or obly gid to force start by removing the task rom queue!
38
Examples:
39
<code>/{BotCommands.ForceStartCommand[1]}</code> GID fu (force upload)
40
<code>/{BotCommands.ForceStartCommand[1]}</code> GID (force download and upload)
41
By reply to task cmd:
42
<code>/{BotCommands.ForceStartCommand[1]}</code> (force download and upload)
43
<code>/{BotCommands.ForceStartCommand[1]}</code> fd (force download)
44
"""
45
await send_message(message, msg)
46
return
47
if (
48
Config.OWNER_ID != user_id
49
and task.listener.user_id != user_id
50
and (user_id not in user_data or not user_data[user_id].get("SUDO"))
51
):
52
await send_message(message, "This task is not for you!")
53
return
54
listener = task.listener
55
msg = ""
56
async with queue_dict_lock:
57
if status == "fu":
58
listener.force_upload = True
59
if listener.mid in queued_up:
60
await start_up_from_queued(listener.mid)
61
msg = "Task have been force started to upload!"
62
else:
63
msg = "Force upload enabled for this task!"
64
elif status == "fd":
65
listener.force_download = True
66
if listener.mid in queued_dl:
67
await start_dl_from_queued(listener.mid)
68
msg = "Task have been force started to download only!"
69
else:
70
msg = "This task not in download queue!"
71
else:
72
listener.force_download = True
73
listener.force_upload = True
74
if listener.mid in queued_up:
75
await start_up_from_queued(listener.mid)
76
msg = "Task have been force started to upload!"
77
elif listener.mid in queued_dl:
78
await start_dl_from_queued(listener.mid)
79
msg = "Task have been force started to download and upload will start once download finish!"
80
else:
81
msg = "This task not in queue!"
82
if msg:
83
await send_message(message, msg)
84
85