From f486b76ab941bc5e4d66bf3f973a0b9ff5d24faa Mon Sep 17 00:00:00 2001 From: X-Gorn Date: Sun, 9 Jun 2024 17:56:45 +0900 Subject: [PATCH] fix: filters --- Bot/clients.py | 2 ++ Bot/functions/filters.py | 7 ++++++- Bot/plugins/admin.py | 9 ++++----- Bot/plugins/commands.py | 4 ++-- Bot/plugins/echo.py | 2 +- Bot/plugins/settings.py | 6 +++--- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Bot/clients.py b/Bot/clients.py index 5837ce4..ba509d3 100644 --- a/Bot/clients.py +++ b/Bot/clients.py @@ -7,11 +7,13 @@ from typing import Union from .config import Config from .translation import Translation +from .functions.filters import Filter class BotClient(Client): def __init__(self): + self.filters = Filter self.sleep = asyncio.sleep self.session: ClientSession = None self.config = Config diff --git a/Bot/functions/filters.py b/Bot/functions/filters.py index 0d9a85c..c2c1939 100644 --- a/Bot/functions/filters.py +++ b/Bot/functions/filters.py @@ -6,4 +6,9 @@ async def database_filter(_, __, ___): return True if client.database else False -database = filters.create(database_filter) +class Filter(object): + + database = filters.create(database_filter) + + auth_users = filters.incoming & filters.user( + client.config.AUTH_USERS) if client.config.AUTH_USERS else filters.incoming diff --git a/Bot/plugins/admin.py b/Bot/plugins/admin.py index e176b99..058d35d 100644 --- a/Bot/plugins/admin.py +++ b/Bot/plugins/admin.py @@ -1,12 +1,11 @@ import traceback from .. import client -from ..functions import filters as myFilters from pyrogram import Client, filters from pyrogram.types import Message from pyrogram.errors import FloodWait, Forbidden, BadRequest -@Client.on_message(filters.private & filters.command('broadcast') & filters.reply & myFilters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('broadcast') & filters.reply & client.filters.database & filters.user(users=client.config.OWNER_ID)) async def broadcast(bot: Client, update: Message): message = await update.reply(text='Broadcast started...') async for user in client.database.xurluploader.users.find({}): @@ -26,12 +25,12 @@ async def broadcast(bot: Client, update: Message): await message.edit(text='Broadcast done.') -@Client.on_message(filters.private & filters.command('broadcast') & ~filters.reply & myFilters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('broadcast') & ~filters.reply & client.filters.database & filters.user(users=client.config.OWNER_ID)) async def broadcast_no_reply(bot: Client, update: Message): await update.reply('Reply to a message.') -@Client.on_message(filters.private & filters.command('ban') & myFilters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('ban') & client.filters.database & filters.user(users=client.config.OWNER_ID)) async def ban(bot: Client, update: Message): try: user_id = int(update.command[1]) @@ -47,7 +46,7 @@ async def ban(bot: Client, update: Message): await update.reply('User ID is not exist in database.') -@Client.on_message(filters.private & filters.command('unban') & myFilters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('unban') & client.filters.database & filters.user(users=client.config.OWNER_ID)) async def unban(bot: Client, update: Message): try: user_id = int(update.command[1]) diff --git a/Bot/plugins/commands.py b/Bot/plugins/commands.py index 1c9e031..66196f0 100644 --- a/Bot/plugins/commands.py +++ b/Bot/plugins/commands.py @@ -8,7 +8,7 @@ from .. import client -@Client.on_message(filters.private & filters.command("help") & filters.user(client.config.AUTH_USERS)) +@Client.on_message(filters.private & filters.command("help") & client.filters.auth_users) async def help(bot: Client, update: Message): await bot.send_message( chat_id=update.chat.id, @@ -18,7 +18,7 @@ async def help(bot: Client, update: Message): ) -@Client.on_message(filters.private & filters.command("start") & filters.user(client.config.AUTH_USERS)) +@Client.on_message(filters.private & filters.command("start") & client.filters.auth_users) async def start(bot: Client, update: Message): await bot.send_message( chat_id=update.chat.id, diff --git a/Bot/plugins/echo.py b/Bot/plugins/echo.py index acbb0f8..3efbcef 100644 --- a/Bot/plugins/echo.py +++ b/Bot/plugins/echo.py @@ -21,7 +21,7 @@ pattern=r'(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*))(.*)?') -@Client.on_message(filters.private & filters.regex(pattern=URL_REGEX) & filters.user(users=client.config.AUTH_USERS)) +@Client.on_message(filters.private & filters.regex(pattern=URL_REGEX) & client.filters.auth_users) async def echo_http(bot: Client, update: Message): if client.database: user = await client.database.xurluploader.users.find_one({'id': update.from_user.id}) diff --git a/Bot/plugins/settings.py b/Bot/plugins/settings.py index a04686f..1512260 100644 --- a/Bot/plugins/settings.py +++ b/Bot/plugins/settings.py @@ -12,7 +12,7 @@ async def no_args_filter(_, __, m: Message): return True if len(m.command) == 1 else False -@Client.on_message(filters.private & filters.command('caption') & filters.user(client.config.AUTH_USERS)) +@Client.on_message(filters.private & filters.command('caption') & client.filters.auth_users) async def custom_caption(bot: Client, update: Message): if client.database: user = await client.database.xurluploader.users.find_one({'id': update.from_user.id}) @@ -34,7 +34,7 @@ async def custom_caption(bot: Client, update: Message): client.custom_caption[update.from_user.id] = caption -@Client.on_message(filters.private & filters.command('thumbnail') & ~filters.reply & (filters.regex(pattern=URL_REGEX) | filters.create(no_args_filter)) & filters.user(client.config.AUTH_USERS)) +@Client.on_message(filters.private & filters.command('thumbnail') & ~filters.reply & (filters.regex(pattern=URL_REGEX) | filters.create(no_args_filter)) & client.filters.auth_users) async def custom_thumbnail(bot: Client, update: Message): if client.database: user = await client.database.xurluploader.users.find_one({'id': update.from_user.id}) @@ -59,7 +59,7 @@ async def custom_thumbnail(bot: Client, update: Message): client.custom_thumbnail[update.from_user.id] = thumbnail -@Client.on_message(filters.private & filters.command('thumbnail') & filters.reply & filters.create(reply_to_photo_filter) & filters.user(client.config.AUTH_USERS)) +@Client.on_message(filters.private & filters.command('thumbnail') & filters.reply & filters.create(reply_to_photo_filter) & client.filters.auth_users) async def custom_thumbnail_reply(bot: Client, update: Message): client.custom_thumbnail[update.from_user.id] = await update.reply_to_message.download(file_name=f'{client.config.DOWNLOAD_LOCATION}/{update.from_user.id}.jpg') await update.reply(text='Custom thumbnail updated.')