-
-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78323a4
commit 750c897
Showing
4 changed files
with
34 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
__author__ = "Benny <[email protected]>" | ||
|
||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
import pathlib | ||
|
@@ -40,7 +39,6 @@ | |
ENABLE_CELERY, | ||
ENABLE_VIP, | ||
OWNER, | ||
PREMIUM_USER, | ||
RATE_LIMIT, | ||
RCLONE_PATH, | ||
TMPFILE_PATH, | ||
|
@@ -53,6 +51,7 @@ | |
from limit import Payment | ||
from utils import ( | ||
apply_log_formatter, | ||
auto_restart, | ||
customize_logger, | ||
get_metadata, | ||
get_revision, | ||
|
@@ -79,6 +78,18 @@ def retrieve_message(chat_id: int, message_id: int) -> types.Message | Any: | |
return bot.get_messages(chat_id, message_id) | ||
|
||
|
||
def premium_button(): | ||
markup = types.InlineKeyboardMarkup( | ||
[ | ||
[ | ||
types.InlineKeyboardButton("Yes", callback_data="premium-yes"), | ||
types.InlineKeyboardButton("No", callback_data="premium-no"), | ||
] | ||
] | ||
) | ||
return markup | ||
|
||
|
||
@app.task(rate_limit=f"{RATE_LIMIT}/m") | ||
def ytdl_download_task(chat_id: int, message_id: int, url: str): | ||
logging.info("YouTube celery tasks started for %s", url) | ||
|
@@ -88,9 +99,7 @@ def ytdl_download_task(chat_id: int, message_id: int, url: str): | |
except FileTooBig as e: | ||
# if you can go there, that means you have premium users set up | ||
logging.warning("Seeking for help from premium user...") | ||
bot_msg.edit_text(f"{e}\n\nPlease wait, I will try to send it as premium user") | ||
data = {"url": url, "user_id": bot_msg.chat.id} | ||
bot.send_message(PREMIUM_USER, json.dumps(data), disable_notification=True, disable_web_page_preview=True) | ||
bot_msg.edit_text(f"{e}\n\n{bot_text.premium_warning}", reply_markup=premium_button()) | ||
except Exception: | ||
bot_msg.edit_text(f"Download failed!❌\n\n`{traceback.format_exc()[-2000:]}`", disable_web_page_preview=True) | ||
logging.info("YouTube celery tasks ended.") | ||
|
@@ -157,10 +166,8 @@ def ytdl_download_entrance(client: Client, bot_msg: types.Message, url: str, mod | |
ytdl_normal_download(client, bot_msg, url) | ||
except FileTooBig as e: | ||
logging.warning("Seeking for help from premium user...") | ||
bot_msg.edit_text(f"{e}\n\nPlease wait, I will try to send it as premium user") | ||
# this is only for normal node. Celery node will need to do it in celery tasks | ||
data = {"url": url, "user_id": bot_msg.chat.id} | ||
client.send_message(PREMIUM_USER, json.dumps(data), disable_notification=True, disable_web_page_preview=True) | ||
bot_msg.edit_text(f"{e}\n\n{bot_text.premium_warning}", reply_markup=premium_button()) | ||
except Exception as e: | ||
logging.error("Failed to download %s, error: %s", url, e) | ||
bot_msg.edit_text(f"Download failed!❌\n\n`{traceback.format_exc()[-2000:]}`", disable_web_page_preview=True) | ||
|
@@ -502,7 +509,7 @@ def run_celery(): | |
threading.Thread(target=run_celery, daemon=True).start() | ||
|
||
scheduler = BackgroundScheduler(timezone="Europe/London") | ||
# scheduler.add_job(auto_restart, "interval", seconds=900) | ||
scheduler.add_job(auto_restart, "interval", seconds=900) | ||
scheduler.start() | ||
|
||
idle() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
__author__ = "Benny <[email protected]>" | ||
|
||
import contextlib | ||
import json | ||
import logging | ||
import os | ||
import random | ||
|
@@ -316,6 +317,17 @@ def tronpayment_btn_calback(client: Client, callback_query: types.CallbackQuery) | |
client.send_photo(chat_id, bio, caption=f"Send any amount of TRX to `{addr}`") | ||
|
||
|
||
@app.on_callback_query(filters.regex(r"premium.*")) | ||
def premium_click(client: Client, callback_query: types.CallbackQuery): | ||
data = callback_query.data | ||
if data == "premium-yes": | ||
replied = callback_query.message.reply_to_message | ||
data = {"url": replied.text, "user_id": callback_query.message.chat.id} | ||
client.send_message(PREMIUM_USER, json.dumps(data), disable_notification=True, disable_web_page_preview=True) | ||
else: | ||
callback_query.answer("Cancelled.") | ||
|
||
|
||
@app.on_callback_query(filters.regex(r"bot-payments-.*")) | ||
def bot_payment_btn_calback(client: Client, callback_query: types.CallbackQuery): | ||
callback_query.answer("Generating invoice...") | ||
|