支持手动强制推送某应用

This commit is contained in:
xtaodada 2022-11-06 14:42:31 +08:00
parent 0e46857c8c
commit fc41e89458
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 102 additions and 68 deletions

View File

@ -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")

75
defs/track.py Normal file
View File

@ -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)

21
plugins/force_push.py Normal file
View File

@ -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 <app_name>")
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!")

View File

@ -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))