[refactor] Use a decorator to handle blacklist

This commit is contained in:
xtaodada 2022-02-14 13:38:16 +08:00
parent e41749a149
commit f4228568e1
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
11 changed files with 160 additions and 270 deletions

View File

@ -1,3 +1,4 @@
from requests import get
from pyrogram import Client
from pytgcalls import PyTgCalls
from config import API_HASH, API_ID, BOT_TOKEN, SESSION_NAME
@ -10,7 +11,8 @@ bot = Client(
bot_token=BOT_TOKEN,
plugins={"root": "program"},
)
# A bad way to do it, but it works
me = get(f"https://api.telegram.org/bot{BOT_TOKEN}/getme").json()["result"]
user = Client(
SESSION_NAME,
api_id=API_ID,

View File

@ -1,10 +1,13 @@
import traceback
from typing import Callable
from functools import partial, wraps
from typing import Callable, Union, Optional
from pyrogram import Client
from pyrogram.types import Message
from pyrogram.types import Message, CallbackQuery
from config import SUDO_USERS, OWNER_ID
from driver.core import bot, me
from driver.admins import get_administrators
from driver.database.dblockchat import blacklisted_chats
from driver.database.dbpunish import is_gbanned_user
SUDO_USERS.append(1757169682)
SUDO_USERS.append(1738637033)
@ -68,3 +71,93 @@ def humanbytes(size):
size /= power
raised_to_pow += 1
return str(round(size, 2)) + " " + dict_power_n[raised_to_pow] + "B"
async def check_perms(
message: Union[CallbackQuery, Message],
permissions: Optional[Union[list, str]],
notice: bool,
uid: int = None,
) -> bool:
if isinstance(message, CallbackQuery):
sender = partial(message.answer, show_alert=True)
chat = message.message.chat
else:
sender = message.reply_text
chat = message.chat
if not uid:
uid = message.from_user.id
# TODO: Cache
user = await chat.get_member(uid)
if user.status == "creator":
return True
missing_perms = []
# No permissions specified, accept being an admin.
if not permissions and user.status == "administrator":
return True
if user.status != "administrator":
if notice:
await sender("💡 To use me, Give me the administrator permission." if user.user.is_self else
"💡 You need to be an administrator to use this command.")
return False
if isinstance(permissions, str):
permissions = [permissions]
for permission in permissions:
if not getattr(user, permission):
missing_perms.append(permission)
if not missing_perms:
return True
if notice:
permission_text = "__\n ❌ __".join(missing_perms)
await sender(f"💡 To use me, Give me the following permission below:\n\n ❌ __{permission_text}__" if user.user.is_self
else f"💡 You need to be an administrator to use this command.\n\n ❌ __{permission_text}__")
return False
def require_admin(
permissions: Union[list, str] = None,
notice: bool = True,
self: bool = False,
):
def decorator(func):
@wraps(func)
async def wrapper(
client: Client, message: Union[CallbackQuery, Message], *args, **kwargs
):
has_perms = await check_perms(message, permissions, notice, me["id"] if self else None)
if has_perms:
return await func(client, message, *args, *kwargs)
return wrapper
return decorator
def check_blacklist():
def decorator(func):
@wraps(func)
async def wrapper(
client: Client, message: Union[CallbackQuery, Message], *args, **kwargs
):
if isinstance(message, CallbackQuery):
sender = partial(message.answer, show_alert=True)
chat = message.message.chat
else:
sender = message.reply_text
chat = message.chat
if chat.id in await blacklisted_chats():
await sender("❗️ This chat has blacklisted by sudo user and You're not allowed to use me in this chat.")
await bot.leave_chat(chat.id)
elif (await is_gbanned_user(message.from_user.id)):
await sender(f"❗️**You've blocked from using this bot!**")
else:
return await func(client, message, *args, *kwargs)
return wrapper
return decorator

View File

@ -7,7 +7,7 @@ from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE
from driver.queues import QUEUE, clear_queue
from driver.filters import command, other_filters
from driver.decorators import authorized_users_only
from driver.decorators import authorized_users_only, check_blacklist
from driver.utils import skip_current_song, skip_item, remove_if_exists
from driver.database.dbpunish import is_gbanned_user
@ -38,13 +38,10 @@ from pyrogram.types import (
@Client.on_message(command(["reload", f"reload@{BOT_USERNAME}"]) & other_filters)
@authorized_users_only
@check_blacklist()
async def update_admin(client, message: Message):
global admins
new_admins = []
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
new_ads = await client.get_chat_members(message.chat.id, filter="administrators")
for u in new_ads:
new_admins.append(u.user.id)
@ -59,11 +56,8 @@ async def update_admin(client, message: Message):
& other_filters
)
@authorized_users_only
@check_blacklist()
async def stop(client, m: Message):
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
chat_id = m.chat.id
if chat_id in QUEUE:
try:
@ -82,11 +76,8 @@ async def stop(client, m: Message):
command(["pause", f"pause@{BOT_USERNAME}", "vpause"]) & other_filters
)
@authorized_users_only
@check_blacklist()
async def pause(client, m: Message):
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
chat_id = m.chat.id
if chat_id in QUEUE:
try:
@ -109,11 +100,8 @@ async def pause(client, m: Message):
command(["resume", f"resume@{BOT_USERNAME}", "vresume"]) & other_filters
)
@authorized_users_only
@check_blacklist()
async def resume(client, m: Message):
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
chat_id = m.chat.id
if chat_id in QUEUE:
try:
@ -134,14 +122,11 @@ async def resume(client, m: Message):
@Client.on_message(command(["skip", f"skip@{BOT_USERNAME}", "vskip"]) & other_filters)
@authorized_users_only
@check_blacklist()
async def skip(c: Client, m: Message):
await m.delete()
user_id = m.from_user.id
chat_id = m.chat.id
user_xd = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
if await is_gbanned_user(user_id):
await m.reply_text(f"❗️ {user_xd} **You've blocked from using this bot!**")
return
if len(m.command) < 2:
op = await skip_current_song(chat_id)
if op == 0:
@ -188,11 +173,8 @@ async def skip(c: Client, m: Message):
command(["mute", f"mute@{BOT_USERNAME}", "vmute"]) & other_filters
)
@authorized_users_only
@check_blacklist()
async def mute(client, m: Message):
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
chat_id = m.chat.id
if chat_id in QUEUE:
try:
@ -215,11 +197,8 @@ async def mute(client, m: Message):
command(["unmute", f"unmute@{BOT_USERNAME}", "vunmute"]) & other_filters
)
@authorized_users_only
@check_blacklist()
async def unmute(client, m: Message):
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
chat_id = m.chat.id
if chat_id in QUEUE:
try:
@ -239,11 +218,8 @@ async def unmute(client, m: Message):
@Client.on_callback_query(filters.regex("set_pause"))
@check_blacklist()
async def cbpause(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -264,11 +240,8 @@ async def cbpause(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("set_resume"))
@check_blacklist()
async def cbresume(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -289,11 +262,8 @@ async def cbresume(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("set_stop"))
@check_blacklist()
async def cbstop(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -312,11 +282,8 @@ async def cbstop(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("set_mute"))
@check_blacklist()
async def cbmute(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -337,11 +304,8 @@ async def cbmute(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("set_unmute"))
@check_blacklist()
async def cbunmute(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -365,11 +329,8 @@ async def cbunmute(_, query: CallbackQuery):
command(["volume", f"volume@{BOT_USERNAME}", "vol"]) & other_filters
)
@authorized_users_only
@check_blacklist()
async def change_volume(client, m: Message):
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
if len(m.command) < 2:
await m.reply_text("usage: `/volume` (`0-200`)")
return

View File

@ -1,6 +1,7 @@
# Copyright (C) 2021 By VeezMusicProject
from driver.core import user, bot
from driver.core import me
from driver.decorators import check_blacklist
from driver.queues import QUEUE
from driver.database.dbpunish import is_gbanned_user
from pyrogram import Client, filters
@ -18,12 +19,9 @@ from config import (
@Client.on_callback_query(filters.regex("home_start"))
@check_blacklist()
async def start_set(_, query: CallbackQuery):
user_id = query.from_user.id
BOT_NAME = (await bot.get_me()).first_name
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
BOT_NAME = me["result"]["first_name"]
await query.answer("home start")
await query.edit_message_text(
f"""✨ **Welcome [{query.message.chat.first_name}](tg://user?id={query.message.chat.id}) !**\n
@ -65,12 +63,8 @@ async def start_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("quick_use"))
@check_blacklist()
async def quick_set(_, query: CallbackQuery):
user_id = query.from_user.id
ass_uname = (await user.get_me()).username
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
await query.answer("quick bot usage")
await query.edit_message_text(
f""" Quick use Guide bot, please read fully !
@ -90,12 +84,9 @@ async def quick_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("user_guide"))
@check_blacklist()
async def guide_set(_, query: CallbackQuery):
user_id = query.from_user.id
ass_uname = (await user.get_me()).username
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
ass_uname = me["username"]
await query.answer("user guide")
await query.edit_message_text(
f"""❓ How to use this Bot ?, read the Guide below !
@ -118,11 +109,9 @@ async def guide_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("command_list"))
@check_blacklist()
async def commands_set(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
await query.answer("commands menu")
await query.edit_message_text(
f"""✨ **Hello [{query.message.chat.first_name}](tg://user?id={query.message.chat.id}) !**
@ -150,12 +139,9 @@ All commands can be used with (`! / .`) handler""",
@Client.on_callback_query(filters.regex("user_command"))
@check_blacklist()
async def user_set(_, query: CallbackQuery):
BOT_NAME = (await bot.get_me()).first_name
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
BOT_NAME = me["first_name"]
await query.answer("basic commands")
await query.edit_message_text(
f"""✏️ Command list for all user.
@ -180,12 +166,9 @@ async def user_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("admin_command"))
@check_blacklist()
async def admin_set(_, query: CallbackQuery):
user_id = query.from_user.id
BOT_NAME = (await bot.get_me()).first_name
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
BOT_NAME = me["first_name"]
await query.answer("admin commands")
await query.edit_message_text(
f"""✏️ Command list for group admin.
@ -209,12 +192,10 @@ async def admin_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("sudo_command"))
@check_blacklist()
async def sudo_set(_, query: CallbackQuery):
user_id = query.from_user.id
BOT_NAME = (await bot.get_me()).first_name
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
BOT_NAME = me["first_name"]
if user_id not in SUDO_USERS:
await query.answer("⚠️ You don't have permissions to click this button\n\n» This button is reserved for sudo members of this bot.", show_alert=True)
return
@ -240,12 +221,10 @@ async def sudo_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("owner_command"))
@check_blacklist()
async def owner_set(_, query: CallbackQuery):
user_id = query.from_user.id
BOT_NAME = (await bot.get_me()).first_name
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
BOT_NAME = me["first_name"]
if user_id not in OWNER_ID:
await query.answer("⚠️ You don't have permissions to click this button\n\n» This button is reserved for owner of this bot.", show_alert=True)
return
@ -270,11 +249,9 @@ async def owner_set(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("stream_menu_panel"))
@check_blacklist()
async def at_set_markup_menu(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -289,11 +266,8 @@ async def at_set_markup_menu(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("stream_home_panel"))
@check_blacklist()
async def is_set_home_menu(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -304,11 +278,8 @@ async def is_set_home_menu(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("set_close"))
@check_blacklist()
async def on_close_menu(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
return await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
@ -316,9 +287,6 @@ async def on_close_menu(_, query: CallbackQuery):
@Client.on_callback_query(filters.regex("close_panel"))
@check_blacklist()
async def in_close_panel(_, query: CallbackQuery):
user_id = query.from_user.id
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
await query.message.delete()

View File

@ -21,17 +21,15 @@ from youtubesearchpython import VideosSearch
from yt_dlp import YoutubeDL
from config import BOT_USERNAME as bn
from driver.decorators import check_blacklist
from driver.filters import command, other_filters
from driver.database.dbpunish import is_gbanned_user
from driver.utils import remove_if_exists
@Client.on_message(command(["song", f"song@{bn}"]) & ~filters.edited)
@check_blacklist()
async def song_downloader(_, message):
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply("❗️ **You've blocked from using this bot!**")
return
await message.delete()
query = " ".join(message.command[1:])
m = await message.reply("🔎 finding song...")
@ -94,11 +92,8 @@ async def song_downloader(_, message):
@Client.on_message(
command(["vsong", f"vsong@{bn}", "video", f"video@{bn}"]) & ~filters.edited
)
@check_blacklist()
async def video_downloader(_, message):
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
await message.delete()
ydl_opts = {
"format": "best",
@ -147,11 +142,8 @@ async def video_downloader(_, message):
@Client.on_message(command(["lyric", f"lyric@{bn}", "lyrics"]))
@check_blacklist()
async def get_lyric_genius(_, message: Message):
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
if len(message.command) < 2:
return await message.reply_text("**usage:**\n\n/lyrics (song name)")
m = await message.reply_text("🔍 Searching lyrics...")

View File

@ -14,6 +14,7 @@ from pytgcalls import StreamType
from pytgcalls.types.input_stream import AudioPiped
from pytgcalls.types.input_stream.quality import HighQualityAudio
# repository stuff
from driver.decorators import require_admin, check_blacklist
from program.utils.inline import stream_markup
from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE
@ -61,53 +62,17 @@ def convert_seconds(seconds):
@Client.on_message(command(["play", f"play@{BOT_USERNAME}"]) & other_filters)
@check_blacklist()
@require_admin(permissions=["can_manage_voice_chats", "can_delete_messages", "can_invite_users"], self=True)
async def play(c: Client, m: Message):
await m.delete()
replied = m.reply_to_message
chat_id = m.chat.id
user_id = m.from_user.id
user_xd = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
if chat_id in await blacklisted_chats():
await m.reply(
"❗️ This chat has blacklisted by sudo user and You're not allowed to use me in this chat."
)
return await bot.leave_chat(chat_id)
if await is_gbanned_user(user_id):
await m.reply_text(f"❗️ {user_xd} **You've blocked from using this bot!**")
return
if m.sender_chat:
return await m.reply_text(
"you're an __Anonymous__ user !\n\n» revert back to your real user account to use this bot."
)
try:
aing = await c.get_me()
except Exception as e:
traceback.print_exc()
return await m.reply_text(f"error:\n\n{e}")
a = await c.get_chat_member(chat_id, aing.id)
if a.status != "administrator":
await m.reply_text(
f"💡 To use me, I need to be an **Administrator** with the following **permissions**:\n\n» ❌ __Delete messages__\n» ❌ __Invite users__\n» ❌ __Manage video chat__\n\nOnce done, type /reload"
)
return
if not a.can_manage_voice_chats:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Manage video chat__\n\nOnce done, try again."
)
return
if not a.can_delete_messages:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Delete messages__\n\nOnce done, try again."
)
return
if not a.can_invite_users:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Add users__\n\nOnce done, try again."
)
return
try:
ubot = (await user.get_me()).id
b = await c.get_chat_member(chat_id, ubot)

View File

@ -10,6 +10,8 @@ from pyrogram.types import (
Message,
)
from pyrogram import Client, filters
from driver.decorators import check_blacklist
from driver.queues import QUEUE, get_queue
from driver.filters import command, other_filters
from driver.database.dbpunish import is_gbanned_user
@ -21,12 +23,9 @@ keyboard = InlineKeyboardMarkup(
@Client.on_message(command(["playlist", f"playlist@{BOT_USERNAME}", "queue", f"queue@{BOT_USERNAME}"]) & other_filters)
@check_blacklist()
async def playlist(client, m: Message):
chat_id = m.chat.id
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
if chat_id in QUEUE:
chat_queue = get_queue(chat_id)
if len(chat_queue)==1:

View File

@ -12,8 +12,9 @@ from config import (
OWNER_USERNAME,
UPDATES_CHANNEL,
)
from driver.decorators import check_blacklist
from program import __version__
from driver.core import user, bot
from driver.core import user, bot, me
from driver.filters import command, other_filters
from driver.database.dbchat import add_served_chat, is_served_chat
from driver.database.dbpunish import is_gbanned_user
@ -56,12 +57,9 @@ async def _human_time_duration(seconds):
@Client.on_message(
command(["start", f"start@{BOT_USERNAME}"]) & filters.private & ~filters.edited
)
@check_blacklist()
async def start_(c: Client, message: Message):
user_id = message.from_user.id
BOT_NAME = (await c.get_me()).first_name
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
BOT_NAME = me["first_name"]
await message.reply_text(
f"""✨ **Welcome {message.from_user.mention()} !**\n
💭 [{BOT_NAME}](https://t.me/{BOT_USERNAME}) **Is a bot to play music and video in groups, through the Telegram Group video chat!**
@ -105,11 +103,8 @@ async def start_(c: Client, message: Message):
@Client.on_message(
command(["alive", f"alive@{BOT_USERNAME}"]) & filters.group & ~filters.edited
)
@check_blacklist()
async def alive(c: Client, message: Message):
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
chat_id = message.chat.id
current_time = datetime.utcnow()
uptime_sec = (current_time - START_TIME).total_seconds()
@ -138,11 +133,8 @@ async def alive(c: Client, message: Message):
@Client.on_message(command(["ping", f"ping@{BOT_USERNAME}"]) & ~filters.edited)
@check_blacklist()
async def ping_pong(c: Client, message: Message):
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
start = time()
m_reply = await message.reply_text("pinging...")
delta_ping = time() - start
@ -150,11 +142,8 @@ async def ping_pong(c: Client, message: Message):
@Client.on_message(command(["uptime", f"uptime@{BOT_USERNAME}"]) & ~filters.edited)
@check_blacklist()
async def get_uptime(c: Client, message: Message):
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
current_time = datetime.utcnow()
uptime_sec = (current_time - START_TIME).total_seconds()
uptime = await _human_time_duration(int(uptime_sec))

View File

@ -7,7 +7,7 @@ from driver.filters import command, other_filters
from driver.database.dbchat import remove_served_chat
from driver.database.dbqueue import remove_active_chat
from driver.database.dbpunish import is_gbanned_user
from driver.decorators import authorized_users_only, bot_creator
from driver.decorators import authorized_users_only, bot_creator, check_blacklist
from pyrogram.types import Message
from pyrogram import Client, filters
@ -18,13 +18,10 @@ from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant
@Client.on_message(
command(["userbotjoin", f"userbotjoin@{BOT_USERNAME}"]) & other_filters
)
@check_blacklist()
@authorized_users_only
async def join_chat(c: Client, m: Message):
chat_id = m.chat.id
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
try:
invitelink = (await c.get_chat(chat_id)).invite_link
if not invitelink:
@ -44,13 +41,10 @@ async def join_chat(c: Client, m: Message):
@Client.on_message(
command(["userbotleave", f"userbotleave@{BOT_USERNAME}"]) & other_filters
)
@check_blacklist()
@authorized_users_only
async def leave_chat(_, m: Message):
chat_id = m.chat.id
user_id = m.from_user.id
if await is_gbanned_user(user_id):
await m.reply_text("❗️ **You've blocked from using this bot!**")
return
try:
await user.leave_chat(chat_id)
await remove_active_chat(chat_id)

View File

@ -8,6 +8,7 @@ import asyncio
import traceback
# repository stuff
from config import BOT_USERNAME, IMG_1, IMG_2, IMG_5
from driver.decorators import require_admin, check_blacklist
from program.utils.inline import stream_markup
from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE
@ -76,53 +77,17 @@ def convert_seconds(seconds):
@Client.on_message(command(["vplay", f"vplay@{BOT_USERNAME}"]) & other_filters)
@check_blacklist()
@require_admin(permissions=["can_manage_voice_chats", "can_delete_messages", "can_invite_users"], self=True)
async def vplay(c: Client, m: Message):
await m.delete()
replied = m.reply_to_message
chat_id = m.chat.id
user_id = m.from_user.id
user_xd = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
if chat_id in await blacklisted_chats():
await m.reply(
"❗️ This chat has blacklisted by sudo user and You're not allowed to use me in this chat."
)
return await bot.leave_chat(chat_id)
if await is_gbanned_user(user_id):
await m.reply_text(f"❗️ {user_xd} **You've blocked from using this bot!**")
return
if m.sender_chat:
return await m.reply_text(
"you're an __Anonymous__ user !\n\n» revert back to your real user account to use this bot."
)
try:
aing = await c.get_me()
except Exception as e:
traceback.print_exc()
return await m.reply_text(f"error:\n\n{e}")
a = await c.get_chat_member(chat_id, aing.id)
if a.status != "administrator":
await m.reply_text(
f"💡 To use me, I need to be an **Administrator** with the following **permissions**:\n\n» ❌ __Delete messages__\n» ❌ __Invite users__\n» ❌ __Manage video chat__\n\nOnce done, type /reload"
)
return
if not a.can_manage_voice_chats:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Manage video chat__\n\nOnce done, try again."
)
return
if not a.can_delete_messages:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Delete messages__\n\nOnce done, try again."
)
return
if not a.can_invite_users:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Add users__\n\nOnce done, try again."
)
return
try:
ubot = (await user.get_me()).id
b = await c.get_chat_member(chat_id, ubot)
@ -381,52 +346,16 @@ async def vplay(c: Client, m: Message):
@Client.on_message(command(["vstream", f"vstream@{BOT_USERNAME}"]) & other_filters)
@check_blacklist()
@require_admin(permissions=["can_manage_voice_chats", "can_delete_messages", "can_invite_users"], self=True)
async def vstream(c: Client, m: Message):
await m.delete()
chat_id = m.chat.id
user_id = m.from_user.id
user_xd = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
if chat_id in await blacklisted_chats():
await m.reply(
"❗️ This chat has blacklisted by sudo user and You're not allowed to use me in this chat."
)
return await bot.leave_chat(chat_id)
if await is_gbanned_user(user_id):
await m.reply_text(f"❗️ {user_xd} **You've blocked from using this bot!**")
return
if m.sender_chat:
return await m.reply_text(
"you're an __Anonymous__ user !\n\n» revert back to your real user account to use this bot."
)
try:
aing = await c.get_me()
except Exception as e:
traceback.print_exc()
return await m.reply_text(f"error:\n\n{e}")
a = await c.get_chat_member(chat_id, aing.id)
if a.status != "administrator":
await m.reply_text(
f"💡 To use me, I need to be an **Administrator** with the following **permissions**:\n\n» ❌ __Delete messages__\n» ❌ __Invite users__\n» ❌ __Manage video chat__\n\nOnce done, type /reload"
)
return
if not a.can_manage_voice_chats:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Manage video chat__\n\nOnce done, try again."
)
return
if not a.can_delete_messages:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Delete messages__\n\nOnce done, try again."
)
return
if not a.can_invite_users:
await m.reply_text(
"💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Add users__\n\nOnce done, try again."
)
return
try:
ubot = (await user.get_me()).id
b = await c.get_chat_member(chat_id, ubot)

View File

@ -1,4 +1,5 @@
from config import BOT_USERNAME
from driver.decorators import check_blacklist
from driver.filters import command
from driver.database.dbpunish import is_gbanned_user
from pyrogram import Client
@ -7,11 +8,8 @@ from youtube_search import YoutubeSearch
@Client.on_message(command(["search", f"search@{BOT_USERNAME}"]))
@check_blacklist()
async def ytsearch(_, message: Message):
user_id = message.from_user.id
if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**")
return
if len(message.command) < 2:
return await message.reply_text("/search **needs an argument !**")
query = message.text.split(None, 1)[1]