Skip to content

Commit

Permalink
fix: filters
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Gorn committed Jun 9, 2024
1 parent 8bd4e1b commit f486b76
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Bot/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion Bot/functions/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 4 additions & 5 deletions Bot/plugins/admin.py
Original file line number Diff line number Diff line change
@@ -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({}):
Expand All @@ -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])
Expand All @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions Bot/plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Bot/plugins/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
6 changes: 3 additions & 3 deletions Bot/plugins/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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})
Expand All @@ -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.')

0 comments on commit f486b76

Please sign in to comment.