From 5ea997215d39df3df538c5b6ec5fbdb10d052a58 Mon Sep 17 00:00:00 2001 From: X-Gorn Date: Sun, 9 Jun 2024 18:37:17 +0900 Subject: [PATCH] fix: circular import --- .gitignore | 7 +++---- Bot/clients.py | 2 -- Bot/{ => functions}/filters.py | 0 Bot/plugins/admin.py | 9 +++++---- Bot/plugins/commands.py | 5 +++-- Bot/plugins/echo.py | 3 ++- Bot/plugins/settings.py | 7 ++++--- 7 files changed, 17 insertions(+), 16 deletions(-) rename Bot/{ => functions}/filters.py (100%) diff --git a/.gitignore b/.gitignore index 944afc7..d03529d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -# venv +__pycache__ .venv - -# env -.env \ No newline at end of file +.env +*.session \ No newline at end of file diff --git a/Bot/clients.py b/Bot/clients.py index 2a6c1df..23c875e 100644 --- a/Bot/clients.py +++ b/Bot/clients.py @@ -7,13 +7,11 @@ from typing import Union from .config import Config from .translation import Translation -from .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/filters.py b/Bot/functions/filters.py similarity index 100% rename from Bot/filters.py rename to Bot/functions/filters.py diff --git a/Bot/plugins/admin.py b/Bot/plugins/admin.py index 058d35d..f4d4094 100644 --- a/Bot/plugins/admin.py +++ b/Bot/plugins/admin.py @@ -3,9 +3,10 @@ from pyrogram import Client, filters from pyrogram.types import Message from pyrogram.errors import FloodWait, Forbidden, BadRequest +from ..functions.filters import Filter -@Client.on_message(filters.private & filters.command('broadcast') & filters.reply & client.filters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('broadcast') & filters.reply & Filter.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({}): @@ -25,12 +26,12 @@ async def broadcast(bot: Client, update: Message): await message.edit(text='Broadcast done.') -@Client.on_message(filters.private & filters.command('broadcast') & ~filters.reply & client.filters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('broadcast') & ~filters.reply & Filter.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') & client.filters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('ban') & Filter.database & filters.user(users=client.config.OWNER_ID)) async def ban(bot: Client, update: Message): try: user_id = int(update.command[1]) @@ -46,7 +47,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') & client.filters.database & filters.user(users=client.config.OWNER_ID)) +@Client.on_message(filters.private & filters.command('unban') & Filter.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 66196f0..7265dcf 100644 --- a/Bot/plugins/commands.py +++ b/Bot/plugins/commands.py @@ -5,10 +5,11 @@ from pyrogram import Client, filters from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup +from ..functions.filters import Filter from .. import client -@Client.on_message(filters.private & filters.command("help") & client.filters.auth_users) +@Client.on_message(filters.private & filters.command("help") & Filter.auth_users) async def help(bot: Client, update: Message): await bot.send_message( chat_id=update.chat.id, @@ -18,7 +19,7 @@ async def help(bot: Client, update: Message): ) -@Client.on_message(filters.private & filters.command("start") & client.filters.auth_users) +@Client.on_message(filters.private & filters.command("start") & Filter.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 79cdd9b..cd9144b 100644 --- a/Bot/plugins/echo.py +++ b/Bot/plugins/echo.py @@ -13,6 +13,7 @@ from PIL import Image from ..functions.download import download_coroutine from ..functions.display_progress import humanbytes +from ..functions.filters import Filter from .. import client @@ -21,7 +22,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) & client.filters.auth_users) +@Client.on_message(filters.private & filters.regex(pattern=URL_REGEX) & Filter.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 1512260..1b849d0 100644 --- a/Bot/plugins/settings.py +++ b/Bot/plugins/settings.py @@ -2,6 +2,7 @@ from pyrogram import Client, filters from pyrogram.types import Message from ..functions.helper import URL_REGEX, run_cmd +from ..functions.filters import Filter async def reply_to_photo_filter(_, __, m: Message): @@ -12,7 +13,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') & client.filters.auth_users) +@Client.on_message(filters.private & filters.command('caption') & Filter.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 +35,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)) & client.filters.auth_users) +@Client.on_message(filters.private & filters.command('thumbnail') & ~filters.reply & (filters.regex(pattern=URL_REGEX) | filters.create(no_args_filter)) & Filter.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 +60,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) & client.filters.auth_users) +@Client.on_message(filters.private & filters.command('thumbnail') & filters.reply & filters.create(reply_to_photo_filter) & Filter.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.')