private use

This commit is contained in:
BennyThink 2021-09-26 19:18:29 +08:00
parent 902a4609e3
commit e8496cedfd
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
3 changed files with 24 additions and 1 deletions

View File

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

View File

@ -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
View File

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