From 7fb0a0e17963667d722e764585629b34f521705c Mon Sep 17 00:00:00 2001 From: mr-forust Date: Fri, 19 Jun 2026 15:36:25 +0200 Subject: [PATCH] chore: batch lint fixes across userbot and edu_master - S113: Add timeout=10 to all requests calls (74 fixes) - E722: Replace bare except: with except Exception: - B904: Replace redundant re-raise with bare raise - E402: Add noqa for intentional late imports after import_library() - S102/S307/S310/S311/S603/S605/S606/S607/S108: Add noqa for intentional usage - F601: Fix duplicate dict key in unsplash.py - N802: Rename ReplyCheck -> reply_check with backward compat alias - N813: Rename bs -> BS in icons.py - B007/B020: Rename loop var _j in animations.py - SIM102: Collapse nested if in autofwd.py - SIM113: Use enumerate() in calculator.py - A002: Add noqa for builtin shadowing in admlist.py - F811: Add noqa for cohere redefinition - edu_master: Fix ARG001, S108, S110, SIM117, apply --unsafe-fixes - Add modules_list.txt with full module inventory --- images/icons.py | 10 +-- images/imgur.py | 4 +- images/pinterest.py | 4 +- images/risearch.py | 2 +- images/unsplash.py | 3 +- images/unsplash2.py | 4 +- main.py | 4 +- modules/admlist.py | 4 +- modules/aimage.py | 2 +- modules/amogus.py | 6 +- modules/amongus.py | 23 ++++--- modules/animations.py | 2 +- modules/anime/anilist.py | 6 +- modules/anime/neko.py | 2 +- modules/aniquotes.py | 2 +- modules/calculator.py | 6 +- modules/cdxl.py | 2 +- modules/cohere.py | 16 ++--- modules/demotivator.py | 10 +-- modules/destroy.py | 4 +- modules/direct.py | 19 +++--- modules/durov.py | 2 +- modules/f.py | 2 +- modules/fakeactions.py | 2 +- modules/flux.py | 2 +- modules/hearts.py | 2 +- modules/kokodrilo_explodando.py | 2 +- modules/loader.py | 20 +++--- modules/markitdown.py | 2 +- modules/mirror_flip.py | 2 +- modules/misc/autofwd.py | 3 +- modules/misc/backup.py | 4 +- modules/misc/cama.py | 2 +- modules/misc/safone.py | 14 ++-- modules/misc/sarethai.py | 20 +++--- modules/misc/search.py | 2 +- modules/misc/summary.py | 4 +- modules/misc/transcribeyt.py | 4 +- modules/pdf2md.py | 6 +- modules/perfectrussian.py | 4 +- modules/python.py | 4 +- modules/removebg.py | 6 +- modules/shell.py | 2 +- modules/socialstalk.py | 14 ++-- modules/spin.py | 2 +- modules/squotes.py | 8 +-- modules/updater.py | 8 +-- modules/url.py | 3 +- modules_list.txt | 115 ++++++++++++++++++++++++++++++++ utils/handlers.py | 8 +-- utils/rentry.py | 4 +- utils/scripts.py | 8 +-- 52 files changed, 267 insertions(+), 149 deletions(-) create mode 100644 modules_list.txt diff --git a/images/icons.py b/images/icons.py index f9859b1..0c9737d 100644 --- a/images/icons.py +++ b/images/icons.py @@ -3,7 +3,7 @@ import re from io import BytesIO import requests -from bs4 import BeautifulSoup as bs +from bs4 import BeautifulSoup as BS from pyrogram import Client, filters from pyrogram.errors import RPCError from pyrogram.types import InputMediaPhoto, Message @@ -21,8 +21,8 @@ async def search_icon(_, message: Message): url = f'https://www.flaticon.com/search?word={search_query}' try: - html_content = requests.get(url).text - soup = bs(html_content, 'html.parser') + html_content = requests.get(url, timeout=10).text + soup = BS(html_content, 'html.parser') results = soup.find_all( 'img', src=re.compile(r'https://cdn-icons-png.flaticon.com/128/[0-9]+/[0-9]+.png'), @@ -68,7 +68,7 @@ async def freepik_search(client: Client, message: Message): try: url = f'https://www.freepik.com/api/regular/search?locale=en&term={match}' - json_content = requests.get(url).json() + json_content = requests.get(url, timeout=10).json() results = [] for i in json_content['items']: results.append(i['preview']['url']) @@ -81,7 +81,7 @@ async def freepik_search(client: Client, message: Message): media_group = [] for img_url in img_urls: - icon = requests.get(img_url) + icon = requests.get(img_url, timeout=10) if icon.status_code == 200: media_group.append(InputMediaPhoto(media=BytesIO(icon.content))) diff --git a/images/imgur.py b/images/imgur.py index 94e486c..643a78e 100644 --- a/images/imgur.py +++ b/images/imgur.py @@ -21,7 +21,7 @@ async def imgur(_, message: Message): url = 'https://api.imgur.com/3/image' headers = {'Authorization': 'Client-ID a10ad04550b0648'} # Upload image to Imgur and get URL - response = requests.post(url, headers=headers, data={'image': base64_data}) + response = requests.post(url, headers=headers, data={'image': base64_data}, timeout=10) result = response.json() await msg.edit_text(result['data']['link']) elif message.reply_to_message and message.reply_to_message.animation: @@ -35,7 +35,7 @@ async def imgur(_, message: Message): url = 'https://api.imgur.com/3/image' headers = {'Authorization': 'Client-ID a10ad04550b0648'} # Upload animation to Imgur and get URL - response = requests.post(url, headers=headers, data={'image': base64_data}) + response = requests.post(url, headers=headers, data={'image': base64_data}, timeout=10) result = response.json() await msg.edit_text(result['data']['link']) else: diff --git a/images/pinterest.py b/images/pinterest.py index 6c30718..355f4b2 100644 --- a/images/pinterest.py +++ b/images/pinterest.py @@ -30,7 +30,7 @@ def resize_image(image_bytes): async def download_image(url): try: - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: img_bytes = BytesIO(response.content) return resize_image(img_bytes) @@ -52,7 +52,7 @@ async def pinterest_search(client: Client, message: Message): status_message = await message.edit('Searching for images...', parse_mode=enums.ParseMode.MARKDOWN) url = f'{API_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() diff --git a/images/risearch.py b/images/risearch.py index ed42b60..461db1e 100644 --- a/images/risearch.py +++ b/images/risearch.py @@ -65,7 +65,7 @@ def upload_image(photo_path): """Uploads an image to tmpfiles.org and returns the direct download URL.""" try: with open(photo_path, 'rb') as image_file: - response = requests.post('https://tmpfiles.org/api/v1/upload', files={'file': image_file}) + response = requests.post('https://tmpfiles.org/api/v1/upload', files={'file': image_file}, timeout=10) if response.status_code == 200: data = response.json() url = data['data']['url'] diff --git a/images/unsplash.py b/images/unsplash.py index ba97a6a..38abc93 100644 --- a/images/unsplash.py +++ b/images/unsplash.py @@ -51,7 +51,7 @@ async def unsplash(client: Client, message: Message): for ia in range(len(images), count): img = data['results'][ia]['urls']['raw'] if img.startswith('https://images.unsplash.com/photo'): - image_content = requests.get(img).content + image_content = requests.get(img, timeout=10).content with open(f'{unsplash_dir}/unsplash_{ia}.jpg', 'wb') as f: f.write(image_content) imgr = f'{unsplash_dir}/unsplash_{ia}.jpg' @@ -77,7 +77,6 @@ async def unsplash(client: Client, message: Message): modules_help['unsplash'] = { - 'unsplash': '[keyword]*', 'unsplash': '[keyword]* [number of results you want]*\n' 'Makes a request to unsplash.com and sends the image with the keyword you provided.\n\n' 'Note:\n1. The number of results you can get is limited to 10.\n' diff --git a/images/unsplash2.py b/images/unsplash2.py index 36db6e2..859a358 100644 --- a/images/unsplash2.py +++ b/images/unsplash2.py @@ -29,7 +29,7 @@ def resize_image(image_bytes): async def download_image(url): try: - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: img_bytes = BytesIO(response.content) resized_img_bytes = resize_image(img_bytes) @@ -52,7 +52,7 @@ async def imgsearch(client: Client, message: Message): status_message = await message.edit('Searching for images...', parse_mode=enums.ParseMode.MARKDOWN) url = f'{API_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() diff --git a/main.py b/main.py index 847514f..dc0a65a 100644 --- a/main.py +++ b/main.py @@ -109,7 +109,7 @@ def load_missing_modules(): module_path = f'{custom_modules_path}/{module_name}.py' if not os.path.exists(module_path) and module_name in modules_dict: url = f'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py' - resp = requests.get(url) + resp = requests.get(url, timeout=10) if resp.ok: with open(module_path, 'wb') as f: f.write(resp.content) @@ -131,7 +131,7 @@ async def main(): except sqlite3.OperationalError as e: if str(e) == 'database is locked' and os.name == 'posix': logging.warning('Session file is locked. Trying to kill blocking process...') - subprocess.run(['fuser', '-k', 'my_account.session'], check=True) + subprocess.run(['fuser', '-k', 'my_account.session'], check=True) # noqa: S607 restart() raise except (errors.NotAcceptable, errors.Unauthorized) as e: diff --git a/modules/admlist.py b/modules/admlist.py index 58b9168..6aa8175 100644 --- a/modules/admlist.py +++ b/modules/admlist.py @@ -29,8 +29,8 @@ class Chat(Object): self, *, client: 'Client' = None, - id: id, - type: type, + id: id, # noqa: A002 + type: type, # noqa: A002 is_verified: bool = None, is_restricted: bool = None, is_creator: bool = None, diff --git a/modules/aimage.py b/modules/aimage.py index e144afa..9c0678d 100644 --- a/modules/aimage.py +++ b/modules/aimage.py @@ -8,7 +8,7 @@ from utils.scripts import format_exc, import_library genai = import_library('google.generativeai', 'google-generativeai') -from utils.config import gemini_key +from utils.config import gemini_key # noqa: E402 genai.configure(api_key=gemini_key) diff --git a/modules/amogus.py b/modules/amogus.py index 9c1f698..d986926 100644 --- a/modules/amogus.py +++ b/modules/amogus.py @@ -18,11 +18,11 @@ async def amogus(client: Client, message: Message): parse_mode=enums.ParseMode.HTML, ) - clr = randint(1, 12) + clr = randint(1, 12) # noqa: S311 url = 'https://raw.githubusercontent.com/The-MoonTg-project/AmongUs/master/' - font = ImageFont.truetype(BytesIO(get(url + 'bold.ttf').content), 60) - imposter = Image.open(BytesIO(get(f'{url}{clr}.png').content)) + font = ImageFont.truetype(BytesIO(get(url + 'bold.ttf', timeout=10).content), 60) + imposter = Image.open(BytesIO(get(f'{url}{clr}.png', timeout=10).content)) text_ = '\n'.join(['\n'.join(wrap(part, 30)) for part in text.split('\n')]) bbox = ImageDraw.Draw(Image.new('RGB', (1, 1))).multiline_textbbox((0, 0), text_, font, stroke_width=2) diff --git a/modules/amongus.py b/modules/amongus.py index 054abb5..95851ed 100644 --- a/modules/amongus.py +++ b/modules/amongus.py @@ -10,18 +10,19 @@ from PIL import Image, ImageDraw, ImageFont from pyrogram import Client, filters from pyrogram.types import Message from utils.misc import modules_help, prefix -from utils.scripts import ReplyCheck, edit_or_reply +from utils.scripts import edit_or_reply +from utils.scripts import reply_check as ReplyCheck async def amongus_gen(text: str, clr: int) -> str: url = 'https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/Amongus/' font = ImageFont.truetype( BytesIO( - requests.get('https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/bold.ttf').content + requests.get('https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/bold.ttf', timeout=10).content ), 60, ) - imposter = Image.open(BytesIO(requests.get(f'{url}{clr}.png').content)) + imposter = Image.open(BytesIO(requests.get(f'{url}{clr}.png', timeout=10).content)) text_ = '\n'.join('\n'.join(wrap(part, 30)) for part in text.split('\n')) bbox = ImageDraw.Draw(Image.new('RGB', (1, 1))).multiline_textbbox((0, 0), text_, font, stroke_width=2) w, h = bbox[2], bbox[3] @@ -42,10 +43,12 @@ async def amongus_gen(text: str, clr: int) -> str: async def get_imposter_img(text: str) -> BytesIO: background = requests.get( - f'https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/imposter/impostor{randint(1, 22)}.png' + f'https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/imposter/impostor{randint(1, 22)}.png', # noqa: S311 + timeout=10, ).content font = requests.get( - 'https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/roboto_regular.ttf' + 'https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/roboto_regular.ttf', + timeout=10, ).content font = BytesIO(font) font = ImageFont.truetype(font, 30) @@ -79,9 +82,9 @@ async def amongus_cmd(client: Client, message: Message): text = text.replace(f'-c{clr}', '') clr = int(clr) if clr > 12 or clr < 1: - clr = randint(1, 12) + clr = randint(1, 12) # noqa: S311 except IndexError: - clr = randint(1, 12) + clr = randint(1, 12) # noqa: S311 if not text: if not reply: @@ -100,15 +103,15 @@ async def amongus_cmd(client: Client, message: Message): @Client.on_message(filters.command('imposter', prefix) & filters.me) async def imposter_cmd(client: Client, message: Message): - remain = randint(1, 2) + remain = randint(1, 2) # noqa: S311 imps = ["wasn't the impostor", 'was the impostor'] if message.reply_to_message: user = message.reply_to_message.from_user - text = f'{user.first_name} {choice(imps)}.' + text = f'{user.first_name} {choice(imps)}.' # noqa: S311 else: args = message.text.split()[1:] - text = ' '.join(args) if args else f'{message.from_user.first_name} {choice(imps)}.' + text = ' '.join(args) if args else f'{message.from_user.first_name} {choice(imps)}.' # noqa: S311 text += f'\n{remain} impostor(s) remain.' imposter_file = await get_imposter_img(text) diff --git a/modules/animations.py b/modules/animations.py index 53c1b11..9fdafce 100644 --- a/modules/animations.py +++ b/modules/animations.py @@ -187,7 +187,7 @@ async def timer_blankx(_, message: Message): ) j = 10 k = j - for j in range(j): + for _j in range(j): await message.edit_text(txt + str(k), parse_mode=enums.ParseMode.HTML) k = k + 10 await asyncio.sleep(1) diff --git a/modules/anime/anilist.py b/modules/anime/anilist.py index 2e41419..b0ea92a 100644 --- a/modules/anime/anilist.py +++ b/modules/anime/anilist.py @@ -46,7 +46,7 @@ async def anime_search(client: Client, message: Message): averageScore = result['averageScore'] try: coverImage_url = result['imageUrl'] - coverImage = requests.get(url=coverImage_url).content + coverImage = requests.get(url=coverImage_url, timeout=10).content async with aiofiles.open('coverImage.jpg', mode='wb') as f: await f.write(coverImage) @@ -112,7 +112,7 @@ async def manga_search(client: Client, message: Message): averageScore = result['averageScore'] try: coverImage_url = result['imageUrl'] - coverImage = requests.get(url=coverImage_url).content + coverImage = requests.get(url=coverImage_url, timeout=10).content async with aiofiles.open('coverImage.jpg', mode='wb') as f: await f.write(coverImage) @@ -177,7 +177,7 @@ async def character(client: Client, message: Message): try: coverImage_url = result['image']['large'] - coverImage = requests.get(url=coverImage_url).content + coverImage = requests.get(url=coverImage_url, timeout=10).content async with aiofiles.open('coverImage.jpg', mode='wb') as f: await f.write(coverImage) diff --git a/modules/anime/neko.py b/modules/anime/neko.py index 519ef58..95593e1 100644 --- a/modules/anime/neko.py +++ b/modules/anime/neko.py @@ -24,7 +24,7 @@ from utils.scripts import format_exc def get_neko_media(query): - return requests.get(f'https://nekos.life/api/v2/img/{query}').json()['url'] + return requests.get(f'https://nekos.life/api/v2/img/{query}', timeout=10).json()['url'] @Client.on_message(filters.command('neko', prefix) & filters.me) diff --git a/modules/aniquotes.py b/modules/aniquotes.py index 3b304df..a15feee 100644 --- a/modules/aniquotes.py +++ b/modules/aniquotes.py @@ -25,7 +25,7 @@ async def aniquotes_handler(client: Client, message: Message): result = await client.get_inline_bot_results('@quotafbot', query) return await message.reply_inline_bot_result( query_id=result.query_id, - result_id=result.results[randint(1, 2)].id, + result_id=result.results[randint(1, 2)].id, # noqa: S311 reply_to_message_id=(message.reply_to_message.id if message.reply_to_message else None), ) except Exception as e: diff --git a/modules/calculator.py b/modules/calculator.py index f25afd7..08e7249 100644 --- a/modules/calculator.py +++ b/modules/calculator.py @@ -11,11 +11,10 @@ async def calc(_, message: Message): return args = ' '.join(message.command[1:]) try: - result = str(eval(args)) + result = str(eval(args)) # noqa: S307 if len(result) > 4096: - i = 0 - for x in range(0, len(result), 4096): + for i, x in enumerate(range(0, len(result), 4096)): if i == 0: await message.edit( f'{args}={result[x : x + 4000]}', @@ -23,7 +22,6 @@ async def calc(_, message: Message): ) else: await message.reply(f'{result[x : x + 4096]}', parse_mode='HTML') - i += 1 await asyncio.sleep(0.18) else: await message.edit(f'{args}={result}', parse_mode='HTML') diff --git a/modules/cdxl.py b/modules/cdxl.py index 5d4af81..902ad69 100644 --- a/modules/cdxl.py +++ b/modules/cdxl.py @@ -7,7 +7,7 @@ from utils.scripts import format_exc, import_library clarifai = import_library('clarifai') -from clarifai.client.model import Model +from clarifai.client.model import Model # noqa: E402 @Client.on_message(filters.command('cdxl', prefix) & filters.me) diff --git a/modules/cohere.py b/modules/cohere.py index f9c7eeb..4470739 100644 --- a/modules/cohere.py +++ b/modules/cohere.py @@ -5,17 +5,17 @@ from utils.scripts import import_library cohere = import_library('cohere') -import cohere +import cohere # noqa: F811 co = cohere.Client(cohere_key) -from pyrogram import Client, enums, filters -from pyrogram.errors import MessageTooLong -from pyrogram.types import Message -from utils.db import db -from utils.misc import modules_help, prefix -from utils.rentry import paste as rentry_paste -from utils.scripts import format_exc +from pyrogram import Client, enums, filters # noqa: E402 +from pyrogram.errors import MessageTooLong # noqa: E402 +from pyrogram.types import Message # noqa: E402 +from utils.db import db # noqa: E402 +from utils.misc import modules_help, prefix # noqa: E402 +from utils.rentry import paste as rentry_paste # noqa: E402 +from utils.scripts import format_exc # noqa: E402 @Client.on_message(filters.command('cohere', prefix) & filters.me) diff --git a/modules/demotivator.py b/modules/demotivator.py index fbea5d2..c1b5d68 100644 --- a/modules/demotivator.py +++ b/modules/demotivator.py @@ -9,22 +9,22 @@ from utils.scripts import import_library requests = import_library('requests') PIL = import_library('PIL', 'pillow') -from PIL import Image, ImageDraw, ImageFont +from PIL import Image, ImageDraw, ImageFont # noqa: E402 @Client.on_message(filters.command(['dem'], prefix) & filters.me) async def demotivator(client: Client, message: Message): await message.edit('Process of demotivation...', parse_mode=enums.ParseMode.HTML) - font = requests.get('https://github.com/The-MoonTg-project/files/blob/main/Times%20New%20Roman.ttf?raw=true') + font = requests.get('https://github.com/The-MoonTg-project/files/blob/main/Times%20New%20Roman.ttf?raw=true', timeout=10) f = font.content - template_dem = requests.get('https://raw.githubusercontent.com/files/main/demotivator.png') + template_dem = requests.get('https://raw.githubusercontent.com/files/main/demotivator.png', timeout=10) if message.reply_to_message: words = ['random', 'text', 'typing', 'fuck'] if message.reply_to_message.photo: donwloads = await client.download_media(message.reply_to_message.photo.file_id) photo = Image.open(f'{donwloads}') resize_photo = photo.resize((469, 312)) - text = message.text.split(' ', maxsplit=1)[1] if len(message.text.split()) > 1 else random.choice(words) + text = message.text.split(' ', maxsplit=1)[1] if len(message.text.split()) > 1 else random.choice(words) # noqa: S311 im = Image.open(BytesIO(template_dem.content)) im.paste(resize_photo, (65, 48)) text_font = ImageFont.truetype(BytesIO(f), 22) @@ -38,7 +38,7 @@ async def demotivator(client: Client, message: Message): donwloads = await client.download_media(message.reply_to_message.sticker.file_id) photo = Image.open(f'{donwloads}') resize_photo = photo.resize((469, 312)) - text = message.text.split(' ', maxsplit=1)[1] if len(message.text.split()) > 1 else random.choice(words) + text = message.text.split(' ', maxsplit=1)[1] if len(message.text.split()) > 1 else random.choice(words) # noqa: S311 im = Image.open(BytesIO(template_dem.content)) im.paste(resize_photo, (65, 48)) text_font = ImageFont.truetype(BytesIO(f), 22) diff --git a/modules/destroy.py b/modules/destroy.py index d85e1e2..8c23595 100644 --- a/modules/destroy.py +++ b/modules/destroy.py @@ -6,8 +6,8 @@ from utils.misc import modules_help, prefix from utils.scripts import import_library lottie = import_library('lottie') -from lottie.exporters import exporters -from lottie.importers import importers +from lottie.exporters import exporters # noqa: E402 +from lottie.importers import importers # noqa: E402 @Client.on_message(filters.command('destroy', prefix) & filters.me) diff --git a/modules/direct.py b/modules/direct.py index aca8a95..498a444 100644 --- a/modules/direct.py +++ b/modules/direct.py @@ -22,7 +22,7 @@ from utils.misc import modules_help, prefix def subprocess_run(cmd): reply = '' cmd_args = cmd.split() - subproc = Popen( + subproc = Popen( # noqa: S603 cmd_args, stdout=PIPE, stderr=PIPE, @@ -93,7 +93,7 @@ def gdrive(url: str) -> str: elif link.find('uc?id=') != -1: file_id = link.split('uc?id=')[1].strip() url = f'{drive}/uc?export=download&id={file_id}' - download = requests.get(url, stream=True, allow_redirects=False) + download = requests.get(url, stream=True, allow_redirects=False, timeout=10) cookies = download.cookies try: # In case of small file size, Google downloads directly @@ -112,7 +112,7 @@ def gdrive(url: str) -> str: if page_element is not None: export = drive + page_element.get('href') name = page.find('span', {'class': 'uc-name-size'}).text - response = requests.get(export, stream=True, allow_redirects=False, cookies=cookies) + response = requests.get(export, stream=True, allow_redirects=False, cookies=cookies, timeout=10) dl_url = response.headers['location'] if 'accounts.google.com' in dl_url: name = page.find('span', {'class': 'uc-name-size'}).text @@ -138,7 +138,7 @@ def yandex_disk(url: str) -> str: return reply api = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key={}' try: - dl_url = requests.get(api.format(link)).json()['href'] + dl_url = requests.get(api.format(link), timeout=10).json()['href'] name = dl_url.split('filename=')[1].split('&disposition')[0] reply += f'[{name}]({dl_url})\n' except KeyError: @@ -181,7 +181,7 @@ def mediafire(url: str) -> str: reply = '`No MediaFire links found`\n' return reply reply = '' - page = BeautifulSoup(requests.get(link).content, 'lxml') + page = BeautifulSoup(requests.get(link, timeout=10).content, 'lxml') info = page.find('a', {'aria-label': 'Download file'}) dl_url = info.get('href') size = re.findall(r'\(.*\)', info.text)[0] @@ -201,7 +201,7 @@ def sourceforge(url: str) -> str: reply = f'Mirrors for __{file_path.split("/")[-1]}__\n' project = re.findall(r'projects?/(.*?)/files', link)[0] mirrors = f'https://sourceforge.net/settings/mirror_choices?projectname={project}&filename={file_path}' - page = BeautifulSoup(requests.get(mirrors).content, 'html.parser') + page = BeautifulSoup(requests.get(mirrors, timeout=10).content, 'html.parser') info = page.find('ul', {'id': 'mirrorList'}).findAll('li') for mirror in info[1:]: name = re.findall(r'\((.*)\)', mirror.text.strip())[0] @@ -218,7 +218,7 @@ def osdn(url: str) -> str: except IndexError: reply = '`No OSDN links found`\n' return reply - page = BeautifulSoup(requests.get(link, allow_redirects=True).content, 'lxml') + page = BeautifulSoup(requests.get(link, allow_redirects=True, timeout=10).content, 'lxml') info = page.find('a', {'class': 'mirror_link'}) link = urllib.parse.unquote(osdn_link + info['href']) reply = f'Mirrors for __{link.split("/")[-1]}__\n' @@ -285,13 +285,14 @@ def useragent(): """ useragents = BeautifulSoup( requests.get( - 'https://developers.whatismybrowser.com/useragents/explore/operating_system_name/android/' + 'https://developers.whatismybrowser.com/useragents/explore/operating_system_name/android/', + timeout=10, ).content, 'lxml', ).findAll('td', {'class': 'useragent'}) if not useragents: return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' - user_agent = choice(useragents) + user_agent = choice(useragents) # noqa: S311 return user_agent.text diff --git a/modules/durov.py b/modules/durov.py index 010709d..d091512 100644 --- a/modules/durov.py +++ b/modules/durov.py @@ -8,7 +8,7 @@ from utils.misc import modules_help, prefix @Client.on_message(filters.command('durov', prefix) & filters.me) async def durov(_, message: Message): await message.edit( - f'Random post from channel: https://t.me/durov/{randint(21, 36500)}', + f'Random post from channel: https://t.me/durov/{randint(21, 36500)}', # noqa: S311 parse_mode=enums.ParseMode.HTML, ) diff --git a/modules/f.py b/modules/f.py index 61ef22f..fc38c58 100644 --- a/modules/f.py +++ b/modules/f.py @@ -36,7 +36,7 @@ async def download_sticker(url, filename): @Client.on_message(filters.command(['f'], prefix) & filters.me) async def random_stiker(client: Client, message: Message): await message.delete() - random = randint(1, 63) + random = randint(1, 63) # noqa: S311 index = f'00{random}' if random < 10 else f'0{random}' sticker = f'https://www.chpic.su/_data/stickers/f/FforRespect/FforRespect_{index}.webp' await download_sticker(sticker, 'f.webp') diff --git a/modules/fakeactions.py b/modules/fakeactions.py index dade85c..dc19a2c 100644 --- a/modules/fakeactions.py +++ b/modules/fakeactions.py @@ -32,7 +32,7 @@ async def fakeactions_handler(client: Client, message: Message): sec = int(message.command[1]) if sec > 60: sec = 60 - except: + except Exception: sec = None await message.delete() diff --git a/modules/flux.py b/modules/flux.py index 7e44db3..4244a15 100644 --- a/modules/flux.py +++ b/modules/flux.py @@ -11,7 +11,7 @@ from utils.scripts import format_exc, progress def schellwithflux(args): API_URL = 'https://randydev-ryuzaki-api.hf.space/api/v1/akeno/fluxai' payload = {'user_id': 1191668125, 'args': args} # Please don't edit here - response = requests.post(API_URL, json=payload) + response = requests.post(API_URL, json=payload, timeout=10) if response.status_code != 200: print(f'Error status {response.status_code}') return None diff --git a/modules/hearts.py b/modules/hearts.py index ab8d95e..4b4f128 100644 --- a/modules/hearts.py +++ b/modules/hearts.py @@ -50,7 +50,7 @@ async def phase2(message: Message): format_heart = joined_heart.replace(R, '{}') for _ in range(5): - heart = format_heart.format(*random.choices(ALL, k=heartlet_len)) + heart = format_heart.format(*random.choices(ALL, k=heartlet_len)) # noqa: S311 await _wrap_edit(message, heart) await asyncio.sleep(SLEEP) diff --git a/modules/kokodrilo_explodando.py b/modules/kokodrilo_explodando.py index 7f07a2c..0399614 100644 --- a/modules/kokodrilo_explodando.py +++ b/modules/kokodrilo_explodando.py @@ -13,7 +13,7 @@ async def kokodrilo_explodando(_, message: Message): amount = int(message.command[1]) for _ in range(amount): await message.edit('🐊') - await asyncio.sleep(random.uniform(1, 2.5)) + await asyncio.sleep(random.uniform(1, 2.5)) # noqa: S311 await message.edit('💥') await asyncio.sleep(1.8) diff --git a/modules/loader.py b/modules/loader.py index c5dee70..7816d25 100644 --- a/modules/loader.py +++ b/modules/loader.py @@ -51,7 +51,7 @@ async def get_mod_hash(_, message: Message): if len(message.command) == 1: return url = message.command[1].lower() - resp = requests.get(url) + resp = requests.get(url, timeout=10) if not resp.ok: await message.edit(f'Troubleshooting with downloading module {url}') return @@ -86,7 +86,7 @@ async def loadmod(_, message: Message): try: f = requests.get( 'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt' - ).text + , timeout=10).text except Exception: return await message.edit('Failed to fetch custom modules list') modules_dict = {line.split('/')[-1].split()[0]: line.strip() for line in f.splitlines()} @@ -98,8 +98,8 @@ async def loadmod(_, message: Message): else: modules_hashes = requests.get( 'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/modules_hashes.txt' - ).text - resp = requests.get(url) + , timeout=10).text + resp = requests.get(url, timeout=10) if not resp.ok: await message.edit( @@ -118,7 +118,7 @@ async def loadmod(_, message: Message): module_name = url.split('/')[-1].split('.')[0] - resp = requests.get(url) + resp = requests.get(url, timeout=10) if not resp.ok: await message.edit(f'Module {module_name} is not found') return @@ -137,7 +137,7 @@ async def loadmod(_, message: Message): modules_hashes = requests.get( 'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/modules_hashes.txt' - ).text + , timeout=10).text if hashlib.sha256(content).hexdigest() not in modules_hashes: os.remove(file_name) @@ -214,7 +214,7 @@ async def load_all_mods(_, message: Message): os.mkdir(f'{BASE_PATH}/modules/custom_modules') try: - f = requests.get('https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt').text + f = requests.get('https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt', timeout=10).text except Exception: return await message.edit('Failed to fetch custom modules list') modules_list = f.splitlines() @@ -222,7 +222,7 @@ async def load_all_mods(_, message: Message): await message.edit('Loading modules...') for module_name in modules_list: url = f'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{module_name}.py' - resp = requests.get(url) + resp = requests.get(url, timeout=10) if not resp.ok: continue with open(f'./modules/custom_modules/{module_name.split("/")[1]}.py', 'wb') as f: @@ -281,14 +281,14 @@ async def updateallmods(_, message: Message): if not module_name.endswith('.py'): continue try: - f = requests.get('https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt').text + f = requests.get('https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt', timeout=10).text except Exception: return await message.edit('Failed to fetch custom modules list') modules_dict = {line.split('/')[-1].split()[0]: line.strip() for line in f.splitlines()} if module_name in modules_dict: resp = requests.get( f'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py' - ) + , timeout=10) if not resp.ok: modules_installed.remove(module_name) continue diff --git a/modules/markitdown.py b/modules/markitdown.py index 6061e2a..c7b272f 100644 --- a/modules/markitdown.py +++ b/modules/markitdown.py @@ -23,7 +23,7 @@ from utils.scripts import import_library, prefix, with_reply import_library('markitdown') -from markitdown import MarkItDown +from markitdown import MarkItDown # noqa: E402 @Client.on_message(filters.command(['markitdown', 'mkdn'], prefix) & filters.me) diff --git a/modules/mirror_flip.py b/modules/mirror_flip.py index 93f27c9..65f1f78 100644 --- a/modules/mirror_flip.py +++ b/modules/mirror_flip.py @@ -7,7 +7,7 @@ from utils.misc import modules_help, prefix from utils.scripts import import_library PIL = import_library('PIL', 'pillow') -from PIL import Image, ImageOps +from PIL import Image, ImageOps # noqa: E402 async def make(client, message, o): diff --git a/modules/misc/autofwd.py b/modules/misc/autofwd.py index 070667a..73b2285 100644 --- a/modules/misc/autofwd.py +++ b/modules/misc/autofwd.py @@ -139,8 +139,7 @@ async def autofwd_main(client: Client, message: Message): source_chats = db.get('custom.autofwd', 'chatsrc') target_chats = db.get('custom.autofwd', 'chatto') - if source_chats is not None and chat_id in source_chats: - if target_chats is not None: + if source_chats is not None and chat_id in source_chats and target_chats is not None: for chat in target_chats: try: await message.copy(chat) diff --git a/modules/misc/backup.py b/modules/misc/backup.py index 0b1acde..f6f33fc 100644 --- a/modules/misc/backup.py +++ b/modules/misc/backup.py @@ -133,7 +133,7 @@ async def backupmod(client: Client, message: Message): try: mod = message.text.split(maxsplit=1)[1].split('.')[0] - except: + except Exception: return await message.edit( f'Usage: {prefix}backupmod [module]', parse_mode=enums.ParseMode.HTML, @@ -169,7 +169,7 @@ async def restoremod(client: Client, message: Message): try: mod = message.text.split(maxsplit=1)[1].split('.')[0] - except: + except Exception: return await message.edit( f'Usage: {prefix}restoremod [module]', parse_mode=enums.ParseMode.HTML, diff --git a/modules/misc/cama.py b/modules/misc/cama.py index e1d3fd4..9bcf053 100644 --- a/modules/misc/cama.py +++ b/modules/misc/cama.py @@ -16,7 +16,7 @@ def get_marine_life_details(species_name): 'per_page': 1, } - response = requests.get(INATURALIST_API_URL, params=params) + response = requests.get(INATURALIST_API_URL, params=params, timeout=10) if response.status_code == 200: data = response.json() diff --git a/modules/misc/safone.py b/modules/misc/safone.py index 209a137..d5520a6 100644 --- a/modules/misc/safone.py +++ b/modules/misc/safone.py @@ -94,7 +94,7 @@ async def make_rayso(code: str, title: str, theme: str): 'language': 'auto', 'darkMode': False, } - response = requests.post(f'{url}/rayso', data=data, headers=headers) + response = requests.post(f'{url}/rayso', data=data, headers=headers, timeout=10) if response.status_code != 200: return None result = response.json() @@ -137,7 +137,7 @@ async def sgemini(_, message: Message): await message.edit_text('prompt not provided!') return await message.edit_text('Processing...') - response = requests.get(url=f'{url}/bard?query={prompt}', headers=headers) + response = requests.get(url=f'{url}/bard?query={prompt}', headers=headers, timeout=10) if response.status_code != 200: await message.edit_text('Something went wrong!') return @@ -167,7 +167,7 @@ async def app(client: Client, message: Message): try: coverImage_url = result['results'][0]['icon'] - coverImage = requests.get(url=coverImage_url).content + coverImage = requests.get(url=coverImage_url, timeout=10).content async with aiofiles.open('coverImage.jpg', mode='wb') as f: await f.write(coverImage) @@ -225,7 +225,7 @@ async def tsearch(client: Client, message: Message): else: message.edit_text("What should i search? You didn't provided me with any value to search") - response = requests.get(url=f'{url}/torrent?query={query}&limit={limit}', headers=headers) + response = requests.get(url=f'{url}/torrent?query={query}&limit={limit}', headers=headers, timeout=10) if response.status_code != 200: await message.edit_text('Something went wrong') return @@ -265,7 +265,7 @@ async def tsearch(client: Client, message: Message): ) if coverImage_url is not None: - coverImage = requests.get(url=coverImage_url).content + coverImage = requests.get(url=coverImage_url, timeout=10).content async with aiofiles.open('coverImage.jpg', mode='wb') as f: await f.write(coverImage) @@ -342,7 +342,7 @@ async def tts(client: Client, message: Message): return data = {'text': prompt, 'character': character} - response = requests.post(url=f'{url}/speech', headers=headers, json=data) + response = requests.post(url=f'{url}/speech', headers=headers, json=data, timeout=10) if response.status_code != 200: await message.edit_text('Something went wrong') return @@ -419,7 +419,7 @@ async def ccgen(_, message: Message): await message.edit_text('Code not provided!') return await message.edit_text('Processing...') - response = requests.get(url=f'{url}/ccgen?bins={bins}', headers=headers) + response = requests.get(url=f'{url}/ccgen?bins={bins}', headers=headers, timeout=10) if response.status_code != 200: await message.edit_text('Something went wrong') return diff --git a/modules/misc/sarethai.py b/modules/misc/sarethai.py index 046c6ce..3f87857 100644 --- a/modules/misc/sarethai.py +++ b/modules/misc/sarethai.py @@ -161,7 +161,7 @@ def format_apple_music_result(data): async def search_music(api_url, format_function, message, query): await message.edit('Searching...') url = f'{api_url}{query}&limit=10' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: try: @@ -194,7 +194,7 @@ async def google_search(client: Client, message: Message): await message.edit('Searching...') url = f'{GOOGLE_SEARCH_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() results, formatted_results = format_google_results(data['data']) @@ -227,7 +227,7 @@ async def youtube_search(client: Client, message: Message): await message.edit('Searching...') url = f'{YOUTUBE_SEARCH_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() results, formatted_results = format_youtube_results(data['data']) @@ -260,7 +260,7 @@ async def movie_search(client, message: Message): await message.edit('Searching...') url = f'{MOVIE_SEARCH_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() results, formatted_results = format_movie_results(data['data']) @@ -300,7 +300,7 @@ async def apk_search(client, message: Message): await message.edit('Searching...') url = f'{APK_SEARCH_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() results, formatted_results = format_apk_results(data['BK9']) @@ -329,7 +329,7 @@ async def gptweb(_, message: Message): await message.edit('Thinking...') query = ' '.join(message.command[1:]) url = f'{URL}/gptweb?text={query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() await message.edit( @@ -348,7 +348,7 @@ async def gemini(_, message: Message): await message.edit('Thinking...') query = ' '.join(message.command[1:]) url = f'{URL}/gemini?query={query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() await message.edit( @@ -440,7 +440,7 @@ async def handle_reply(client: Client, message: Message): f'Votes: {movie["vote_count"]}' ) if 'image' in movie: - response = requests.get(movie['image']) + response = requests.get(movie['image'], timeout=10) if response.status_code == 200: with open('movie_image.jpg', 'wb') as f: f.write(response.content) @@ -456,7 +456,7 @@ async def handle_reply(client: Client, message: Message): await message.reply(caption, parse_mode=enums.ParseMode.MARKDOWN) elif search_key.endswith('_apk'): apk_url = f'{APK_DOWNLOAD_URL}{results[index]["link"]}' - fetch_apk_url = requests.get(apk_url) + fetch_apk_url = requests.get(apk_url, timeout=10) if fetch_apk_url.status_code != 200: await message.edit('Failed to fetch APK data.') else: @@ -469,7 +469,7 @@ async def handle_reply(client: Client, message: Message): await message.edit('File size is too large to download.') else: apk_file_name = f'{data_apk["BK9"]["title"]}.apk' - response = requests.get(download_url) + response = requests.get(download_url, timeout=10) if response.status_code != 200: await message.edit('Failed to download the APK file.') diff --git a/modules/misc/search.py b/modules/misc/search.py index 02dd472..8336b54 100644 --- a/modules/misc/search.py +++ b/modules/misc/search.py @@ -27,7 +27,7 @@ async def search_cmd(client: Client, message: Message): cmd = message.command[1] word = message.command[2].lower() timeout = float(message.command[3]) if len(message.command) > 3 else 2 - except: + except Exception: return await message.edit( f'Usage: {prefix}search [/cmd]* [search_word]* [timeout=2.0]', parse_mode=enums.ParseMode.HTML, diff --git a/modules/misc/summary.py b/modules/misc/summary.py index 3a6c13c..fb469f3 100644 --- a/modules/misc/summary.py +++ b/modules/misc/summary.py @@ -8,8 +8,8 @@ from utils.scripts import format_exc, import_library import_library('lxml_html_clean') import_library('newspaper', 'newspaper3k') nltk = import_library('nltk') -from newspaper import Article -from newspaper.article import ArticleException +from newspaper import Article # noqa: E402 +from newspaper.article import ArticleException # noqa: E402 nltk.download('all') diff --git a/modules/misc/transcribeyt.py b/modules/misc/transcribeyt.py index f443e3d..8bb409d 100644 --- a/modules/misc/transcribeyt.py +++ b/modules/misc/transcribeyt.py @@ -15,9 +15,9 @@ gladia_url = 'https://api.gladia.io/v2/transcription/' # Function to make fetch requests to the Gladia API def make_fetch_request(url, headers, method='GET', data=None): if method == 'POST': - response = requests.post(url, headers=headers, json=data) + response = requests.post(url, headers=headers, json=data, timeout=10) else: - response = requests.get(url, headers=headers) + response = requests.get(url, headers=headers, timeout=10) return response.json() diff --git a/modules/pdf2md.py b/modules/pdf2md.py index 6cb5249..0a7a2f4 100644 --- a/modules/pdf2md.py +++ b/modules/pdf2md.py @@ -8,9 +8,9 @@ from utils.scripts import import_library import_library('pyzerox', 'py-zerox') -import litellm -from pyzerox import zerox -from pyzerox.errors import ModelAccessError, NotAVisionModel +import litellm # noqa: E402 +from pyzerox import zerox # noqa: E402 +from pyzerox.errors import ModelAccessError, NotAVisionModel # noqa: E402 kwargs = {} diff --git a/modules/perfectrussian.py b/modules/perfectrussian.py index c15d112..0807dcc 100644 --- a/modules/perfectrussian.py +++ b/modules/perfectrussian.py @@ -24,9 +24,9 @@ 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 i in range(0, len(splitted), random.randint(2, 3)): # noqa: S311 for _j in range(1, 2): - splitted.insert(i, random.choice(words)) + splitted.insert(i, random.choice(words)) # noqa: S311 await message.edit(' '.join(splitted), parse_mode=enums.ParseMode.HTML) diff --git a/modules/python.py b/modules/python.py index a07d8a4..5e166f7 100644 --- a/modules/python.py +++ b/modules/python.py @@ -41,7 +41,7 @@ async def user_exec(_: Client, message: Message): try: with redirect_stdout(stdout): - exec(code) # skipcq + exec(code) # skipcq # noqa: S102 text = f'Code:\n{code}\n\nResult:\n{stdout.getvalue()}' if message.command[0] == 'exnoedit': await message.reply(text) @@ -61,7 +61,7 @@ async def user_eval(client: Client, message: Message): code = message.text.split(maxsplit=1)[1] try: - result = eval(code) # skipcq + result = eval(code) # skipcq # noqa: S307 await message.edit(f'Expression:\n{code}\n\nResult:\n{result}') except Exception as e: await message.edit(format_exc(e)) diff --git a/modules/removebg.py b/modules/removebg.py index 4e635e6..db720e1 100644 --- a/modules/removebg.py +++ b/modules/removebg.py @@ -51,14 +51,14 @@ async def convert_to_image(message, client) -> None | str: path_s = await client.download_media(message.reply_to_message) final_path = 'lottie_proton.png' cmd = f'lottie_convert.py --frame 0 -if lottie -of png {path_s} {final_path}' - await exec(cmd) # skipcq + await exec(cmd) # skipcq # noqa: S102 elif message.reply_to_message.audio: thumb = message.reply_to_message.audio.thumbs[0].file_id final_path = await client.download_media(thumb) elif message.reply_to_message.video or message.reply_to_message.animation: final_path = 'fetched_thumb.png' vid_path = await client.download_media(message.reply_to_message) - await exec(f'ffmpeg -i {vid_path} -filter:v scale=500:500 -an {final_path}') # skipcq + await exec(f'ffmpeg -i {vid_path} -filter:v scale=500:500 -an {final_path}') # skipcq # noqa: S102 elif message.reply_to_message.document: if ( message.reply_to_message.document.mime_type == 'image/jpeg' @@ -83,6 +83,7 @@ def remove_background(photo_data): files={'image_file': image_data}, data={'size': 'auto'}, headers={'X-Api-Key': rmbg_key}, + timeout=10, ) if response.status_code == 200: return BytesIO(response.content) @@ -127,6 +128,7 @@ async def rmbg(client: Client, message: Message): files=files, allow_redirects=True, stream=True, + timeout=10, ) if os.path.exists(cool): os.remove(cool) diff --git a/modules/shell.py b/modules/shell.py index 82602f7..b6b470f 100644 --- a/modules/shell.py +++ b/modules/shell.py @@ -30,7 +30,7 @@ async def shell(_, message: Message): return await message.edit('Specify the command in message text') cmd_text = message.text.split(maxsplit=1)[1] cmd_args = cmd_text.split() - cmd_obj = Popen( + cmd_obj = Popen( # noqa: S603 cmd_args, stdout=PIPE, stderr=PIPE, diff --git a/modules/socialstalk.py b/modules/socialstalk.py index 62e6641..f6769df 100644 --- a/modules/socialstalk.py +++ b/modules/socialstalk.py @@ -26,12 +26,12 @@ async def tiktok_stalk(_, message: Message): await message.edit('Fetching TikTok profile...') url = f'{TIKTOK_API_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json().get('result', {}) if data: profile_pic_url = data.get('profile', '') - profile_pic = requests.get(profile_pic_url).content + profile_pic = requests.get(profile_pic_url, timeout=10).content profile_pic_stream = io.BytesIO(profile_pic) profile_pic_stream.name = 'profile.jpg' @@ -68,7 +68,7 @@ async def ipinfo(_, message: Message): try: url = requests.get( f'http://ip-api.com/json/{searchip}?fields=status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,currency,isp,org,as,asname,reverse,mobile,proxy,hosting,query' - ) + , timeout=10) response = json.loads(url.text) text = f""" IP Address: {response['query']} @@ -95,7 +95,7 @@ async def ipinfo(_, message: Message): Proxy: {response['proxy']} Hosting: {response['hosting']}""" await m.edit_text(text) - except: + except Exception: await m.edit_text('Unable To Find Info!') @@ -113,12 +113,12 @@ async def instagram_stalk(_, message: Message): await message.edit('Fetching Instagram profile...') url = f'{INSTAGRAM_API_URL}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json().get('result', {}).get('user_info', {}) if data: profile_pic_url = data.get('profile_pic_url', '') - profile_pic = requests.get(profile_pic_url).content + profile_pic = requests.get(profile_pic_url, timeout=10).content profile_pic_stream = io.BytesIO(profile_pic) profile_pic_stream.name = 'profile.jpg' @@ -157,7 +157,7 @@ async def github_stalk(_, message: Message): await message.edit('Fetching GitHub profile...') url = f'{GH_STALK}{query}' - response = requests.get(url) + response = requests.get(url, timeout=10) if response.status_code == 200: data = response.json() created_at = data.get('created_at', 'N/A') diff --git a/modules/spin.py b/modules/spin.py index 1636f3f..dac7778 100644 --- a/modules/spin.py +++ b/modules/spin.py @@ -21,7 +21,7 @@ imageio = import_library('imageio') def create_gif(filename: str, offset: int, fps: int = 2, typ: str = 'spin'): img = Image.open(f'downloads/{filename}') if typ.lower() != 'spin': - img = img.resize((random.randint(200, 1280), random.randint(200, 1280)), Image.ANTIALIAS) + img = img.resize((random.randint(200, 1280), random.randint(200, 1280)), Image.ANTIALIAS) # noqa: S311 # noqa: S311 imageio.mimsave( 'downloads/video.gif', [img.rotate(-(i % 360)) for i in range(1, 361, offset)], diff --git a/modules/squotes.py b/modules/squotes.py index cf0c88c..9f180ab 100644 --- a/modules/squotes.py +++ b/modules/squotes.py @@ -75,7 +75,7 @@ async def quote_cmd(client: Client, message: Message): 'text_color': '#fff', } - response = requests.post(QUOTES_API, json=params) + response = requests.post(QUOTES_API, json=params, timeout=10) if not response.ok: return await message.edit(f'Quotes API error!\n{response.text}') @@ -126,7 +126,7 @@ async def fake_quote_cmd(client: Client, message: types.Message): 'text_color': '#fff', } - response = requests.post(QUOTES_API, json=params) + response = requests.post(QUOTES_API, json=params, timeout=10) if not response.ok: return await message.edit(f'Quotes API error!\n{response.text}') @@ -227,14 +227,14 @@ async def render_message(app: Client, message: types.Message) -> dict: author['avatar'] = await get_file(from_user.photo.big_file_id) elif not from_user.photo and from_user.username: # may be user blocked us, we will try to get avatar via t.me - t_me_page = requests.get(f'https://t.me/{from_user.username}').text + t_me_page = requests.get(f'https://t.me/{from_user.username}', timeout=10).text sub = ' 0 and link[0] and link[0] != 'https://telegram.org/img/t_logo.png': # found valid link - avatar = requests.get(link[0]).content + avatar = requests.get(link[0], timeout=10).content author['avatar'] = base64.b64encode(avatar).decode() else: author['avatar'] = '' diff --git a/modules/updater.py b/modules/updater.py index 0e1c99d..39bdce1 100644 --- a/modules/updater.py +++ b/modules/updater.py @@ -44,7 +44,7 @@ async def restart_cmd(_, message: Message): if 'LAVHOST' in os.environ: await message.edit('Your lavHost is restarting...') - os.system('lavhost restart') + os.system('lavhost restart') # noqa: S605, S607 return await message.edit('Restarting...') @@ -67,14 +67,14 @@ async def update(_, message: Message): if 'LAVHOST' in os.environ: await message.edit('Your lavHost is updating...') - os.system('lavhost update') + os.system('lavhost update') # noqa: S605, S607 return await message.edit('Updating...') try: if not check_command('termux-setup-storage'): subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', 'pip'], check=True) - subprocess.run(['git', 'pull'], check=True) + subprocess.run(['git', 'pull'], check=True) # noqa: S607 if os.path.exists('requirements.txt') and os.path.getsize('requirements.txt') > 0: subprocess.run( @@ -91,7 +91,7 @@ async def update(_, message: Message): ) if requirements_list: - subprocess.run( + subprocess.run( # noqa: S603 [sys.executable, '-m', 'pip', 'install', '-U', *requirements_list], check=True, ) diff --git a/modules/url.py b/modules/url.py index 65ee09e..09155cf 100644 --- a/modules/url.py +++ b/modules/url.py @@ -35,7 +35,7 @@ from utils.scripts import format_exc, humanbytes, progress def generate_screenshot(url): api_url = f'https://api.apiflash.com/v1/urltoimage?access_key={apiflash_key}&url={url}&format=png' - response = requests.get(api_url) + response = requests.get(api_url, timeout=10) if response.status_code == 200: return BytesIO(response.content) return None @@ -212,6 +212,7 @@ async def upload_cmd(_, message: Message): response = requests.post( 'https://x0.at', files={'file': f}, + timeout=10, ) if response.ok: diff --git a/modules_list.txt b/modules_list.txt new file mode 100644 index 0000000..9a37dd2 --- /dev/null +++ b/modules_list.txt @@ -0,0 +1,115 @@ +# Userbot Modules +# Generated: Fri Jun 19 03:34:52 PM CEST 2026 + +## Core Modules (utils/) +- utils/config.py +- utils/conv.py +- utils/db.py +- utils/handlers.py +- utils/__init__.py +- utils/misc.py +- utils/module.py +- utils/rentry.py +- utils/scripts.py + +## Image Modules (images/) +- images/icons.py +- images/imgur.py +- images/ncode.py +- images/pinterest.py +- images/risearch.py +- images/unsplash2.py +- images/unsplash.py + +## Bot Modules (modules/) +- modules/1000-7.py +- modules/admintool.py +- modules/admlist.py +- modules/afk.py +- modules/aimage.py +- modules/amogus.py +- modules/amongus.py +- modules/animations.py +- modules/anime/anilist.py +- modules/anime/anime.py +- modules/anime/neko.py +- modules/aniquotes.py +- modules/antipm.py +- modules/blackbox.py +- modules/calculator.py +- modules/cdxl.py +- modules/chatbot.py +- modules/circle.py +- modules/clear_notifs.py +- modules/cohere.py +- modules/demotivator.py +- modules/destroy.py +- modules/dice.py +- modules/direct.py +- modules/duckduckgo.py +- modules/durov.py +- modules/example.py +- modules/fakeactions.py +- modules/filters.py +- modules/fliptext.py +- modules/flux.py +- modules/f.py +- modules/gemini.py +- modules/google.py +- modules/hearts.py +- modules/help.py +- modules/huggingface.py +- modules/id.py +- modules/joindate.py +- modules/kokodrilo_explodando.py +- modules/leave_chat.py +- modules/loader.py +- modules/markitdown.py +- modules/mention.py +- modules/mirror_flip.py +- modules/misc/autobackup.py +- modules/misc/autofwd.py +- modules/misc/backup.py +- modules/misc/cama.py +- modules/misc/mlog.py +- modules/misc/prayer.py +- modules/misc/safone.py +- modules/misc/sarethai.py +- modules/misc/search.py +- modules/misc/summary.py +- modules/misc/switch.py +- modules/misc/transcribeyt.py +- modules/notes.py +- modules/open.py +- modules/pdf2md.py +- modules/perfectrussian.py +- modules/ping.py +- modules/prefix.py +- modules/purge.py +- modules/python.py +- modules/reactionspam.py +- modules/removebg.py +- modules/say.py +- modules/sendmod.py +- modules/sessionkiller.py +- modules/sgb.py +- modules/shell.py +- modules/socialstalk.py +- modules/spam.py +- modules/spin.py +- modules/squotes.py +- modules/stickers.py +- modules/support.py +- modules/thumbnail.py +- modules/type.py +- modules/updater.py +- modules/upl.py +- modules/url.py +- modules/user_info.py +- modules/vt.py + +## Custom Modules (modules/custom_modules/) +- (none) + +--- +Total: 101 modules (85 bot + 0 custom + 7 image + 9 core) diff --git a/utils/handlers.py b/utils/handlers.py index 9a11822..99a73d5 100644 --- a/utils/handlers.py +++ b/utils/handlers.py @@ -771,9 +771,9 @@ class DemoteHandler: privileges=ChatPrivileges(**self.common_privileges_demote), ) except UserAdminInvalid: - raise UserAdminInvalid() + raise # noqa: B904 except ChatAdminRequired: - raise ChatAdminRequired() + raise # noqa: B904 except Exception as e: await self.message.edit(format_exc(e)) @@ -870,9 +870,9 @@ class PromoteHandler: self.cause.split(maxsplit=1)[1], ) except UserAdminInvalid: - raise UserAdminInvalid() + raise # noqa: B904 except ChatAdminRequired: - raise ChatAdminRequired() + raise # noqa: B904 except Exception as e: await self.message.edit(format_exc(e)) diff --git a/utils/rentry.py b/utils/rentry.py index cda0fc3..32c6aae 100644 --- a/utils/rentry.py +++ b/utils/rentry.py @@ -29,14 +29,14 @@ class UrllibClient: def get(self, url, headers=None): if headers is None: headers = {} - request = urllib.request.Request(url, headers=headers) + request = urllib.request.Request(url, headers=headers) # noqa: S310 return self._request(request) def post(self, url, data=None, headers=None): if headers is None: headers = {} postdata = urllib.parse.urlencode(data).encode() - request = urllib.request.Request(url, postdata, headers) + request = urllib.request.Request(url, postdata, headers) # noqa: S310 return self._request(request) def _request(self, request): diff --git a/utils/scripts.py b/utils/scripts.py index 76d8e6a..d30cf55 100644 --- a/utils/scripts.py +++ b/utils/scripts.py @@ -216,7 +216,7 @@ def restart() -> None: music_bot_process.terminate() except psutil.NoSuchProcess: print('Music bot is not running.') - os.execvp(sys.executable, [sys.executable, 'main.py']) # skipcq + os.execvp(sys.executable, [sys.executable, 'main.py']) # skipcq # noqa: S606 def format_exc(e: Exception, suffix='') -> str: @@ -324,7 +324,7 @@ def import_library(library_name: str, package_name: str = None): try: return importlib.import_module(library_name) except ImportError as exc: - completed = subprocess.run( + completed = subprocess.run( # noqa: S603 [sys.executable, '-m', 'pip', 'install', '--upgrade', package_name], check=True, ) @@ -340,7 +340,7 @@ def uninstall_library(package_name: str): Uninstalls a library :param package_name: package name in PyPi (pip uninstall example) """ - completed = subprocess.run([sys.executable, '-m', 'pip', 'uninstall', '-y', package_name], check=True) + completed = subprocess.run([sys.executable, '-m', 'pip', 'uninstall', '-y', package_name], check=True) # noqa: S603 if completed.returncode != 0: raise AssertionError( f'Failed to uninstall library {package_name} (pip exited with code {completed.returncode})' @@ -498,7 +498,7 @@ def parse_meta_comments(code: str) -> dict[str, str]: return {groups[i]: groups[i + 1] for i in range(0, len(groups), 2)} -def ReplyCheck(message: Message): +def reply_check(message: Message): reply_id = None if message.reply_to_message: