mirror of
https://github.com/omg-xtao/ytdlbot.git
synced 2024-11-16 11:52:14 +00:00
private use
This commit is contained in:
parent
902a4609e3
commit
e8496cedfd
@ -30,5 +30,6 @@ APP_ID: "int" = int(os.getenv("APP_ID", 111))
|
||||
APP_HASH = os.getenv("APP_HASH", "111")
|
||||
TOKEN = os.getenv("TOKEN", "3703WLI")
|
||||
REDIS = os.getenv("REDIS")
|
||||
AUTHORIZED_USER: "str" = os.getenv("AUTHORIZED", "")
|
||||
|
||||
WORKERS: "int" = int(os.getenv("WORKERS", 300))
|
||||
|
@ -71,6 +71,8 @@ __I live in a place where I don't have access to Telegram Payments. So...__
|
||||
""" if ENABLE_VIP else "VIP is not enabled."
|
||||
vip_pay = "Processing your payments...If it's not responding after one minute, please contact @BennyThink."
|
||||
|
||||
private = "This bot is for private use"
|
||||
|
||||
def remaining_quota_caption(self, chat_id):
|
||||
if not ENABLE_VIP:
|
||||
return ""
|
||||
|
22
ytdl.py
22
ytdl.py
@ -20,7 +20,8 @@ from pyrogram import Client, filters, types
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from tgbot_ping import get_runtime
|
||||
|
||||
from config import APP_HASH, APP_ID, ENABLE_VIP, OWNER, TOKEN, WORKERS
|
||||
from config import (APP_HASH, APP_ID, AUTHORIZED_USER, ENABLE_VIP, OWNER,
|
||||
TOKEN, WORKERS)
|
||||
from constant import BotText
|
||||
from downloader import convert_flac, sizeof_fmt, upload_hook, ytdl_download
|
||||
from limit import Redis, verify_payment
|
||||
@ -38,6 +39,8 @@ customize_logger(["pyrogram.client", "pyrogram.session.session", "pyrogram.clien
|
||||
app = create_app()
|
||||
bot_text = BotText()
|
||||
|
||||
logging.info("Authorized users are %s", AUTHORIZED_USER)
|
||||
|
||||
|
||||
def get_metadata(video_path):
|
||||
width, height, duration = 1280, 720, 0
|
||||
@ -52,6 +55,22 @@ def get_metadata(video_path):
|
||||
return dict(height=height, width=width, duration=duration)
|
||||
|
||||
|
||||
def private_use(func):
|
||||
def wrapper(client: "Client", message: "types.Message"):
|
||||
chat_id = message.chat.id
|
||||
if AUTHORIZED_USER:
|
||||
users = [int(i) for i in AUTHORIZED_USER.split(",")]
|
||||
else:
|
||||
users = []
|
||||
if users and chat_id not in users:
|
||||
client.send_message(message.chat.id, bot_text.private)
|
||||
return
|
||||
|
||||
return func(client, message)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@app.on_message(filters.command(["start"]))
|
||||
def start_handler(client: "Client", message: "types.Message"):
|
||||
chat_id = message.chat.id
|
||||
@ -111,6 +130,7 @@ def vip_handler(client: "Client", message: "types.Message"):
|
||||
|
||||
|
||||
@app.on_message(filters.incoming)
|
||||
@private_use
|
||||
def download_handler(client: "Client", message: "types.Message"):
|
||||
# check remaining quota
|
||||
chat_id = message.chat.id
|
||||
|
Loading…
Reference in New Issue
Block a user