diff --git a/userbot/images/icons.py b/userbot/images/icons.py index a621147..f9859b1 100644 --- a/userbot/images/icons.py +++ b/userbot/images/icons.py @@ -12,7 +12,7 @@ from utils.misc import modules_help, prefix @Client.on_message(filters.command('icon', prefix) & filters.me) async def search_icon(_, message: Message): - if not len(message.command) == 2: + if len(message.command) != 2: return await message.edit_text('Please provide some text to search icons from Flaticon.com.') query = message.text.split(maxsplit=1)[1] diff --git a/userbot/main.py b/userbot/main.py index 451e45c..847514f 100644 --- a/userbot/main.py +++ b/userbot/main.py @@ -39,6 +39,7 @@ # "pySmartDL", # ] # /// +import contextlib import logging import os import platform @@ -151,10 +152,8 @@ async def main(): 'restart': 'Restart completed!', 'update': 'Update process completed!', }[info['type']] - try: + with contextlib.suppress(errors.RPCError): await app.edit_message_text(info['chat_id'], info['message_id'], text) - except errors.RPCError: - pass db.remove('core.updater', 'restart_info') # required for sessionkiller module diff --git a/userbot/modules/1000-7.py b/userbot/modules/1000-7.py index 08740b7..d77f3c3 100644 --- a/userbot/modules/1000-7.py +++ b/userbot/modules/1000-7.py @@ -15,10 +15,7 @@ def prettify(val: int) -> str: async def ghoul_counter(_, message: Message): await message.delete() - if len(message.command) > 1 and message.command[1].isdigit(): - counter = int(message.command[1]) - else: - counter = 1000 + counter = int(message.command[1]) if len(message.command) > 1 and message.command[1].isdigit() else 1000 msg = await message.reply(prettify(counter), quote=False) diff --git a/userbot/modules/afk.py b/userbot/modules/afk.py index 4794225..536a69d 100644 --- a/userbot/modules/afk.py +++ b/userbot/modules/afk.py @@ -47,10 +47,7 @@ async def afk_handler(_, message: types.Message): @Client.on_message(filters.command('afk', prefix) & filters.me) async def afk(_, message): - if len(message.text.split()) >= 2: - reason = message.text.split(' ', maxsplit=1)[1] - else: - reason = 'None' + reason = message.text.split(' ', maxsplit=1)[1] if len(message.text.split()) >= 2 else 'None' afk_info['start'] = int(datetime.datetime.now().timestamp()) afk_info['is_afk'] = True diff --git a/userbot/modules/amongus.py b/userbot/modules/amongus.py index addb938..054abb5 100644 --- a/userbot/modules/amongus.py +++ b/userbot/modules/amongus.py @@ -108,10 +108,7 @@ async def imposter_cmd(client: Client, message: Message): text = f'{user.first_name} {choice(imps)}.' else: args = message.text.split()[1:] - if args: - text = ' '.join(args) - else: - text = f'{message.from_user.first_name} {choice(imps)}.' + text = ' '.join(args) if args else f'{message.from_user.first_name} {choice(imps)}.' text += f'\n{remain} impostor(s) remain.' imposter_file = await get_imposter_img(text) @@ -128,10 +125,7 @@ async def imp_animation(client: Client, message: Message): name = ' '.join(message.command[1:]) if len(message.command) > 1 else '' if not name: reply = message.reply_to_message - if reply: - name = reply.from_user.first_name - else: - name = message.from_user.first_name + name = reply.from_user.first_name if reply else message.from_user.first_name cmd = message.command[0].lower() text1 = await edit_or_reply(message, 'Uhmm... Something is wrong here!!') diff --git a/userbot/modules/cdxl.py b/userbot/modules/cdxl.py index a869d75..5d4af81 100644 --- a/userbot/modules/cdxl.py +++ b/userbot/modules/cdxl.py @@ -24,7 +24,7 @@ async def cdxl(c: Client, message: Message): await message.edit_text(f'Usage: {prefix}vdxl [prompt/reply to prompt]') return - inference_params = dict(width=1024, height=1024, steps=50, cfg_scale=9.0) + inference_params = {'width': 1024, 'height': 1024, 'steps': 50, 'cfg_scale': 9.0} model_prediction = Model( 'https://clarifai.com/stability-ai/stable-diffusion-2/models/stable-diffusion-xl' diff --git a/userbot/modules/filters.py b/userbot/modules/filters.py index 95e68a7..bda36d6 100644 --- a/userbot/modules/filters.py +++ b/userbot/modules/filters.py @@ -36,7 +36,7 @@ def set_filters_chat(chat_id, filters_): async def contains_filter(_, __, m): - return m.text and m.text.lower() in get_filters_chat(m.chat.id).keys() + return m.text and m.text.lower() in get_filters_chat(m.chat.id) contains = filters.create(contains_filter) @@ -115,7 +115,7 @@ async def filter_handler(client: Client, message: Message): return await message.edit(f'Usage: {prefix}filter [name] (Reply required)') name = message.text.split(maxsplit=1)[1].lower() chat_filters = get_filters_chat(message.chat.id) - if name in chat_filters.keys(): + if name in chat_filters: return await message.edit(f'Filter {name} already exists.') if not message.reply_to_message: return await message.edit('Reply to message please.') @@ -186,7 +186,7 @@ async def filter_del_handler(_, message: Message): ) name = message.text.split(maxsplit=1)[1].lower() chat_filters = get_filters_chat(message.chat.id) - if name not in chat_filters.keys(): + if name not in chat_filters: return await message.edit( f"Filter {name} doesn't exists.", ) @@ -208,7 +208,7 @@ async def filter_search_handler(_, message: Message): ) name = message.text.split(maxsplit=1)[1].lower() chat_filters = get_filters_chat(message.chat.id) - if name not in chat_filters.keys(): + if name not in chat_filters: return await message.edit( f"Filter {name} doesn't exists.", ) diff --git a/userbot/modules/fliptext.py b/userbot/modules/fliptext.py index 619de2a..b85f36a 100644 --- a/userbot/modules/fliptext.py +++ b/userbot/modules/fliptext.py @@ -89,10 +89,7 @@ async def flip(client: Client, message: Message): text = ' '.join(message.command[1:]) final_str = '' for char in text: - if char in REPLACEMENT_MAP: - new_char = REPLACEMENT_MAP[char] - else: - new_char = char + new_char = REPLACEMENT_MAP.get(char, char) final_str += new_char if text != final_str: await message.edit(final_str) diff --git a/userbot/modules/help.py b/userbot/modules/help.py index 4089299..01aea3a 100644 --- a/userbot/modules/help.py +++ b/userbot/modules/help.py @@ -34,7 +34,7 @@ async def help_cmd(_, message: Message): command_name = message.command[1].lower() module_found = False for module_name, commands in modules_help.items(): - for command in commands.keys(): + for command in commands: if command.split()[0] == command_name: cmd = command.split(maxsplit=1) cmd_desc = commands[command] diff --git a/userbot/modules/misc/cama.py b/userbot/modules/misc/cama.py index a61f490..e1d3fd4 100644 --- a/userbot/modules/misc/cama.py +++ b/userbot/modules/misc/cama.py @@ -25,7 +25,7 @@ def get_marine_life_details(species_name): species = observation['taxon']['name'] common_name = observation['taxon']['preferred_common_name'] photo_url = observation['photos'][0]['url'] if observation['photos'] else 'No photo available' - description = observation['description'] if 'description' in observation else 'No description available.' + description = observation.get('description', 'No description available.') return { 'species': species, 'common_name': common_name, diff --git a/userbot/modules/misc/safone.py b/userbot/modules/misc/safone.py index e54c0a2..209a137 100644 --- a/userbot/modules/misc/safone.py +++ b/userbot/modules/misc/safone.py @@ -16,9 +16,12 @@ import base64 import os +from io import BytesIO import aiofiles +import aiohttp import requests +from PIL import Image, ImageEnhance from pyrogram import Client, enums, filters from pyrogram.errors import MediaCaptionTooLong, MessageTooLong from pyrogram.types import InputMediaPhoto, Message diff --git a/userbot/modules/misc/sarethai.py b/userbot/modules/misc/sarethai.py index 275a2ae..046c6ce 100644 --- a/userbot/modules/misc/sarethai.py +++ b/userbot/modules/misc/sarethai.py @@ -15,6 +15,7 @@ #  along with this program.  If not, see . import asyncio +import contextlib import os import requests @@ -101,10 +102,8 @@ async def delete_search_data(client, chat_id, message_id): search_key = f'{chat_id}_{key}' if search_key in search_results and search_results[search_key]['message_id'] == message_id: del search_results[search_key] - try: + with contextlib.suppress(BaseException): await client.delete_messages(chat_id, message_id) - except: - pass break diff --git a/userbot/modules/notes.py b/userbot/modules/notes.py index 216a945..98f8334 100644 --- a/userbot/modules/notes.py +++ b/userbot/modules/notes.py @@ -105,7 +105,7 @@ async def notes(_, message: Message): await message.edit('Loading...') text = 'Available notes:\n\n' collection = db.get_collection('core.notes') - for note in collection.keys(): + for note in collection: if note[:4] == 'note': text += f'{note[4:]}\n' await message.edit(text) diff --git a/userbot/modules/pdf2md.py b/userbot/modules/pdf2md.py index d5cba9e..6cb5249 100644 --- a/userbot/modules/pdf2md.py +++ b/userbot/modules/pdf2md.py @@ -28,7 +28,7 @@ async def pdf2md(client: Client, message: Message): if not message.reply_to_message.document: await message.edit('Reply to a pdf file') return - if not message.reply_to_message.document.mime_type == 'application/pdf': + if message.reply_to_message.document.mime_type != 'application/pdf': await message.edit('Reply to a pdf file') return if gemini_key == '': diff --git a/userbot/modules/perfectrussian.py b/userbot/modules/perfectrussian.py index 568663e..c15d112 100644 --- a/userbot/modules/perfectrussian.py +++ b/userbot/modules/perfectrussian.py @@ -25,7 +25,7 @@ async def prussian_cmd(_, message: Message): splitted = message.reply_to_message.text.split() for i in range(0, len(splitted), random.randint(2, 3)): - for j in range(1, 2): + for _j in range(1, 2): splitted.insert(i, random.choice(words)) await message.edit(' '.join(splitted), parse_mode=enums.ParseMode.HTML) diff --git a/userbot/modules/spin.py b/userbot/modules/spin.py index e3c942b..1636f3f 100644 --- a/userbot/modules/spin.py +++ b/userbot/modules/spin.py @@ -101,10 +101,7 @@ async def spin_handler(client: Client, message: Message): filename = 'sticker.webp' elif message.reply_to_message.text: result = await quote_cmd(client, message) - if result[1]: - filename = 'sticker.png' - else: - filename = 'sticker.webp' + filename = 'sticker.png' if result[1] else 'sticker.webp' open('downloads/' + filename, 'wb').write(result[0].getbuffer()) coro = False else: diff --git a/userbot/modules/stickers.py b/userbot/modules/stickers.py index b1430eb..d310280 100644 --- a/userbot/modules/stickers.py +++ b/userbot/modules/stickers.py @@ -40,10 +40,7 @@ async def kang(client: Client, message: types.Message): return pack = message.command[1] - if len(message.command) >= 3: - emoji = message.command[2] - else: - emoji = '✨' + emoji = message.command[2] if len(message.command) >= 3 else '✨' await client.unblock_user('@stickers') await interact_with(await client.send_message('@stickers', '/cancel', parse_mode=enums.ParseMode.MARKDOWN)) diff --git a/userbot/modules/user_info.py b/userbot/modules/user_info.py index a79bb3b..0f458a1 100644 --- a/userbot/modules/user_info.py +++ b/userbot/modules/user_info.py @@ -35,10 +35,7 @@ async def get_user_inf(client: Client, message: Message): user = response.users[0] full_user = response.full_user - if user.username is None: - username = 'None' - else: - username = f'@{user.username}' + username = 'None' if user.username is None else f'@{user.username}' about = 'None' if full_user.about is None else full_user.about user_info = f"""|=Username: {username} @@ -79,10 +76,7 @@ async def get_full_user_inf(client: Client, message: Message): # await client.delete_messages("@creationdatebot", interact_with_to_delete) interact_with_to_delete.clear() - if user.username is None: - username = 'None' - else: - username = f'@{user.username}' + username = 'None' if user.username is None else f'@{user.username}' about = 'None' if full_user.about is None else full_user.about user_info = f"""|=Username: {username} |-Id: {user.id} diff --git a/userbot/utils/module.py b/userbot/utils/module.py index 515c064..61bfb9c 100644 --- a/userbot/utils/module.py +++ b/userbot/utils/module.py @@ -59,7 +59,7 @@ class HelpNavigator: text += f'Help Page No: {self.current_page}/{self.total_pages}\n\n' for module_name in page_modules: commands = modules_help[module_name] - text += f'• {module_name.title()}: {", ".join([f"{prefix + cmd_name.split()[0]}" for cmd_name in commands.keys()])}\n' + text += f'• {module_name.title()}: {", ".join([f"{prefix + cmd_name.split()[0]}" for cmd_name in commands])}\n' text += f'\nThe number of modules in the userbot: {len(modules_help)}' await message.edit(text, disable_web_page_preview=True) diff --git a/userbot/utils/scripts.py b/userbot/utils/scripts.py index 88fea6e..76d8e6a 100644 --- a/userbot/utils/scripts.py +++ b/userbot/utils/scripts.py @@ -484,9 +484,7 @@ async def unload_module(module_name: str, client: Client) -> bool: def no_prefix(handler): def func(_, __, message): - if message.text and not message.text.startswith(handler): - return True - return False + return bool(message.text and not message.text.startswith(handler)) return filters.create(func)