Skip to content

Commit

Permalink
Fix new_task deco
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Sep 3, 2024
1 parent 2bd2f1a commit 27fa460
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 96 deletions.
14 changes: 7 additions & 7 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
cmd_exec,
sync_to_async,
create_help_buttons,
handler_new_task,
new_task,
)
from .helper.ext_utils.db_handler import database
from .helper.ext_utils.files_utils import clean_all, exit_clean_up
Expand Down Expand Up @@ -63,7 +63,7 @@
)


@handler_new_task
@new_task
async def stats(_, message):
if await aiopath.exists(".git"):
last_commit = await cmd_exec(
Expand Down Expand Up @@ -96,7 +96,7 @@ async def stats(_, message):
await send_message(message, stats)


@handler_new_task
@new_task
async def start(client, message):
buttons = ButtonMaker()
buttons.url_button(
Expand All @@ -118,7 +118,7 @@ async def start(client, message):
)


@handler_new_task
@new_task
async def restart(_, message):
intervals["stopAll"] = True
restart_message = await send_message(message, "Restarting...")
Expand Down Expand Up @@ -153,15 +153,15 @@ async def restart(_, message):
osexecl(executable, executable, "-m", "bot")


@handler_new_task
@new_task
async def ping(_, message):
start_time = int(round(time() * 1000))
reply = await send_message(message, "Starting Ping")
end_time = int(round(time() * 1000))
await edit_message(reply, f"{end_time - start_time} ms")


@handler_new_task
@new_task
async def log(_, message):
await send_file(message, "log.txt")

Expand Down Expand Up @@ -207,7 +207,7 @@ async def log(_, message):
"""


@handler_new_task
@new_task
async def bot_help(_, message):
await send_message(message, help_string)

Expand Down
16 changes: 2 additions & 14 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,11 @@ async def cmd_exec(cmd, shell=False):
return stdout, stderr, proc.returncode


def handler_new_task(func):
@wraps(func)
async def wrapper(*args, **kwargs):
bot_loop.create_task(func(*args, **kwargs))

async def dummy():
pass

return dummy

return wrapper


def new_task(func):
@wraps(func)
async def wrapper(*args, **kwargs):
return bot_loop.create_task(func(*args, **kwargs))
task = bot_loop.create_task(func(*args, **kwargs))
return task

return wrapper

Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_leech_utils/download_utils/jd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
jd_lock,
jd_downloads,
)
from ...ext_utils.bot_utils import retry_function, handler_new_task
from ...ext_utils.bot_utils import retry_function, new_task
from ...ext_utils.jdownloader_booter import jdownloader
from ...ext_utils.task_manager import check_running_tasks, stop_duplicate_check
from ...listeners.jdownloader_listener import on_download_start
Expand All @@ -31,7 +31,7 @@
)


@handler_new_task
@new_task
async def configureDownload(_, query, obj):
data = query.data.split()
message = query.message
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_leech_utils/gdrive_utils/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from time import time

from bot import config_dict
from ...ext_utils.bot_utils import update_user_ldata, handler_new_task
from ...ext_utils.bot_utils import update_user_ldata, new_task
from ...ext_utils.db_handler import database
from ...ext_utils.status_utils import get_readable_file_size, get_readable_time
from ...mirror_leech_utils.gdrive_utils.helper import GoogleDriveHelper
Expand All @@ -25,7 +25,7 @@
LIST_LIMIT = 6


@handler_new_task
@new_task
async def id_updates(_, query, obj):
await query.answer()
message = query.message
Expand Down
8 changes: 2 additions & 6 deletions bot/helper/mirror_leech_utils/rclone_utils/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
from time import time

from bot import LOGGER, config_dict
from ...ext_utils.bot_utils import (
cmd_exec,
handler_new_task,
update_user_ldata,
)
from ...ext_utils.bot_utils import cmd_exec, update_user_ldata, new_task
from ...ext_utils.db_handler import database
from ...ext_utils.status_utils import get_readable_file_size, get_readable_time
from ...telegram_helper.button_build import ButtonMaker
Expand All @@ -26,7 +22,7 @@
LIST_LIMIT = 6


@handler_new_task
@new_task
async def path_updates(_, query, obj):
await query.answer()
message = query.message
Expand Down
10 changes: 5 additions & 5 deletions bot/modules/authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from pyrogram.handlers import MessageHandler

from bot import user_data, config_dict, bot
from ..helper.ext_utils.bot_utils import update_user_ldata, handler_new_task
from ..helper.ext_utils.bot_utils import update_user_ldata, new_task
from ..helper.ext_utils.db_handler import database
from ..helper.telegram_helper.bot_commands import BotCommands
from ..helper.telegram_helper.filters import CustomFilters
from ..helper.telegram_helper.message_utils import send_message


@handler_new_task
@new_task
async def authorize(_, message):
msg = message.text.split()
thread_id = None
Expand Down Expand Up @@ -49,7 +49,7 @@ async def authorize(_, message):
await send_message(message, msg)


@handler_new_task
@new_task
async def unauthorize(_, message):
msg = message.text.split()
thread_id = None
Expand Down Expand Up @@ -81,7 +81,7 @@ async def unauthorize(_, message):
await send_message(message, msg)


@handler_new_task
@new_task
async def addSudo(_, message):
id_ = ""
msg = message.text.split()
Expand All @@ -102,7 +102,7 @@ async def addSudo(_, message):
await send_message(message, msg)


@handler_new_task
@new_task
async def removeSudo(_, message):
id_ = ""
msg = message.text.split()
Expand Down
18 changes: 9 additions & 9 deletions bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
from ..helper.ext_utils.bot_utils import (
SetInterval,
sync_to_async,
handler_new_task,
retry_function,
new_task,
)
from ..helper.ext_utils.db_handler import database
from ..helper.ext_utils.jdownloader_booter import jdownloader
Expand Down Expand Up @@ -249,7 +249,7 @@ async def update_buttons(message, key=None, edit_type=None):
await edit_message(message, msg, button)


@handler_new_task
@new_task
async def edit_variable(_, message, pre_message, key):
handler_dict[message.chat.id] = False
value = message.text
Expand Down Expand Up @@ -344,7 +344,7 @@ async def edit_variable(_, message, pre_message, key):
await sabnzbd_client.set_special_config("servers", s)


@handler_new_task
@new_task
async def edit_aria(_, message, pre_message, key):
handler_dict[message.chat.id] = False
value = message.text
Expand Down Expand Up @@ -373,7 +373,7 @@ async def edit_aria(_, message, pre_message, key):
await database.update_aria2(key, value)


@handler_new_task
@new_task
async def edit_qbit(_, message, pre_message, key):
handler_dict[message.chat.id] = False
value = message.text
Expand All @@ -393,7 +393,7 @@ async def edit_qbit(_, message, pre_message, key):
await database.update_qbittorrent(key, value)


@handler_new_task
@new_task
async def edit_nzb(_, message, pre_message, key):
handler_dict[message.chat.id] = False
value = message.text
Expand All @@ -409,7 +409,7 @@ async def edit_nzb(_, message, pre_message, key):
await database.update_nzb_config()


@handler_new_task
@new_task
async def edit_nzb_server(_, message, pre_message, key, index=0):
handler_dict[message.chat.id] = False
value = message.text
Expand Down Expand Up @@ -474,7 +474,7 @@ async def sync_jdownloader():
await database.update_private_file("cfg.zip")


@handler_new_task
@new_task
async def update_private_file(_, message, pre_message):
handler_dict[message.chat.id] = False
if not message.media and (file_name := message.text):
Expand Down Expand Up @@ -578,7 +578,7 @@ async def event_filter(_, __, event):
client.remove_handler(*handler)


@handler_new_task
@new_task
async def edit_bot_settings(client, query):
data = query.data.split()
message = query.message
Expand Down Expand Up @@ -918,7 +918,7 @@ async def edit_bot_settings(client, query):
await delete_message(message)


@handler_new_task
@new_task
async def bot_settings(_, message):
handler_dict[message.chat.id] = False
msg, button = await get_buttons()
Expand Down
10 changes: 5 additions & 5 deletions bot/modules/cancel_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pyrogram.handlers import MessageHandler, CallbackQueryHandler

from bot import task_dict, bot, task_dict_lock, OWNER_ID, user_data, multi_tags
from ..helper.ext_utils.bot_utils import handler_new_task
from ..helper.ext_utils.bot_utils import new_task
from ..helper.ext_utils.status_utils import (
get_task_by_gid,
get_all_tasks,
Expand All @@ -20,7 +20,7 @@
)


@handler_new_task
@new_task
async def cancel_task(_, message):
user_id = message.from_user.id if message.from_user else message.sender_chat.id
msg = message.text.split()
Expand Down Expand Up @@ -58,7 +58,7 @@ async def cancel_task(_, message):
await obj.cancel_task()


@handler_new_task
@new_task
async def cancel_multi(_, query):
data = query.data.split()
user_id = query.from_user.id
Expand Down Expand Up @@ -128,7 +128,7 @@ def create_cancel_buttons(is_sudo, user_id=""):
return buttons.build_menu(2)


@handler_new_task
@new_task
async def cancell_all_buttons(_, message):
async with task_dict_lock:
count = len(task_dict)
Expand All @@ -141,7 +141,7 @@ async def cancell_all_buttons(_, message):
await auto_delete_message(message, can_msg)


@handler_new_task
@new_task
async def cancel_all_update(_, query):
data = query.data.split()
message = query.message
Expand Down
8 changes: 4 additions & 4 deletions bot/modules/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from traceback import format_exc

from bot import LOGGER, bot
from ..helper.ext_utils.bot_utils import sync_to_async, handler_new_task
from ..helper.ext_utils.bot_utils import sync_to_async, new_task
from ..helper.telegram_helper.bot_commands import BotCommands
from ..helper.telegram_helper.filters import CustomFilters
from ..helper.telegram_helper.message_utils import send_file, send_message
Expand Down Expand Up @@ -45,12 +45,12 @@ async def send(msg, message):
await send_message(message, f"<code>{msg}</code>")


@handler_new_task
@new_task
async def aioexecute(_, message):
await send(await do("aexec", message), message)


@handler_new_task
@new_task
async def execute(_, message):
await send(await do("exec", message), message)

Expand Down Expand Up @@ -108,7 +108,7 @@ async def do(func, message):
return result


@handler_new_task
@new_task
async def clear(_, message):
log_input(message)
global namespaces
Expand Down
6 changes: 3 additions & 3 deletions bot/modules/file_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..helper.ext_utils.bot_utils import (
bt_selection_buttons,
sync_to_async,
handler_new_task,
new_task,
)
from ..helper.ext_utils.status_utils import get_task_by_gid, MirrorStatus
from ..helper.telegram_helper.bot_commands import BotCommands
Expand All @@ -29,7 +29,7 @@
)


@handler_new_task
@new_task
async def select(_, message):
if not config_dict["BASE_URL"]:
await send_message(message, "Base URL not defined!")
Expand Down Expand Up @@ -107,7 +107,7 @@ async def select(_, message):
await send_message(message, msg, SBUTTONS)


@handler_new_task
@new_task
async def get_confirm(_, query):
user_id = query.from_user.id
data = query.data.split()
Expand Down
4 changes: 2 additions & 2 deletions bot/modules/force_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
queued_dl,
queue_dict_lock,
)
from ..helper.ext_utils.bot_utils import handler_new_task
from ..helper.ext_utils.bot_utils import new_task
from ..helper.ext_utils.status_utils import get_task_by_gid
from ..helper.telegram_helper.bot_commands import BotCommands
from ..helper.telegram_helper.filters import CustomFilters
from ..helper.telegram_helper.message_utils import send_message
from ..helper.ext_utils.task_manager import start_dl_from_queued, start_up_from_queued


@handler_new_task
@new_task
async def remove_from_queue(_, message):
user_id = message.from_user.id if message.from_user else message.sender_chat.id
msg = message.text.split()
Expand Down
Loading

0 comments on commit 27fa460

Please sign in to comment.