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
This commit is contained in:
2026-06-19 15:36:25 +02:00
parent 70d7855f06
commit 227e5fda27
54 changed files with 356 additions and 248 deletions
+5 -4
View File
@@ -1,10 +1,11 @@
import logging
import os import os
import time import time
import requests
import logging
import redis
from datetime import datetime from datetime import datetime
import redis
import requests
# Configure logging # Configure logging
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.INFO,
@@ -33,7 +34,7 @@ USER_AGENT = _env('USER_AGENT', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537
REDIS_HOST = _env('REDIS_HOST', 'redis') REDIS_HOST = _env('REDIS_HOST', 'redis')
REDIS_PORT = int(_env('REDIS_PORT', 6379)) REDIS_PORT = int(_env('REDIS_PORT', 6379))
SUCCESS_FILE = '/tmp/last_success' SUCCESS_FILE = '/tmp/last_success' # noqa: S108
def touch_success_file(): def touch_success_file():
"""Updates the timestamp of the success file for healthchecks.""" """Updates the timestamp of the success file for healthchecks."""
+22 -33
View File
@@ -1,15 +1,16 @@
import contextlib
import json
import logging
import os import os
import re import re
import logging
import redis
import json
import time import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, ChatMember import redis
from telegram.constants import ChatType
from telegram.ext import Application, CommandHandler, CallbackQueryHandler, ContextTypes
from playwright.async_api import async_playwright from playwright.async_api import async_playwright
from telegram import ChatMember, InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.constants import ChatType
from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes
# Logger # Logger
logging.basicConfig( logging.basicConfig(
@@ -292,10 +293,7 @@ def _parse_calendar_html(table_html: str) -> tuple:
raw = re.sub(r'<[^>]+>', ' ', row).strip() raw = re.sub(r'<[^>]+>', ' ', row).strip()
raw = re.sub(r'\s+', ' ', raw) raw = re.sub(r'\s+', ' ', raw)
m = re.search(r'([А-Яа-яіїєґ\']+\s*:?\s*\d{4})', raw) m = re.search(r'([А-Яа-яіїєґ\']+\s*:?\s*\d{4})', raw)
if m: month_text = m.group(1).replace(' : ', ' ').strip() if m else raw
month_text = m.group(1).replace(' : ', ' ').strip()
else:
month_text = raw
elif r_idx == 1: elif r_idx == 1:
# Day names row # Day names row
for cell in cells: for cell in cells:
@@ -319,10 +317,7 @@ def _parse_calendar_html(table_html: str) -> tuple:
a_tag = a_match.group(0) a_tag = a_match.group(0)
# Prefer the title attribute (contains full name, not truncated) # Prefer the title attribute (contains full name, not truncated)
title_m = re.search(r'title\s*=\s*"([^"]*)"', a_tag) title_m = re.search(r'title\s*=\s*"([^"]*)"', a_tag)
if title_m: et = title_m.group(1).strip() if title_m else re.sub(r'<[^>]+>', '', a_match.group(1)).strip()
et = title_m.group(1).strip()
else:
et = re.sub(r'<[^>]+>', '', a_match.group(1)).strip()
if et: if et:
events.append(et) events.append(et)
@@ -363,11 +358,9 @@ async def fetch_diary_data(phpsessid: str) -> dict | None:
return None return None
# Debug: save HTML for troubleshooting # Debug: save HTML for troubleshooting
try: with contextlib.suppress(Exception), \
with open('/tmp/diary_debug.html', 'w', encoding='utf-8') as f: open('/tmp/diary_debug.html', 'w', encoding='utf-8') as f: # noqa: S108
f.write(table_html) f.write(table_html)
except Exception:
pass
month_text, days = _parse_calendar_html(table_html) month_text, days = _parse_calendar_html(table_html)
logger.info(f"Diary parsed: month={month_text!r}, days_with_events={sum(1 for d in days.values() if d['events'])}/{len(days)}") logger.info(f"Diary parsed: month={month_text!r}, days_with_events={sum(1 for d in days.values() if d['events'])}/{len(days)}")
@@ -407,7 +400,7 @@ def format_diary_day(data: dict, day_num: int) -> str:
def format_diary_week(data: dict, today: datetime) -> str: def format_diary_week(data: dict, today: datetime) -> str:
days = data.get('days', {}) days = data.get('days', {})
month_str = _parse_diary_month(data.get('monthFullText', '')) _parse_diary_month(data.get('monthFullText', ''))
monday = today - timedelta(days=today.weekday()) monday = today - timedelta(days=today.weekday())
sunday = monday + timedelta(days=6) sunday = monday + timedelta(days=6)
lines = [f"📅 <b>Тиждень {monday.day}.{monday.month} {sunday.day}.{sunday.month}</b>\n"] lines = [f"📅 <b>Тиждень {monday.day}.{monday.month} {sunday.day}.{sunday.month}</b>\n"]
@@ -457,7 +450,7 @@ async def _get_diary_data(context: ContextTypes.DEFAULT_TYPE) -> dict | None:
# --- Command Handlers --- # --- Command Handlers ---
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): async def start(update: Update, _context: ContextTypes.DEFAULT_TYPE):
"""Handle /start command.""" """Handle /start command."""
user = update.effective_user user = update.effective_user
chat = update.effective_chat chat = update.effective_chat
@@ -479,7 +472,7 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
else: else:
await update.message.reply_text(msg, parse_mode='HTML') await update.message.reply_text(msg, parse_mode='HTML')
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE): async def help_command(update: Update, _context: ContextTypes.DEFAULT_TYPE):
"""Handle /help command.""" """Handle /help command."""
user_id = update.effective_user.id user_id = update.effective_user.id
chat_id = update.effective_chat.id chat_id = update.effective_chat.id
@@ -564,7 +557,7 @@ async def remove_user(update: Update, context: ContextTypes.DEFAULT_TYPE):
except ValueError: except ValueError:
await update.message.reply_text(t(admin_id, 'invalid_user_id')) await update.message.reply_text(t(admin_id, 'invalid_user_id'))
async def clear_history(update: Update, context: ContextTypes.DEFAULT_TYPE): async def clear_history(update: Update, _context: ContextTypes.DEFAULT_TYPE):
"""Clear webinar history (admin only).""" """Clear webinar history (admin only)."""
admin_id = update.effective_user.id admin_id = update.effective_user.id
if admin_id != ADMIN_ID: if admin_id != ADMIN_ID:
@@ -579,9 +572,8 @@ async def clear_history(update: Update, context: ContextTypes.DEFAULT_TYPE):
logger.error(f"Failed to clear history: {e}") logger.error(f"Failed to clear history: {e}")
await update.message.reply_text(t(admin_id, 'history_clear_failed')) await update.message.reply_text(t(admin_id, 'history_clear_failed'))
async def diary_command(update: Update, context: ContextTypes.DEFAULT_TYPE): async def diary_command(update: Update, _context: ContextTypes.DEFAULT_TYPE):
user = update.effective_user user = update.effective_user
chat = update.effective_chat
if not is_whitelisted(user.id): if not is_whitelisted(user.id):
await update.message.reply_text(t(user.id, 'access_denied')) await update.message.reply_text(t(user.id, 'access_denied'))
return return
@@ -596,10 +588,9 @@ async def diary_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = query.from_user.id user_id = query.from_user.id
await query.answer() await query.answer()
if user_id != ADMIN_ID: if user_id != ADMIN_ID and not is_whitelisted(user_id):
if not is_whitelisted(user_id): await query.edit_message_text("⛔ Доступ заборонено.")
await query.edit_message_text("⛔ Доступ заборонено.") return
return
data = query.data data = query.data
if data == "diary_refresh": if data == "diary_refresh":
@@ -690,7 +681,7 @@ async def admin_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
else: else:
await query.message.reply_text(t(user_id, 'check_completed', count=result)) await query.message.reply_text(t(user_id, 'check_completed', count=result))
async def language_callback(update: Update, context: ContextTypes.DEFAULT_TYPE): async def language_callback(update: Update, _context: ContextTypes.DEFAULT_TYPE):
"""Handle language selection button clicks.""" """Handle language selection button clicks."""
query = update.callback_query query = update.callback_query
user_id = query.from_user.id user_id = query.from_user.id
@@ -820,11 +811,9 @@ async def check_webinars_job(context: ContextTypes.DEFAULT_TYPE):
except Exception as e: except Exception as e:
logger.error(f"Error checking page: {e}. Saving content for debug.") logger.error(f"Error checking page: {e}. Saving content for debug.")
# If page content is available, save it on error # If page content is available, save it on error
try: with contextlib.suppress(Exception):
if page and not content: if page and not content:
content = await page.content() content = await page.content()
except Exception:
pass # Ignore error during content retrieval on check error
return None return None
finally: finally:
+5 -5
View File
@@ -3,7 +3,7 @@ import re
from io import BytesIO from io import BytesIO
import requests import requests
from bs4 import BeautifulSoup as bs from bs4 import BeautifulSoup as BS
from pyrogram import Client, filters from pyrogram import Client, filters
from pyrogram.errors import RPCError from pyrogram.errors import RPCError
from pyrogram.types import InputMediaPhoto, Message 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}' url = f'https://www.flaticon.com/search?word={search_query}'
try: try:
html_content = requests.get(url).text html_content = requests.get(url, timeout=10).text
soup = bs(html_content, 'html.parser') soup = BS(html_content, 'html.parser')
results = soup.find_all( results = soup.find_all(
'img', 'img',
src=re.compile(r'https://cdn-icons-png.flaticon.com/128/[0-9]+/[0-9]+.png'), 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: try:
url = f'https://www.freepik.com/api/regular/search?locale=en&term={match}' 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 = [] results = []
for i in json_content['items']: for i in json_content['items']:
results.append(i['preview']['url']) results.append(i['preview']['url'])
@@ -81,7 +81,7 @@ async def freepik_search(client: Client, message: Message):
media_group = [] media_group = []
for img_url in img_urls: for img_url in img_urls:
icon = requests.get(img_url) icon = requests.get(img_url, timeout=10)
if icon.status_code == 200: if icon.status_code == 200:
media_group.append(InputMediaPhoto(media=BytesIO(icon.content))) media_group.append(InputMediaPhoto(media=BytesIO(icon.content)))
+2 -2
View File
@@ -21,7 +21,7 @@ async def imgur(_, message: Message):
url = 'https://api.imgur.com/3/image' url = 'https://api.imgur.com/3/image'
headers = {'Authorization': 'Client-ID a10ad04550b0648'} headers = {'Authorization': 'Client-ID a10ad04550b0648'}
# Upload image to Imgur and get URL # 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() result = response.json()
await msg.edit_text(result['data']['link']) await msg.edit_text(result['data']['link'])
elif message.reply_to_message and message.reply_to_message.animation: 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' url = 'https://api.imgur.com/3/image'
headers = {'Authorization': 'Client-ID a10ad04550b0648'} headers = {'Authorization': 'Client-ID a10ad04550b0648'}
# Upload animation to Imgur and get URL # 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() result = response.json()
await msg.edit_text(result['data']['link']) await msg.edit_text(result['data']['link'])
else: else:
+2 -2
View File
@@ -30,7 +30,7 @@ def resize_image(image_bytes):
async def download_image(url): async def download_image(url):
try: try:
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
img_bytes = BytesIO(response.content) img_bytes = BytesIO(response.content)
return resize_image(img_bytes) 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) status_message = await message.edit('Searching for images...', parse_mode=enums.ParseMode.MARKDOWN)
url = f'{API_URL}{query}' url = f'{API_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
+1 -1
View File
@@ -65,7 +65,7 @@ def upload_image(photo_path):
"""Uploads an image to tmpfiles.org and returns the direct download URL.""" """Uploads an image to tmpfiles.org and returns the direct download URL."""
try: try:
with open(photo_path, 'rb') as image_file: 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: if response.status_code == 200:
data = response.json() data = response.json()
url = data['data']['url'] url = data['data']['url']
+1 -2
View File
@@ -51,7 +51,7 @@ async def unsplash(client: Client, message: Message):
for ia in range(len(images), count): for ia in range(len(images), count):
img = data['results'][ia]['urls']['raw'] img = data['results'][ia]['urls']['raw']
if img.startswith('https://images.unsplash.com/photo'): 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: with open(f'{unsplash_dir}/unsplash_{ia}.jpg', 'wb') as f:
f.write(image_content) f.write(image_content)
imgr = f'{unsplash_dir}/unsplash_{ia}.jpg' imgr = f'{unsplash_dir}/unsplash_{ia}.jpg'
@@ -77,7 +77,6 @@ async def unsplash(client: Client, message: Message):
modules_help['unsplash'] = { modules_help['unsplash'] = {
'unsplash': '[keyword]*',
'unsplash': '[keyword]* [number of results you want]*\n' 'unsplash': '[keyword]* [number of results you want]*\n'
'Makes a request to <code>unsplash.com</code> and sends the image with the keyword you provided.\n\n' 'Makes a request to <code>unsplash.com</code> and sends the image with the keyword you provided.\n\n'
'<b>Note:</b>\n1. The number of results you can get is limited to 10.\n' '<b>Note:</b>\n1. The number of results you can get is limited to 10.\n'
+2 -2
View File
@@ -29,7 +29,7 @@ def resize_image(image_bytes):
async def download_image(url): async def download_image(url):
try: try:
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
img_bytes = BytesIO(response.content) img_bytes = BytesIO(response.content)
resized_img_bytes = resize_image(img_bytes) 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) status_message = await message.edit('Searching for images...', parse_mode=enums.ParseMode.MARKDOWN)
url = f'{API_URL}{query}' url = f'{API_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
+2 -2
View File
@@ -109,7 +109,7 @@ def load_missing_modules():
module_path = f'{custom_modules_path}/{module_name}.py' module_path = f'{custom_modules_path}/{module_name}.py'
if not os.path.exists(module_path) and module_name in modules_dict: 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' 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: if resp.ok:
with open(module_path, 'wb') as f: with open(module_path, 'wb') as f:
f.write(resp.content) f.write(resp.content)
@@ -131,7 +131,7 @@ async def main():
except sqlite3.OperationalError as e: except sqlite3.OperationalError as e:
if str(e) == 'database is locked' and os.name == 'posix': if str(e) == 'database is locked' and os.name == 'posix':
logging.warning('Session file is locked. Trying to kill blocking process...') 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() restart()
raise raise
except (errors.NotAcceptable, errors.Unauthorized) as e: except (errors.NotAcceptable, errors.Unauthorized) as e:
+2 -2
View File
@@ -29,8 +29,8 @@ class Chat(Object):
self, self,
*, *,
client: 'Client' = None, client: 'Client' = None,
id: id, id: id, # noqa: A002
type: type, type: type, # noqa: A002
is_verified: bool = None, is_verified: bool = None,
is_restricted: bool = None, is_restricted: bool = None,
is_creator: bool = None, is_creator: bool = None,
+1 -1
View File
@@ -8,7 +8,7 @@ from utils.scripts import format_exc, import_library
genai = import_library('google.generativeai', 'google-generativeai') 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) genai.configure(api_key=gemini_key)
+3 -3
View File
@@ -18,11 +18,11 @@ async def amogus(client: Client, message: Message):
parse_mode=enums.ParseMode.HTML, 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/' url = 'https://raw.githubusercontent.com/The-MoonTg-project/AmongUs/master/'
font = ImageFont.truetype(BytesIO(get(url + 'bold.ttf').content), 60) font = ImageFont.truetype(BytesIO(get(url + 'bold.ttf', timeout=10).content), 60)
imposter = Image.open(BytesIO(get(f'{url}{clr}.png').content)) 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')]) 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) bbox = ImageDraw.Draw(Image.new('RGB', (1, 1))).multiline_textbbox((0, 0), text_, font, stroke_width=2)
+13 -10
View File
@@ -10,18 +10,19 @@ from PIL import Image, ImageDraw, ImageFont
from pyrogram import Client, filters from pyrogram import Client, filters
from pyrogram.types import Message from pyrogram.types import Message
from utils.misc import modules_help, prefix 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: async def amongus_gen(text: str, clr: int) -> str:
url = 'https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/Amongus/' url = 'https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/Amongus/'
font = ImageFont.truetype( font = ImageFont.truetype(
BytesIO( 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, 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')) 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) bbox = ImageDraw.Draw(Image.new('RGB', (1, 1))).multiline_textbbox((0, 0), text_, font, stroke_width=2)
w, h = bbox[2], bbox[3] 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: async def get_imposter_img(text: str) -> BytesIO:
background = requests.get( 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 ).content
font = requests.get( 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 ).content
font = BytesIO(font) font = BytesIO(font)
font = ImageFont.truetype(font, 30) font = ImageFont.truetype(font, 30)
@@ -79,9 +82,9 @@ async def amongus_cmd(client: Client, message: Message):
text = text.replace(f'-c{clr}', '') text = text.replace(f'-c{clr}', '')
clr = int(clr) clr = int(clr)
if clr > 12 or clr < 1: if clr > 12 or clr < 1:
clr = randint(1, 12) clr = randint(1, 12) # noqa: S311
except IndexError: except IndexError:
clr = randint(1, 12) clr = randint(1, 12) # noqa: S311
if not text: if not text:
if not reply: if not reply:
@@ -100,15 +103,15 @@ async def amongus_cmd(client: Client, message: Message):
@Client.on_message(filters.command('imposter', prefix) & filters.me) @Client.on_message(filters.command('imposter', prefix) & filters.me)
async def imposter_cmd(client: Client, message: Message): 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'] imps = ["wasn't the impostor", 'was the impostor']
if message.reply_to_message: if message.reply_to_message:
user = message.reply_to_message.from_user user = message.reply_to_message.from_user
text = f'{user.first_name} {choice(imps)}.' text = f'{user.first_name} {choice(imps)}.' # noqa: S311
else: else:
args = message.text.split()[1:] 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.' text += f'\n{remain} impostor(s) remain.'
imposter_file = await get_imposter_img(text) imposter_file = await get_imposter_img(text)
+1 -1
View File
@@ -187,7 +187,7 @@ async def timer_blankx(_, message: Message):
) )
j = 10 j = 10
k = j k = j
for j in range(j): for _j in range(j):
await message.edit_text(txt + str(k), parse_mode=enums.ParseMode.HTML) await message.edit_text(txt + str(k), parse_mode=enums.ParseMode.HTML)
k = k + 10 k = k + 10
await asyncio.sleep(1) await asyncio.sleep(1)
+3 -3
View File
@@ -46,7 +46,7 @@ async def anime_search(client: Client, message: Message):
averageScore = result['averageScore'] averageScore = result['averageScore']
try: try:
coverImage_url = result['imageUrl'] 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: async with aiofiles.open('coverImage.jpg', mode='wb') as f:
await f.write(coverImage) await f.write(coverImage)
@@ -112,7 +112,7 @@ async def manga_search(client: Client, message: Message):
averageScore = result['averageScore'] averageScore = result['averageScore']
try: try:
coverImage_url = result['imageUrl'] 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: async with aiofiles.open('coverImage.jpg', mode='wb') as f:
await f.write(coverImage) await f.write(coverImage)
@@ -177,7 +177,7 @@ async def character(client: Client, message: Message):
try: try:
coverImage_url = result['image']['large'] 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: async with aiofiles.open('coverImage.jpg', mode='wb') as f:
await f.write(coverImage) await f.write(coverImage)
+1 -1
View File
@@ -24,7 +24,7 @@ from utils.scripts import format_exc
def get_neko_media(query): 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) @Client.on_message(filters.command('neko', prefix) & filters.me)
+1 -1
View File
@@ -25,7 +25,7 @@ async def aniquotes_handler(client: Client, message: Message):
result = await client.get_inline_bot_results('@quotafbot', query) result = await client.get_inline_bot_results('@quotafbot', query)
return await message.reply_inline_bot_result( return await message.reply_inline_bot_result(
query_id=result.query_id, 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), reply_to_message_id=(message.reply_to_message.id if message.reply_to_message else None),
) )
except Exception as e: except Exception as e:
+2 -4
View File
@@ -11,11 +11,10 @@ async def calc(_, message: Message):
return return
args = ' '.join(message.command[1:]) args = ' '.join(message.command[1:])
try: try:
result = str(eval(args)) result = str(eval(args)) # noqa: S307
if len(result) > 4096: if len(result) > 4096:
i = 0 for i, x in enumerate(range(0, len(result), 4096)):
for x in range(0, len(result), 4096):
if i == 0: if i == 0:
await message.edit( await message.edit(
f'<i>{args}</i><b>=</b><code>{result[x : x + 4000]}</code>', f'<i>{args}</i><b>=</b><code>{result[x : x + 4000]}</code>',
@@ -23,7 +22,6 @@ async def calc(_, message: Message):
) )
else: else:
await message.reply(f'<code>{result[x : x + 4096]}</code>', parse_mode='HTML') await message.reply(f'<code>{result[x : x + 4096]}</code>', parse_mode='HTML')
i += 1
await asyncio.sleep(0.18) await asyncio.sleep(0.18)
else: else:
await message.edit(f'<i>{args}</i><b>=</b><code>{result}</code>', parse_mode='HTML') await message.edit(f'<i>{args}</i><b>=</b><code>{result}</code>', parse_mode='HTML')
+1 -1
View File
@@ -7,7 +7,7 @@ from utils.scripts import format_exc, import_library
clarifai = import_library('clarifai') 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) @Client.on_message(filters.command('cdxl', prefix) & filters.me)
+8 -8
View File
@@ -5,17 +5,17 @@ from utils.scripts import import_library
cohere = import_library('cohere') cohere = import_library('cohere')
import cohere import cohere # noqa: F811
co = cohere.Client(cohere_key) co = cohere.Client(cohere_key)
from pyrogram import Client, enums, filters from pyrogram import Client, enums, filters # noqa: E402
from pyrogram.errors import MessageTooLong from pyrogram.errors import MessageTooLong # noqa: E402
from pyrogram.types import Message from pyrogram.types import Message # noqa: E402
from utils.db import db from utils.db import db # noqa: E402
from utils.misc import modules_help, prefix from utils.misc import modules_help, prefix # noqa: E402
from utils.rentry import paste as rentry_paste from utils.rentry import paste as rentry_paste # noqa: E402
from utils.scripts import format_exc from utils.scripts import format_exc # noqa: E402
@Client.on_message(filters.command('cohere', prefix) & filters.me) @Client.on_message(filters.command('cohere', prefix) & filters.me)
+5 -5
View File
@@ -9,22 +9,22 @@ from utils.scripts import import_library
requests = import_library('requests') requests = import_library('requests')
PIL = import_library('PIL', 'pillow') 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) @Client.on_message(filters.command(['dem'], prefix) & filters.me)
async def demotivator(client: Client, message: Message): async def demotivator(client: Client, message: Message):
await message.edit('<code>Process of demotivation...</code>', parse_mode=enums.ParseMode.HTML) await message.edit('<code>Process of demotivation...</code>', 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 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: if message.reply_to_message:
words = ['random', 'text', 'typing', 'fuck'] words = ['random', 'text', 'typing', 'fuck']
if message.reply_to_message.photo: if message.reply_to_message.photo:
donwloads = await client.download_media(message.reply_to_message.photo.file_id) donwloads = await client.download_media(message.reply_to_message.photo.file_id)
photo = Image.open(f'{donwloads}') photo = Image.open(f'{donwloads}')
resize_photo = photo.resize((469, 312)) 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 = Image.open(BytesIO(template_dem.content))
im.paste(resize_photo, (65, 48)) im.paste(resize_photo, (65, 48))
text_font = ImageFont.truetype(BytesIO(f), 22) 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) donwloads = await client.download_media(message.reply_to_message.sticker.file_id)
photo = Image.open(f'{donwloads}') photo = Image.open(f'{donwloads}')
resize_photo = photo.resize((469, 312)) 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 = Image.open(BytesIO(template_dem.content))
im.paste(resize_photo, (65, 48)) im.paste(resize_photo, (65, 48))
text_font = ImageFont.truetype(BytesIO(f), 22) text_font = ImageFont.truetype(BytesIO(f), 22)
+2 -2
View File
@@ -6,8 +6,8 @@ from utils.misc import modules_help, prefix
from utils.scripts import import_library from utils.scripts import import_library
lottie = import_library('lottie') lottie = import_library('lottie')
from lottie.exporters import exporters from lottie.exporters import exporters # noqa: E402
from lottie.importers import importers from lottie.importers import importers # noqa: E402
@Client.on_message(filters.command('destroy', prefix) & filters.me) @Client.on_message(filters.command('destroy', prefix) & filters.me)
+10 -9
View File
@@ -22,7 +22,7 @@ from utils.misc import modules_help, prefix
def subprocess_run(cmd): def subprocess_run(cmd):
reply = '' reply = ''
cmd_args = cmd.split() cmd_args = cmd.split()
subproc = Popen( subproc = Popen( # noqa: S603
cmd_args, cmd_args,
stdout=PIPE, stdout=PIPE,
stderr=PIPE, stderr=PIPE,
@@ -93,7 +93,7 @@ def gdrive(url: str) -> str:
elif link.find('uc?id=') != -1: elif link.find('uc?id=') != -1:
file_id = link.split('uc?id=')[1].strip() file_id = link.split('uc?id=')[1].strip()
url = f'{drive}/uc?export=download&id={file_id}' 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 cookies = download.cookies
try: try:
# In case of small file size, Google downloads directly # In case of small file size, Google downloads directly
@@ -112,7 +112,7 @@ def gdrive(url: str) -> str:
if page_element is not None: if page_element is not None:
export = drive + page_element.get('href') export = drive + page_element.get('href')
name = page.find('span', {'class': 'uc-name-size'}).text 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'] dl_url = response.headers['location']
if 'accounts.google.com' in dl_url: if 'accounts.google.com' in dl_url:
name = page.find('span', {'class': 'uc-name-size'}).text name = page.find('span', {'class': 'uc-name-size'}).text
@@ -138,7 +138,7 @@ def yandex_disk(url: str) -> str:
return reply return reply
api = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key={}' api = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key={}'
try: 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] name = dl_url.split('filename=')[1].split('&disposition')[0]
reply += f'[{name}]({dl_url})\n' reply += f'[{name}]({dl_url})\n'
except KeyError: except KeyError:
@@ -181,7 +181,7 @@ def mediafire(url: str) -> str:
reply = '`No MediaFire links found`\n' reply = '`No MediaFire links found`\n'
return reply return reply
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'}) info = page.find('a', {'aria-label': 'Download file'})
dl_url = info.get('href') dl_url = info.get('href')
size = re.findall(r'\(.*\)', info.text)[0] 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' reply = f'Mirrors for __{file_path.split("/")[-1]}__\n'
project = re.findall(r'projects?/(.*?)/files', link)[0] project = re.findall(r'projects?/(.*?)/files', link)[0]
mirrors = f'https://sourceforge.net/settings/mirror_choices?projectname={project}&filename={file_path}' 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') info = page.find('ul', {'id': 'mirrorList'}).findAll('li')
for mirror in info[1:]: for mirror in info[1:]:
name = re.findall(r'\((.*)\)', mirror.text.strip())[0] name = re.findall(r'\((.*)\)', mirror.text.strip())[0]
@@ -218,7 +218,7 @@ def osdn(url: str) -> str:
except IndexError: except IndexError:
reply = '`No OSDN links found`\n' reply = '`No OSDN links found`\n'
return reply 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'}) info = page.find('a', {'class': 'mirror_link'})
link = urllib.parse.unquote(osdn_link + info['href']) link = urllib.parse.unquote(osdn_link + info['href'])
reply = f'Mirrors for __{link.split("/")[-1]}__\n' reply = f'Mirrors for __{link.split("/")[-1]}__\n'
@@ -285,13 +285,14 @@ def useragent():
""" """
useragents = BeautifulSoup( useragents = BeautifulSoup(
requests.get( 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, ).content,
'lxml', 'lxml',
).findAll('td', {'class': 'useragent'}) ).findAll('td', {'class': 'useragent'})
if not useragents: 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' 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 return user_agent.text
+1 -1
View File
@@ -8,7 +8,7 @@ from utils.misc import modules_help, prefix
@Client.on_message(filters.command('durov', prefix) & filters.me) @Client.on_message(filters.command('durov', prefix) & filters.me)
async def durov(_, message: Message): async def durov(_, message: Message):
await message.edit( await message.edit(
f'<b>Random post from channel: https://t.me/durov/{randint(21, 36500)}</b>', f'<b>Random post from channel: https://t.me/durov/{randint(21, 36500)}</b>', # noqa: S311
parse_mode=enums.ParseMode.HTML, parse_mode=enums.ParseMode.HTML,
) )
+1 -1
View File
@@ -36,7 +36,7 @@ async def download_sticker(url, filename):
@Client.on_message(filters.command(['f'], prefix) & filters.me) @Client.on_message(filters.command(['f'], prefix) & filters.me)
async def random_stiker(client: Client, message: Message): async def random_stiker(client: Client, message: Message):
await message.delete() await message.delete()
random = randint(1, 63) random = randint(1, 63) # noqa: S311
index = f'00{random}' if random < 10 else f'0{random}' index = f'00{random}' if random < 10 else f'0{random}'
sticker = f'https://www.chpic.su/_data/stickers/f/FforRespect/FforRespect_{index}.webp' sticker = f'https://www.chpic.su/_data/stickers/f/FforRespect/FforRespect_{index}.webp'
await download_sticker(sticker, 'f.webp') await download_sticker(sticker, 'f.webp')
+1 -1
View File
@@ -32,7 +32,7 @@ async def fakeactions_handler(client: Client, message: Message):
sec = int(message.command[1]) sec = int(message.command[1])
if sec > 60: if sec > 60:
sec = 60 sec = 60
except: except Exception:
sec = None sec = None
await message.delete() await message.delete()
+1 -1
View File
@@ -11,7 +11,7 @@ from utils.scripts import format_exc, progress
def schellwithflux(args): def schellwithflux(args):
API_URL = 'https://randydev-ryuzaki-api.hf.space/api/v1/akeno/fluxai' API_URL = 'https://randydev-ryuzaki-api.hf.space/api/v1/akeno/fluxai'
payload = {'user_id': 1191668125, 'args': args} # Please don't edit here 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: if response.status_code != 200:
print(f'Error status {response.status_code}') print(f'Error status {response.status_code}')
return None return None
+1 -1
View File
@@ -50,7 +50,7 @@ async def phase2(message: Message):
format_heart = joined_heart.replace(R, '{}') format_heart = joined_heart.replace(R, '{}')
for _ in range(5): 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 _wrap_edit(message, heart)
await asyncio.sleep(SLEEP) await asyncio.sleep(SLEEP)
+1 -1
View File
@@ -13,7 +13,7 @@ async def kokodrilo_explodando(_, message: Message):
amount = int(message.command[1]) amount = int(message.command[1])
for _ in range(amount): for _ in range(amount):
await message.edit('🐊') 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 message.edit('💥')
await asyncio.sleep(1.8) await asyncio.sleep(1.8)
+10 -10
View File
@@ -51,7 +51,7 @@ async def get_mod_hash(_, message: Message):
if len(message.command) == 1: if len(message.command) == 1:
return return
url = message.command[1].lower() url = message.command[1].lower()
resp = requests.get(url) resp = requests.get(url, timeout=10)
if not resp.ok: if not resp.ok:
await message.edit(f'<b>Troubleshooting with downloading module <code>{url}</code></b>') await message.edit(f'<b>Troubleshooting with downloading module <code>{url}</code></b>')
return return
@@ -86,7 +86,7 @@ async def loadmod(_, message: Message):
try: try:
f = requests.get( f = requests.get(
'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt' 'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/full.txt'
).text , timeout=10).text
except Exception: except Exception:
return await message.edit('Failed to fetch custom modules list') return await message.edit('Failed to fetch custom modules list')
modules_dict = {line.split('/')[-1].split()[0]: line.strip() for line in f.splitlines()} modules_dict = {line.split('/')[-1].split()[0]: line.strip() for line in f.splitlines()}
@@ -98,8 +98,8 @@ async def loadmod(_, message: Message):
else: else:
modules_hashes = requests.get( modules_hashes = requests.get(
'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/modules_hashes.txt' 'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/modules_hashes.txt'
).text , timeout=10).text
resp = requests.get(url) resp = requests.get(url, timeout=10)
if not resp.ok: if not resp.ok:
await message.edit( await message.edit(
@@ -118,7 +118,7 @@ async def loadmod(_, message: Message):
module_name = url.split('/')[-1].split('.')[0] module_name = url.split('/')[-1].split('.')[0]
resp = requests.get(url) resp = requests.get(url, timeout=10)
if not resp.ok: if not resp.ok:
await message.edit(f'<b>Module <code>{module_name}</code> is not found</b>') await message.edit(f'<b>Module <code>{module_name}</code> is not found</b>')
return return
@@ -137,7 +137,7 @@ async def loadmod(_, message: Message):
modules_hashes = requests.get( modules_hashes = requests.get(
'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/modules_hashes.txt' '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: if hashlib.sha256(content).hexdigest() not in modules_hashes:
os.remove(file_name) os.remove(file_name)
@@ -214,7 +214,7 @@ async def load_all_mods(_, message: Message):
os.mkdir(f'{BASE_PATH}/modules/custom_modules') os.mkdir(f'{BASE_PATH}/modules/custom_modules')
try: 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: except Exception:
return await message.edit('Failed to fetch custom modules list') return await message.edit('Failed to fetch custom modules list')
modules_list = f.splitlines() modules_list = f.splitlines()
@@ -222,7 +222,7 @@ async def load_all_mods(_, message: Message):
await message.edit('<b>Loading modules...</b>') await message.edit('<b>Loading modules...</b>')
for module_name in modules_list: for module_name in modules_list:
url = f'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{module_name}.py' 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: if not resp.ok:
continue continue
with open(f'./modules/custom_modules/{module_name.split("/")[1]}.py', 'wb') as f: 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'): if not module_name.endswith('.py'):
continue continue
try: 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: except Exception:
return await message.edit('Failed to fetch custom modules list') return await message.edit('Failed to fetch custom modules list')
modules_dict = {line.split('/')[-1].split()[0]: line.strip() for line in f.splitlines()} modules_dict = {line.split('/')[-1].split()[0]: line.strip() for line in f.splitlines()}
if module_name in modules_dict: if module_name in modules_dict:
resp = requests.get( resp = requests.get(
f'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py' f'https://raw.githubusercontent.com/The-MoonTg-project/custom_modules/main/{modules_dict[module_name]}.py'
) , timeout=10)
if not resp.ok: if not resp.ok:
modules_installed.remove(module_name) modules_installed.remove(module_name)
continue continue
+1 -1
View File
@@ -23,7 +23,7 @@ from utils.scripts import import_library, prefix, with_reply
import_library('markitdown') import_library('markitdown')
from markitdown import MarkItDown from markitdown import MarkItDown # noqa: E402
@Client.on_message(filters.command(['markitdown', 'mkdn'], prefix) & filters.me) @Client.on_message(filters.command(['markitdown', 'mkdn'], prefix) & filters.me)
+1 -1
View File
@@ -7,7 +7,7 @@ from utils.misc import modules_help, prefix
from utils.scripts import import_library from utils.scripts import import_library
PIL = import_library('PIL', 'pillow') PIL = import_library('PIL', 'pillow')
from PIL import Image, ImageOps from PIL import Image, ImageOps # noqa: E402
async def make(client, message, o): async def make(client, message, o):
+1 -2
View File
@@ -139,8 +139,7 @@ async def autofwd_main(client: Client, message: Message):
source_chats = db.get('custom.autofwd', 'chatsrc') source_chats = db.get('custom.autofwd', 'chatsrc')
target_chats = db.get('custom.autofwd', 'chatto') target_chats = db.get('custom.autofwd', 'chatto')
if source_chats is not None and chat_id in source_chats: if source_chats is not None and chat_id in source_chats and target_chats is not None:
if target_chats is not None:
for chat in target_chats: for chat in target_chats:
try: try:
await message.copy(chat) await message.copy(chat)
+2 -2
View File
@@ -133,7 +133,7 @@ async def backupmod(client: Client, message: Message):
try: try:
mod = message.text.split(maxsplit=1)[1].split('.')[0] mod = message.text.split(maxsplit=1)[1].split('.')[0]
except: except Exception:
return await message.edit( return await message.edit(
f'<b>Usage:</b> <code>{prefix}backupmod [module]</code>', f'<b>Usage:</b> <code>{prefix}backupmod [module]</code>',
parse_mode=enums.ParseMode.HTML, parse_mode=enums.ParseMode.HTML,
@@ -169,7 +169,7 @@ async def restoremod(client: Client, message: Message):
try: try:
mod = message.text.split(maxsplit=1)[1].split('.')[0] mod = message.text.split(maxsplit=1)[1].split('.')[0]
except: except Exception:
return await message.edit( return await message.edit(
f'<b>Usage:</b> <code>{prefix}restoremod [module]</code>', f'<b>Usage:</b> <code>{prefix}restoremod [module]</code>',
parse_mode=enums.ParseMode.HTML, parse_mode=enums.ParseMode.HTML,
+1 -1
View File
@@ -16,7 +16,7 @@ def get_marine_life_details(species_name):
'per_page': 1, '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: if response.status_code == 200:
data = response.json() data = response.json()
+7 -7
View File
@@ -94,7 +94,7 @@ async def make_rayso(code: str, title: str, theme: str):
'language': 'auto', 'language': 'auto',
'darkMode': False, '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: if response.status_code != 200:
return None return None
result = response.json() result = response.json()
@@ -137,7 +137,7 @@ async def sgemini(_, message: Message):
await message.edit_text('prompt not provided!') await message.edit_text('prompt not provided!')
return return
await message.edit_text('Processing...') 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: if response.status_code != 200:
await message.edit_text('Something went wrong!') await message.edit_text('Something went wrong!')
return return
@@ -167,7 +167,7 @@ async def app(client: Client, message: Message):
try: try:
coverImage_url = result['results'][0]['icon'] 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: async with aiofiles.open('coverImage.jpg', mode='wb') as f:
await f.write(coverImage) await f.write(coverImage)
@@ -225,7 +225,7 @@ async def tsearch(client: Client, message: Message):
else: else:
message.edit_text("What should i search? You didn't provided me with any value to search") 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: if response.status_code != 200:
await message.edit_text('Something went wrong') await message.edit_text('Something went wrong')
return return
@@ -265,7 +265,7 @@ async def tsearch(client: Client, message: Message):
) )
if coverImage_url is not None: 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: async with aiofiles.open('coverImage.jpg', mode='wb') as f:
await f.write(coverImage) await f.write(coverImage)
@@ -342,7 +342,7 @@ async def tts(client: Client, message: Message):
return return
data = {'text': prompt, 'character': character} 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: if response.status_code != 200:
await message.edit_text('Something went wrong') await message.edit_text('Something went wrong')
return return
@@ -419,7 +419,7 @@ async def ccgen(_, message: Message):
await message.edit_text('Code not provided!') await message.edit_text('Code not provided!')
return return
await message.edit_text('Processing...') 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: if response.status_code != 200:
await message.edit_text('Something went wrong') await message.edit_text('Something went wrong')
return return
+10 -10
View File
@@ -161,7 +161,7 @@ def format_apple_music_result(data):
async def search_music(api_url, format_function, message, query): async def search_music(api_url, format_function, message, query):
await message.edit('Searching...') await message.edit('Searching...')
url = f'{api_url}{query}&limit=10' url = f'{api_url}{query}&limit=10'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
try: try:
@@ -194,7 +194,7 @@ async def google_search(client: Client, message: Message):
await message.edit('Searching...') await message.edit('Searching...')
url = f'{GOOGLE_SEARCH_URL}{query}' url = f'{GOOGLE_SEARCH_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
results, formatted_results = format_google_results(data['data']) results, formatted_results = format_google_results(data['data'])
@@ -227,7 +227,7 @@ async def youtube_search(client: Client, message: Message):
await message.edit('Searching...') await message.edit('Searching...')
url = f'{YOUTUBE_SEARCH_URL}{query}' url = f'{YOUTUBE_SEARCH_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
results, formatted_results = format_youtube_results(data['data']) results, formatted_results = format_youtube_results(data['data'])
@@ -260,7 +260,7 @@ async def movie_search(client, message: Message):
await message.edit('Searching...') await message.edit('Searching...')
url = f'{MOVIE_SEARCH_URL}{query}' url = f'{MOVIE_SEARCH_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
results, formatted_results = format_movie_results(data['data']) results, formatted_results = format_movie_results(data['data'])
@@ -300,7 +300,7 @@ async def apk_search(client, message: Message):
await message.edit('Searching...') await message.edit('Searching...')
url = f'{APK_SEARCH_URL}{query}' url = f'{APK_SEARCH_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
results, formatted_results = format_apk_results(data['BK9']) results, formatted_results = format_apk_results(data['BK9'])
@@ -329,7 +329,7 @@ async def gptweb(_, message: Message):
await message.edit('Thinking...') await message.edit('Thinking...')
query = ' '.join(message.command[1:]) query = ' '.join(message.command[1:])
url = f'{URL}/gptweb?text={query}' url = f'{URL}/gptweb?text={query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
await message.edit( await message.edit(
@@ -348,7 +348,7 @@ async def gemini(_, message: Message):
await message.edit('Thinking...') await message.edit('Thinking...')
query = ' '.join(message.command[1:]) query = ' '.join(message.command[1:])
url = f'{URL}/gemini?query={query}' url = f'{URL}/gemini?query={query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
await message.edit( await message.edit(
@@ -440,7 +440,7 @@ async def handle_reply(client: Client, message: Message):
f'Votes: {movie["vote_count"]}' f'Votes: {movie["vote_count"]}'
) )
if 'image' in movie: if 'image' in movie:
response = requests.get(movie['image']) response = requests.get(movie['image'], timeout=10)
if response.status_code == 200: if response.status_code == 200:
with open('movie_image.jpg', 'wb') as f: with open('movie_image.jpg', 'wb') as f:
f.write(response.content) 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) await message.reply(caption, parse_mode=enums.ParseMode.MARKDOWN)
elif search_key.endswith('_apk'): elif search_key.endswith('_apk'):
apk_url = f'{APK_DOWNLOAD_URL}{results[index]["link"]}' 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: if fetch_apk_url.status_code != 200:
await message.edit('Failed to fetch APK data.') await message.edit('Failed to fetch APK data.')
else: else:
@@ -469,7 +469,7 @@ async def handle_reply(client: Client, message: Message):
await message.edit('File size is too large to download.') await message.edit('File size is too large to download.')
else: else:
apk_file_name = f'{data_apk["BK9"]["title"]}.apk' 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: if response.status_code != 200:
await message.edit('Failed to download the APK file.') await message.edit('Failed to download the APK file.')
+1 -1
View File
@@ -27,7 +27,7 @@ async def search_cmd(client: Client, message: Message):
cmd = message.command[1] cmd = message.command[1]
word = message.command[2].lower() word = message.command[2].lower()
timeout = float(message.command[3]) if len(message.command) > 3 else 2 timeout = float(message.command[3]) if len(message.command) > 3 else 2
except: except Exception:
return await message.edit( return await message.edit(
f'<b>Usage:</b> <code>{prefix}search [/cmd]* [search_word]* [timeout=2.0]</code>', f'<b>Usage:</b> <code>{prefix}search [/cmd]* [search_word]* [timeout=2.0]</code>',
parse_mode=enums.ParseMode.HTML, parse_mode=enums.ParseMode.HTML,
+2 -2
View File
@@ -8,8 +8,8 @@ from utils.scripts import format_exc, import_library
import_library('lxml_html_clean') import_library('lxml_html_clean')
import_library('newspaper', 'newspaper3k') import_library('newspaper', 'newspaper3k')
nltk = import_library('nltk') nltk = import_library('nltk')
from newspaper import Article from newspaper import Article # noqa: E402
from newspaper.article import ArticleException from newspaper.article import ArticleException # noqa: E402
nltk.download('all') nltk.download('all')
+2 -2
View File
@@ -15,9 +15,9 @@ gladia_url = 'https://api.gladia.io/v2/transcription/'
# Function to make fetch requests to the Gladia API # Function to make fetch requests to the Gladia API
def make_fetch_request(url, headers, method='GET', data=None): def make_fetch_request(url, headers, method='GET', data=None):
if method == 'POST': if method == 'POST':
response = requests.post(url, headers=headers, json=data) response = requests.post(url, headers=headers, json=data, timeout=10)
else: else:
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers, timeout=10)
return response.json() return response.json()
+3 -3
View File
@@ -8,9 +8,9 @@ from utils.scripts import import_library
import_library('pyzerox', 'py-zerox') import_library('pyzerox', 'py-zerox')
import litellm import litellm # noqa: E402
from pyzerox import zerox from pyzerox import zerox # noqa: E402
from pyzerox.errors import ModelAccessError, NotAVisionModel from pyzerox.errors import ModelAccessError, NotAVisionModel # noqa: E402
kwargs = {} kwargs = {}
+2 -2
View File
@@ -24,9 +24,9 @@ async def prussian_cmd(_, message: Message):
] ]
splitted = message.reply_to_message.text.split() 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): 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) await message.edit(' '.join(splitted), parse_mode=enums.ParseMode.HTML)
+2 -2
View File
@@ -41,7 +41,7 @@ async def user_exec(_: Client, message: Message):
try: try:
with redirect_stdout(stdout): with redirect_stdout(stdout):
exec(code) # skipcq exec(code) # skipcq # noqa: S102
text = f'<b>Code:</b>\n<code>{code}</code>\n\n<b>Result</b>:\n<code>{stdout.getvalue()}</code>' text = f'<b>Code:</b>\n<code>{code}</code>\n\n<b>Result</b>:\n<code>{stdout.getvalue()}</code>'
if message.command[0] == 'exnoedit': if message.command[0] == 'exnoedit':
await message.reply(text) await message.reply(text)
@@ -61,7 +61,7 @@ async def user_eval(client: Client, message: Message):
code = message.text.split(maxsplit=1)[1] code = message.text.split(maxsplit=1)[1]
try: try:
result = eval(code) # skipcq result = eval(code) # skipcq # noqa: S307
await message.edit(f'<b>Expression:</b>\n<code>{code}</code>\n\n<b>Result</b>:\n<code>{result}</code>') await message.edit(f'<b>Expression:</b>\n<code>{code}</code>\n\n<b>Result</b>:\n<code>{result}</code>')
except Exception as e: except Exception as e:
await message.edit(format_exc(e)) await message.edit(format_exc(e))
+4 -2
View File
@@ -51,14 +51,14 @@ async def convert_to_image(message, client) -> None | str:
path_s = await client.download_media(message.reply_to_message) path_s = await client.download_media(message.reply_to_message)
final_path = 'lottie_proton.png' final_path = 'lottie_proton.png'
cmd = f'lottie_convert.py --frame 0 -if lottie -of png {path_s} {final_path}' 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: elif message.reply_to_message.audio:
thumb = message.reply_to_message.audio.thumbs[0].file_id thumb = message.reply_to_message.audio.thumbs[0].file_id
final_path = await client.download_media(thumb) final_path = await client.download_media(thumb)
elif message.reply_to_message.video or message.reply_to_message.animation: elif message.reply_to_message.video or message.reply_to_message.animation:
final_path = 'fetched_thumb.png' final_path = 'fetched_thumb.png'
vid_path = await client.download_media(message.reply_to_message) 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: elif message.reply_to_message.document:
if ( if (
message.reply_to_message.document.mime_type == 'image/jpeg' message.reply_to_message.document.mime_type == 'image/jpeg'
@@ -83,6 +83,7 @@ def remove_background(photo_data):
files={'image_file': image_data}, files={'image_file': image_data},
data={'size': 'auto'}, data={'size': 'auto'},
headers={'X-Api-Key': rmbg_key}, headers={'X-Api-Key': rmbg_key},
timeout=10,
) )
if response.status_code == 200: if response.status_code == 200:
return BytesIO(response.content) return BytesIO(response.content)
@@ -127,6 +128,7 @@ async def rmbg(client: Client, message: Message):
files=files, files=files,
allow_redirects=True, allow_redirects=True,
stream=True, stream=True,
timeout=10,
) )
if os.path.exists(cool): if os.path.exists(cool):
os.remove(cool) os.remove(cool)
+1 -1
View File
@@ -30,7 +30,7 @@ async def shell(_, message: Message):
return await message.edit('<b>Specify the command in message text</b>') return await message.edit('<b>Specify the command in message text</b>')
cmd_text = message.text.split(maxsplit=1)[1] cmd_text = message.text.split(maxsplit=1)[1]
cmd_args = cmd_text.split() cmd_args = cmd_text.split()
cmd_obj = Popen( cmd_obj = Popen( # noqa: S603
cmd_args, cmd_args,
stdout=PIPE, stdout=PIPE,
stderr=PIPE, stderr=PIPE,
+7 -7
View File
@@ -26,12 +26,12 @@ async def tiktok_stalk(_, message: Message):
await message.edit('Fetching TikTok profile...') await message.edit('Fetching TikTok profile...')
url = f'{TIKTOK_API_URL}{query}' url = f'{TIKTOK_API_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json().get('result', {}) data = response.json().get('result', {})
if data: if data:
profile_pic_url = data.get('profile', '') 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 = io.BytesIO(profile_pic)
profile_pic_stream.name = 'profile.jpg' profile_pic_stream.name = 'profile.jpg'
@@ -68,7 +68,7 @@ async def ipinfo(_, message: Message):
try: try:
url = requests.get( 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' 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) response = json.loads(url.text)
text = f""" text = f"""
<b>IP Address:</b> <code>{response['query']}</code> <b>IP Address:</b> <code>{response['query']}</code>
@@ -95,7 +95,7 @@ async def ipinfo(_, message: Message):
<b>Proxy:</b> <code>{response['proxy']}</code> <b>Proxy:</b> <code>{response['proxy']}</code>
<b>Hosting:</b> <code>{response['hosting']}</code>""" <b>Hosting:</b> <code>{response['hosting']}</code>"""
await m.edit_text(text) await m.edit_text(text)
except: except Exception:
await m.edit_text('Unable To Find Info!') await m.edit_text('Unable To Find Info!')
@@ -113,12 +113,12 @@ async def instagram_stalk(_, message: Message):
await message.edit('Fetching Instagram profile...') await message.edit('Fetching Instagram profile...')
url = f'{INSTAGRAM_API_URL}{query}' url = f'{INSTAGRAM_API_URL}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json().get('result', {}).get('user_info', {}) data = response.json().get('result', {}).get('user_info', {})
if data: if data:
profile_pic_url = data.get('profile_pic_url', '') 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 = io.BytesIO(profile_pic)
profile_pic_stream.name = 'profile.jpg' profile_pic_stream.name = 'profile.jpg'
@@ -157,7 +157,7 @@ async def github_stalk(_, message: Message):
await message.edit('Fetching GitHub profile...') await message.edit('Fetching GitHub profile...')
url = f'{GH_STALK}{query}' url = f'{GH_STALK}{query}'
response = requests.get(url) response = requests.get(url, timeout=10)
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
created_at = data.get('created_at', 'N/A') created_at = data.get('created_at', 'N/A')
+1 -1
View File
@@ -21,7 +21,7 @@ imageio = import_library('imageio')
def create_gif(filename: str, offset: int, fps: int = 2, typ: str = 'spin'): def create_gif(filename: str, offset: int, fps: int = 2, typ: str = 'spin'):
img = Image.open(f'downloads/{filename}') img = Image.open(f'downloads/{filename}')
if typ.lower() != 'spin': 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( imageio.mimsave(
'downloads/video.gif', 'downloads/video.gif',
[img.rotate(-(i % 360)) for i in range(1, 361, offset)], [img.rotate(-(i % 360)) for i in range(1, 361, offset)],
+4 -4
View File
@@ -75,7 +75,7 @@ async def quote_cmd(client: Client, message: Message):
'text_color': '#fff', 'text_color': '#fff',
} }
response = requests.post(QUOTES_API, json=params) response = requests.post(QUOTES_API, json=params, timeout=10)
if not response.ok: if not response.ok:
return await message.edit(f'<b>Quotes API error!</b>\n<code>{response.text}</code>') return await message.edit(f'<b>Quotes API error!</b>\n<code>{response.text}</code>')
@@ -126,7 +126,7 @@ async def fake_quote_cmd(client: Client, message: types.Message):
'text_color': '#fff', 'text_color': '#fff',
} }
response = requests.post(QUOTES_API, json=params) response = requests.post(QUOTES_API, json=params, timeout=10)
if not response.ok: if not response.ok:
return await message.edit(f'<b>Quotes API error!</b>\n<code>{response.text}</code>') return await message.edit(f'<b>Quotes API error!</b>\n<code>{response.text}</code>')
@@ -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) author['avatar'] = await get_file(from_user.photo.big_file_id)
elif not from_user.photo and from_user.username: elif not from_user.photo and from_user.username:
# may be user blocked us, we will try to get avatar via t.me # 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 = '<meta property="og:image" content=' sub = '<meta property="og:image" content='
index = t_me_page.find(sub) index = t_me_page.find(sub)
if index != -1: if index != -1:
link = t_me_page[index + 35 :].split('"') link = t_me_page[index + 35 :].split('"')
if len(link) > 0 and link[0] and link[0] != 'https://telegram.org/img/t_logo.png': if len(link) > 0 and link[0] and link[0] != 'https://telegram.org/img/t_logo.png':
# found valid link # found valid link
avatar = requests.get(link[0]).content avatar = requests.get(link[0], timeout=10).content
author['avatar'] = base64.b64encode(avatar).decode() author['avatar'] = base64.b64encode(avatar).decode()
else: else:
author['avatar'] = '' author['avatar'] = ''
+4 -4
View File
@@ -44,7 +44,7 @@ async def restart_cmd(_, message: Message):
if 'LAVHOST' in os.environ: if 'LAVHOST' in os.environ:
await message.edit('<b>Your lavHost is restarting...</b>') await message.edit('<b>Your lavHost is restarting...</b>')
os.system('lavhost restart') os.system('lavhost restart') # noqa: S605, S607
return return
await message.edit('<b>Restarting...</b>') await message.edit('<b>Restarting...</b>')
@@ -67,14 +67,14 @@ async def update(_, message: Message):
if 'LAVHOST' in os.environ: if 'LAVHOST' in os.environ:
await message.edit('<b>Your lavHost is updating...</b>') await message.edit('<b>Your lavHost is updating...</b>')
os.system('lavhost update') os.system('lavhost update') # noqa: S605, S607
return return
await message.edit('<b>Updating...</b>') await message.edit('<b>Updating...</b>')
try: try:
if not check_command('termux-setup-storage'): if not check_command('termux-setup-storage'):
subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', 'pip'], check=True) 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: if os.path.exists('requirements.txt') and os.path.getsize('requirements.txt') > 0:
subprocess.run( subprocess.run(
@@ -91,7 +91,7 @@ async def update(_, message: Message):
) )
if requirements_list: if requirements_list:
subprocess.run( subprocess.run( # noqa: S603
[sys.executable, '-m', 'pip', 'install', '-U', *requirements_list], [sys.executable, '-m', 'pip', 'install', '-U', *requirements_list],
check=True, check=True,
) )
+2 -1
View File
@@ -35,7 +35,7 @@ from utils.scripts import format_exc, humanbytes, progress
def generate_screenshot(url): def generate_screenshot(url):
api_url = f'https://api.apiflash.com/v1/urltoimage?access_key={apiflash_key}&url={url}&format=png' 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: if response.status_code == 200:
return BytesIO(response.content) return BytesIO(response.content)
return None return None
@@ -212,6 +212,7 @@ async def upload_cmd(_, message: Message):
response = requests.post( response = requests.post(
'https://x0.at', 'https://x0.at',
files={'file': f}, files={'file': f},
timeout=10,
) )
if response.ok: if response.ok:
+115
View File
@@ -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)
+4 -4
View File
@@ -771,9 +771,9 @@ class DemoteHandler:
privileges=ChatPrivileges(**self.common_privileges_demote), privileges=ChatPrivileges(**self.common_privileges_demote),
) )
except UserAdminInvalid: except UserAdminInvalid:
raise UserAdminInvalid() raise # noqa: B904
except ChatAdminRequired: except ChatAdminRequired:
raise ChatAdminRequired() raise # noqa: B904
except Exception as e: except Exception as e:
await self.message.edit(format_exc(e)) await self.message.edit(format_exc(e))
@@ -870,9 +870,9 @@ class PromoteHandler:
self.cause.split(maxsplit=1)[1], self.cause.split(maxsplit=1)[1],
) )
except UserAdminInvalid: except UserAdminInvalid:
raise UserAdminInvalid() raise # noqa: B904
except ChatAdminRequired: except ChatAdminRequired:
raise ChatAdminRequired() raise # noqa: B904
except Exception as e: except Exception as e:
await self.message.edit(format_exc(e)) await self.message.edit(format_exc(e))
+2 -2
View File
@@ -29,14 +29,14 @@ class UrllibClient:
def get(self, url, headers=None): def get(self, url, headers=None):
if headers is None: if headers is None:
headers = {} headers = {}
request = urllib.request.Request(url, headers=headers) request = urllib.request.Request(url, headers=headers) # noqa: S310
return self._request(request) return self._request(request)
def post(self, url, data=None, headers=None): def post(self, url, data=None, headers=None):
if headers is None: if headers is None:
headers = {} headers = {}
postdata = urllib.parse.urlencode(data).encode() 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) return self._request(request)
def _request(self, request): def _request(self, request):
+4 -4
View File
@@ -216,7 +216,7 @@ def restart() -> None:
music_bot_process.terminate() music_bot_process.terminate()
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
print('Music bot is not running.') 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: def format_exc(e: Exception, suffix='') -> str:
@@ -324,7 +324,7 @@ def import_library(library_name: str, package_name: str = None):
try: try:
return importlib.import_module(library_name) return importlib.import_module(library_name)
except ImportError as exc: except ImportError as exc:
completed = subprocess.run( completed = subprocess.run( # noqa: S603
[sys.executable, '-m', 'pip', 'install', '--upgrade', package_name], [sys.executable, '-m', 'pip', 'install', '--upgrade', package_name],
check=True, check=True,
) )
@@ -340,7 +340,7 @@ def uninstall_library(package_name: str):
Uninstalls a library Uninstalls a library
:param package_name: package name in PyPi (pip uninstall example) :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: if completed.returncode != 0:
raise AssertionError( raise AssertionError(
f'Failed to uninstall library {package_name} (pip exited with code {completed.returncode})' 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)} 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 reply_id = None
if message.reply_to_message: if message.reply_to_message: