Path: blob/master/bot/modules/force_start.py
1620 views
from .. import (1task_dict,2task_dict_lock,3user_data,4queued_up,5queued_dl,6queue_dict_lock,7)8from ..core.config_manager import Config9from ..helper.ext_utils.bot_utils import new_task10from ..helper.ext_utils.status_utils import get_task_by_gid11from ..helper.telegram_helper.bot_commands import BotCommands12from ..helper.telegram_helper.message_utils import send_message13from ..helper.ext_utils.task_manager import start_dl_from_queued, start_up_from_queued141516@new_task17async def remove_from_queue(_, message):18user_id = message.from_user.id if message.from_user else message.sender_chat.id19msg = message.text.split()20status = msg[1] if len(msg) > 1 and msg[1] in ["fd", "fu"] else ""21if status and len(msg) > 2 or not status and len(msg) > 1:22gid = msg[2] if status else msg[1]23task = await get_task_by_gid(gid)24if task is None:25await send_message(message, f"GID: <code>{gid}</code> Not Found.")26return27elif reply_to_id := message.reply_to_message_id:28async with task_dict_lock:29task = task_dict.get(reply_to_id)30if task is None:31await send_message(message, "This is not an active task!")32return33elif len(msg) in {1, 2}:34msg = f"""Reply to an active Command message which was used to start the download/upload.35<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.36Also send <code>/{BotCommands.ForceStartCommand[0]} GID</code> fu|fd or obly gid to force start by removing the task rom queue!37Examples:38<code>/{BotCommands.ForceStartCommand[1]}</code> GID fu (force upload)39<code>/{BotCommands.ForceStartCommand[1]}</code> GID (force download and upload)40By reply to task cmd:41<code>/{BotCommands.ForceStartCommand[1]}</code> (force download and upload)42<code>/{BotCommands.ForceStartCommand[1]}</code> fd (force download)43"""44await send_message(message, msg)45return46if (47Config.OWNER_ID != user_id48and task.listener.user_id != user_id49and (user_id not in user_data or not user_data[user_id].get("SUDO"))50):51await send_message(message, "This task is not for you!")52return53listener = task.listener54msg = ""55async with queue_dict_lock:56if status == "fu":57listener.force_upload = True58if listener.mid in queued_up:59await start_up_from_queued(listener.mid)60msg = "Task have been force started to upload!"61else:62msg = "Force upload enabled for this task!"63elif status == "fd":64listener.force_download = True65if listener.mid in queued_dl:66await start_dl_from_queued(listener.mid)67msg = "Task have been force started to download only!"68else:69msg = "This task not in download queue!"70else:71listener.force_download = True72listener.force_upload = True73if listener.mid in queued_up:74await start_up_from_queued(listener.mid)75msg = "Task have been force started to upload!"76elif listener.mid in queued_dl:77await start_dl_from_queued(listener.mid)78msg = "Task have been force started to download and upload will start once download finish!"79else:80msg = "This task not in queue!"81if msg:82await send_message(message, msg)838485