diff --git a/defs/subs.py b/defs/subs.py index 58fad61..b460aba 100644 --- a/defs/subs.py +++ b/defs/subs.py @@ -59,8 +59,8 @@ async def send_to_subscribes(data: Module): try: await send_subs_msg(i, data, link) except FloodWait as e: - print(f"Send subscribes msg flood - Sleep for {e.x} second(s)") - await sleep(uniform(0.5, 1.0)) + print(f"Send subscribes msg flood - Sleep for {e.value} second(s)") + await sleep(e.value + uniform(0.5, 1.0)) await send_subs_msg(i, data, link) except ButtonUrlInvalid: print(f"Send button error") diff --git a/defs/track.py b/defs/track.py new file mode 100644 index 0000000..c381e4b --- /dev/null +++ b/defs/track.py @@ -0,0 +1,75 @@ +import contextlib +import traceback +from asyncio import sleep +from os import remove +from random import uniform + +from pyrogram.enums import ParseMode +from pyrogram.errors import FloodWait, ButtonUrlInvalid +from pyrogram.types import Message + +from ci import channel_id, app, sqlite +from defs.msg import gen_update_msg +from defs.source import download +from defs.subs import send_to_subscribes +from defs.utils import Module + + +async def send_track_msg(file, track_msg) -> Message: + if file: + return await app.send_document(channel_id, file, + caption=track_msg.text, + force_document=True, + parse_mode=ParseMode.HTML, + reply_markup=track_msg.button) + else: + return await app.send_message(channel_id, track_msg.text, + parse_mode=ParseMode.HTML, + reply_markup=track_msg.button) + + +async def push_module_to_channel(i: Module): + track_msg = gen_update_msg(i) + msg = None + if track_msg.url: + try: + file, url = await download(track_msg.url, track_msg.name, i.name) + track_msg.url = url + try: + msg = await send_track_msg(file, track_msg) + except FloodWait as e: + print(f"Send document flood - Need wait for {e.value} second(s)") + await sleep(e.value + uniform(0.5, 1.0)) + msg = await send_track_msg(file, track_msg) + except ButtonUrlInvalid: + print("Send button error") + msg = await app.send_document(channel_id, file, + caption=track_msg.text, + force_document=True, + parse_mode=ParseMode.HTML, ) + except Exception: + traceback.print_exc() + with contextlib.suppress(FileNotFoundError): + remove(file) + except FileNotFoundError: + track_msg.url = None + if not track_msg.url: + try: + msg = await send_track_msg(None, track_msg) + except FloodWait as e: + print(f"Send document flood - Sleep for {e.value} second(s)") + await sleep(e.value + uniform(0.5, 1.0)) + msg = await send_track_msg(None, track_msg) + except ButtonUrlInvalid: + print("Send button error") + msg = await app.send_message(channel_id, track_msg.text, parse_mode=ParseMode.HTML, ) + except Exception: + traceback.print_exc() + await sleep(uniform(0.5, 2.0)) + data_ = sqlite.get(i.name, {"msg_link": ""}) + if msg: + data_["msg_link"] = msg.link + else: + data_["msg_link"] = "https://t.me/lsposed_Modules_Updates_Tracker" + sqlite[i.name] = data_ + await send_to_subscribes(i) diff --git a/plugins/force_push.py b/plugins/force_push.py new file mode 100644 index 0000000..762b29a --- /dev/null +++ b/plugins/force_push.py @@ -0,0 +1,21 @@ +from pyrogram import Client, filters +from pyrogram.types import Message + +from ci import admin_id +from defs.source import from_keyword_to_module +from defs.track import push_module_to_channel + + +@Client.on_message(filters.incoming & filters.private & filters.chat(admin_id) & + filters.command(["force_push"])) +async def force_push(_: Client, message: Message): + if len(message.command) != 2: + await message.reply_text("Usage: /force_push ") + return + data = " ".join(message.command[1:]) + module = from_keyword_to_module(data) + if not module: + await message.reply_text("Not found this app.") + return + await push_module_to_channel(module) + await message.reply("Force push OK!") diff --git a/plugins/track.py b/plugins/track.py index 8a09324..050b626 100644 --- a/plugins/track.py +++ b/plugins/track.py @@ -1,31 +1,12 @@ -import contextlib -import traceback from asyncio import sleep -from os import remove from random import uniform -from pyrogram.enums import ParseMode -from pyrogram.errors import FloodWait, ButtonUrlInvalid from pyrogram.types import Message -from ci import app, scheduler, channel_id, admin_id, sqlite +from ci import scheduler, admin_id from pyrogram import Client, filters -from defs.msg import gen_update_msg -from defs.source import update_data, compare, download -from defs.subs import send_to_subscribes - - -async def send_track_msg(file, track_msg) -> Message: - if file: - return await app.send_document(channel_id, file, - caption=track_msg.text, - force_document=True, - parse_mode=ParseMode.HTML, - reply_markup=track_msg.button) - else: - return await app.send_message(channel_id, track_msg.text, - parse_mode=ParseMode.HTML, - reply_markup=track_msg.button) +from defs.source import update_data, compare +from defs.track import push_module_to_channel @scheduler.scheduled_job("cron", minute="*/30", id="0") @@ -33,50 +14,7 @@ async def run_every_30_minute(): await update_data() need_update = compare() for i in need_update: - track_msg = gen_update_msg(i) - msg = None - if track_msg.url: - try: - file, url = await download(track_msg.url, track_msg.name, i.name) - track_msg.url = url - try: - msg = await send_track_msg(file, track_msg) - except FloodWait as e: - print(f"Send document flood - Need wait for {e.value} second(s)") - await sleep(uniform(0.5, 1.0)) - msg = await send_track_msg(file, track_msg) - except ButtonUrlInvalid: - print("Send button error") - msg = await app.send_document(channel_id, file, - caption=track_msg.text, - force_document=True, - parse_mode=ParseMode.HTML, ) - except Exception: - traceback.print_exc() - with contextlib.suppress(FileNotFoundError): - remove(file) - except FileNotFoundError: - track_msg.url = None - if not track_msg.url: - try: - msg = await send_track_msg(None, track_msg) - except FloodWait as e: - print(f"Send document flood - Sleep for {e.value} second(s)") - await sleep(e.value + uniform(0.5, 1.0)) - msg = await send_track_msg(None, track_msg) - except ButtonUrlInvalid: - print("Send button error") - msg = await app.send_message(channel_id, track_msg.text, parse_mode=ParseMode.HTML, ) - except Exception: - traceback.print_exc() - await sleep(uniform(0.5, 2.0)) - data_ = sqlite.get(i.name, {"msg_link": ""}) - if msg: - data_["msg_link"] = msg.link - else: - data_["msg_link"] = "https://t.me/lsposed_Modules_Updates_Tracker" - sqlite[i.name] = data_ - await send_to_subscribes(i) + await push_module_to_channel(i) await sleep(uniform(0.5, 2.0))