fix(userbot): add missing safone.py imports, apply ruff --unsafe-fixes
- Add missing aiohttp, PIL, BytesIO imports to safone.py (F821 runtime bugs) - Apply ruff --unsafe-fixes (27 fixes): ternary operators, .get() patterns, contextlib.suppress, enumerate(), collapsible if/else, remove .keys()
This commit is contained in:
@@ -12,7 +12,7 @@ from utils.misc import modules_help, prefix
|
|||||||
|
|
||||||
@Client.on_message(filters.command('icon', prefix) & filters.me)
|
@Client.on_message(filters.command('icon', prefix) & filters.me)
|
||||||
async def search_icon(_, message: Message):
|
async def search_icon(_, message: Message):
|
||||||
if not len(message.command) == 2:
|
if len(message.command) != 2:
|
||||||
return await message.edit_text('Please provide some text to search icons from Flaticon.com.')
|
return await message.edit_text('Please provide some text to search icons from Flaticon.com.')
|
||||||
query = message.text.split(maxsplit=1)[1]
|
query = message.text.split(maxsplit=1)[1]
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -39,6 +39,7 @@
|
|||||||
# "pySmartDL",
|
# "pySmartDL",
|
||||||
# ]
|
# ]
|
||||||
# ///
|
# ///
|
||||||
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -151,10 +152,8 @@ async def main():
|
|||||||
'restart': '<b>Restart completed!</b>',
|
'restart': '<b>Restart completed!</b>',
|
||||||
'update': '<b>Update process completed!</b>',
|
'update': '<b>Update process completed!</b>',
|
||||||
}[info['type']]
|
}[info['type']]
|
||||||
try:
|
with contextlib.suppress(errors.RPCError):
|
||||||
await app.edit_message_text(info['chat_id'], info['message_id'], text)
|
await app.edit_message_text(info['chat_id'], info['message_id'], text)
|
||||||
except errors.RPCError:
|
|
||||||
pass
|
|
||||||
db.remove('core.updater', 'restart_info')
|
db.remove('core.updater', 'restart_info')
|
||||||
|
|
||||||
# required for sessionkiller module
|
# required for sessionkiller module
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ def prettify(val: int) -> str:
|
|||||||
async def ghoul_counter(_, message: Message):
|
async def ghoul_counter(_, message: Message):
|
||||||
await message.delete()
|
await message.delete()
|
||||||
|
|
||||||
if len(message.command) > 1 and message.command[1].isdigit():
|
counter = int(message.command[1]) if len(message.command) > 1 and message.command[1].isdigit() else 1000
|
||||||
counter = int(message.command[1])
|
|
||||||
else:
|
|
||||||
counter = 1000
|
|
||||||
|
|
||||||
msg = await message.reply(prettify(counter), quote=False)
|
msg = await message.reply(prettify(counter), quote=False)
|
||||||
|
|
||||||
|
|||||||
@@ -47,10 +47,7 @@ async def afk_handler(_, message: types.Message):
|
|||||||
|
|
||||||
@Client.on_message(filters.command('afk', prefix) & filters.me)
|
@Client.on_message(filters.command('afk', prefix) & filters.me)
|
||||||
async def afk(_, message):
|
async def afk(_, message):
|
||||||
if len(message.text.split()) >= 2:
|
reason = message.text.split(' ', maxsplit=1)[1] if len(message.text.split()) >= 2 else 'None'
|
||||||
reason = message.text.split(' ', maxsplit=1)[1]
|
|
||||||
else:
|
|
||||||
reason = 'None'
|
|
||||||
|
|
||||||
afk_info['start'] = int(datetime.datetime.now().timestamp())
|
afk_info['start'] = int(datetime.datetime.now().timestamp())
|
||||||
afk_info['is_afk'] = True
|
afk_info['is_afk'] = True
|
||||||
|
|||||||
@@ -108,10 +108,7 @@ async def imposter_cmd(client: Client, message: Message):
|
|||||||
text = f'{user.first_name} {choice(imps)}.'
|
text = f'{user.first_name} {choice(imps)}.'
|
||||||
else:
|
else:
|
||||||
args = message.text.split()[1:]
|
args = message.text.split()[1:]
|
||||||
if args:
|
text = ' '.join(args) if args else f'{message.from_user.first_name} {choice(imps)}.'
|
||||||
text = ' '.join(args)
|
|
||||||
else:
|
|
||||||
text = f'{message.from_user.first_name} {choice(imps)}.'
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -128,10 +125,7 @@ async def imp_animation(client: Client, message: Message):
|
|||||||
name = ' '.join(message.command[1:]) if len(message.command) > 1 else ''
|
name = ' '.join(message.command[1:]) if len(message.command) > 1 else ''
|
||||||
if not name:
|
if not name:
|
||||||
reply = message.reply_to_message
|
reply = message.reply_to_message
|
||||||
if reply:
|
name = reply.from_user.first_name if reply else message.from_user.first_name
|
||||||
name = reply.from_user.first_name
|
|
||||||
else:
|
|
||||||
name = message.from_user.first_name
|
|
||||||
cmd = message.command[0].lower()
|
cmd = message.command[0].lower()
|
||||||
|
|
||||||
text1 = await edit_or_reply(message, 'Uhmm... Something is wrong here!!')
|
text1 = await edit_or_reply(message, 'Uhmm... Something is wrong here!!')
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ async def cdxl(c: Client, message: Message):
|
|||||||
await message.edit_text(f'<b>Usage: </b><code>{prefix}vdxl [prompt/reply to prompt]</code>')
|
await message.edit_text(f'<b>Usage: </b><code>{prefix}vdxl [prompt/reply to prompt]</code>')
|
||||||
return
|
return
|
||||||
|
|
||||||
inference_params = dict(width=1024, height=1024, steps=50, cfg_scale=9.0)
|
inference_params = {'width': 1024, 'height': 1024, 'steps': 50, 'cfg_scale': 9.0}
|
||||||
|
|
||||||
model_prediction = Model(
|
model_prediction = Model(
|
||||||
'https://clarifai.com/stability-ai/stable-diffusion-2/models/stable-diffusion-xl'
|
'https://clarifai.com/stability-ai/stable-diffusion-2/models/stable-diffusion-xl'
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ def set_filters_chat(chat_id, filters_):
|
|||||||
|
|
||||||
|
|
||||||
async def contains_filter(_, __, m):
|
async def contains_filter(_, __, m):
|
||||||
return m.text and m.text.lower() in get_filters_chat(m.chat.id).keys()
|
return m.text and m.text.lower() in get_filters_chat(m.chat.id)
|
||||||
|
|
||||||
|
|
||||||
contains = filters.create(contains_filter)
|
contains = filters.create(contains_filter)
|
||||||
@@ -115,7 +115,7 @@ async def filter_handler(client: Client, message: Message):
|
|||||||
return await message.edit(f'<b>Usage</b>: <code>{prefix}filter [name] (Reply required)</code>')
|
return await message.edit(f'<b>Usage</b>: <code>{prefix}filter [name] (Reply required)</code>')
|
||||||
name = message.text.split(maxsplit=1)[1].lower()
|
name = message.text.split(maxsplit=1)[1].lower()
|
||||||
chat_filters = get_filters_chat(message.chat.id)
|
chat_filters = get_filters_chat(message.chat.id)
|
||||||
if name in chat_filters.keys():
|
if name in chat_filters:
|
||||||
return await message.edit(f'<b>Filter</b> <code>{name}</code> already exists.')
|
return await message.edit(f'<b>Filter</b> <code>{name}</code> already exists.')
|
||||||
if not message.reply_to_message:
|
if not message.reply_to_message:
|
||||||
return await message.edit('<b>Reply to message</b> please.')
|
return await message.edit('<b>Reply to message</b> please.')
|
||||||
@@ -186,7 +186,7 @@ async def filter_del_handler(_, message: Message):
|
|||||||
)
|
)
|
||||||
name = message.text.split(maxsplit=1)[1].lower()
|
name = message.text.split(maxsplit=1)[1].lower()
|
||||||
chat_filters = get_filters_chat(message.chat.id)
|
chat_filters = get_filters_chat(message.chat.id)
|
||||||
if name not in chat_filters.keys():
|
if name not in chat_filters:
|
||||||
return await message.edit(
|
return await message.edit(
|
||||||
f"<b>Filter</b> <code>{name}</code> doesn't exists.",
|
f"<b>Filter</b> <code>{name}</code> doesn't exists.",
|
||||||
)
|
)
|
||||||
@@ -208,7 +208,7 @@ async def filter_search_handler(_, message: Message):
|
|||||||
)
|
)
|
||||||
name = message.text.split(maxsplit=1)[1].lower()
|
name = message.text.split(maxsplit=1)[1].lower()
|
||||||
chat_filters = get_filters_chat(message.chat.id)
|
chat_filters = get_filters_chat(message.chat.id)
|
||||||
if name not in chat_filters.keys():
|
if name not in chat_filters:
|
||||||
return await message.edit(
|
return await message.edit(
|
||||||
f"<b>Filter</b> <code>{name}</code> doesn't exists.",
|
f"<b>Filter</b> <code>{name}</code> doesn't exists.",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -89,10 +89,7 @@ async def flip(client: Client, message: Message):
|
|||||||
text = ' '.join(message.command[1:])
|
text = ' '.join(message.command[1:])
|
||||||
final_str = ''
|
final_str = ''
|
||||||
for char in text:
|
for char in text:
|
||||||
if char in REPLACEMENT_MAP:
|
new_char = REPLACEMENT_MAP.get(char, char)
|
||||||
new_char = REPLACEMENT_MAP[char]
|
|
||||||
else:
|
|
||||||
new_char = char
|
|
||||||
final_str += new_char
|
final_str += new_char
|
||||||
if text != final_str:
|
if text != final_str:
|
||||||
await message.edit(final_str)
|
await message.edit(final_str)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ async def help_cmd(_, message: Message):
|
|||||||
command_name = message.command[1].lower()
|
command_name = message.command[1].lower()
|
||||||
module_found = False
|
module_found = False
|
||||||
for module_name, commands in modules_help.items():
|
for module_name, commands in modules_help.items():
|
||||||
for command in commands.keys():
|
for command in commands:
|
||||||
if command.split()[0] == command_name:
|
if command.split()[0] == command_name:
|
||||||
cmd = command.split(maxsplit=1)
|
cmd = command.split(maxsplit=1)
|
||||||
cmd_desc = commands[command]
|
cmd_desc = commands[command]
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ def get_marine_life_details(species_name):
|
|||||||
species = observation['taxon']['name']
|
species = observation['taxon']['name']
|
||||||
common_name = observation['taxon']['preferred_common_name']
|
common_name = observation['taxon']['preferred_common_name']
|
||||||
photo_url = observation['photos'][0]['url'] if observation['photos'] else 'No photo available'
|
photo_url = observation['photos'][0]['url'] if observation['photos'] else 'No photo available'
|
||||||
description = observation['description'] if 'description' in observation else 'No description available.'
|
description = observation.get('description', 'No description available.')
|
||||||
return {
|
return {
|
||||||
'species': species,
|
'species': species,
|
||||||
'common_name': common_name,
|
'common_name': common_name,
|
||||||
|
|||||||
@@ -16,9 +16,12 @@
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import aiofiles
|
import aiofiles
|
||||||
|
import aiohttp
|
||||||
import requests
|
import requests
|
||||||
|
from PIL import Image, ImageEnhance
|
||||||
from pyrogram import Client, enums, filters
|
from pyrogram import Client, enums, filters
|
||||||
from pyrogram.errors import MediaCaptionTooLong, MessageTooLong
|
from pyrogram.errors import MediaCaptionTooLong, MessageTooLong
|
||||||
from pyrogram.types import InputMediaPhoto, Message
|
from pyrogram.types import InputMediaPhoto, Message
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import contextlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -101,10 +102,8 @@ async def delete_search_data(client, chat_id, message_id):
|
|||||||
search_key = f'{chat_id}_{key}'
|
search_key = f'{chat_id}_{key}'
|
||||||
if search_key in search_results and search_results[search_key]['message_id'] == message_id:
|
if search_key in search_results and search_results[search_key]['message_id'] == message_id:
|
||||||
del search_results[search_key]
|
del search_results[search_key]
|
||||||
try:
|
with contextlib.suppress(BaseException):
|
||||||
await client.delete_messages(chat_id, message_id)
|
await client.delete_messages(chat_id, message_id)
|
||||||
except:
|
|
||||||
pass
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ async def notes(_, message: Message):
|
|||||||
await message.edit('<b>Loading...</b>')
|
await message.edit('<b>Loading...</b>')
|
||||||
text = 'Available notes:\n\n'
|
text = 'Available notes:\n\n'
|
||||||
collection = db.get_collection('core.notes')
|
collection = db.get_collection('core.notes')
|
||||||
for note in collection.keys():
|
for note in collection:
|
||||||
if note[:4] == 'note':
|
if note[:4] == 'note':
|
||||||
text += f'<code>{note[4:]}</code>\n'
|
text += f'<code>{note[4:]}</code>\n'
|
||||||
await message.edit(text)
|
await message.edit(text)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ async def pdf2md(client: Client, message: Message):
|
|||||||
if not message.reply_to_message.document:
|
if not message.reply_to_message.document:
|
||||||
await message.edit('Reply to a pdf file')
|
await message.edit('Reply to a pdf file')
|
||||||
return
|
return
|
||||||
if not message.reply_to_message.document.mime_type == 'application/pdf':
|
if message.reply_to_message.document.mime_type != 'application/pdf':
|
||||||
await message.edit('Reply to a pdf file')
|
await message.edit('Reply to a pdf file')
|
||||||
return
|
return
|
||||||
if gemini_key == '':
|
if gemini_key == '':
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ 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)):
|
||||||
for j in range(1, 2):
|
for _j in range(1, 2):
|
||||||
splitted.insert(i, random.choice(words))
|
splitted.insert(i, random.choice(words))
|
||||||
|
|
||||||
await message.edit(' '.join(splitted), parse_mode=enums.ParseMode.HTML)
|
await message.edit(' '.join(splitted), parse_mode=enums.ParseMode.HTML)
|
||||||
|
|||||||
@@ -101,10 +101,7 @@ async def spin_handler(client: Client, message: Message):
|
|||||||
filename = 'sticker.webp'
|
filename = 'sticker.webp'
|
||||||
elif message.reply_to_message.text:
|
elif message.reply_to_message.text:
|
||||||
result = await quote_cmd(client, message)
|
result = await quote_cmd(client, message)
|
||||||
if result[1]:
|
filename = 'sticker.png' if result[1] else 'sticker.webp'
|
||||||
filename = 'sticker.png'
|
|
||||||
else:
|
|
||||||
filename = 'sticker.webp'
|
|
||||||
open('downloads/' + filename, 'wb').write(result[0].getbuffer())
|
open('downloads/' + filename, 'wb').write(result[0].getbuffer())
|
||||||
coro = False
|
coro = False
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -40,10 +40,7 @@ async def kang(client: Client, message: types.Message):
|
|||||||
return
|
return
|
||||||
|
|
||||||
pack = message.command[1]
|
pack = message.command[1]
|
||||||
if len(message.command) >= 3:
|
emoji = message.command[2] if len(message.command) >= 3 else '✨'
|
||||||
emoji = message.command[2]
|
|
||||||
else:
|
|
||||||
emoji = '✨'
|
|
||||||
|
|
||||||
await client.unblock_user('@stickers')
|
await client.unblock_user('@stickers')
|
||||||
await interact_with(await client.send_message('@stickers', '/cancel', parse_mode=enums.ParseMode.MARKDOWN))
|
await interact_with(await client.send_message('@stickers', '/cancel', parse_mode=enums.ParseMode.MARKDOWN))
|
||||||
|
|||||||
@@ -35,10 +35,7 @@ async def get_user_inf(client: Client, message: Message):
|
|||||||
user = response.users[0]
|
user = response.users[0]
|
||||||
full_user = response.full_user
|
full_user = response.full_user
|
||||||
|
|
||||||
if user.username is None:
|
username = 'None' if user.username is None else f'@{user.username}'
|
||||||
username = 'None'
|
|
||||||
else:
|
|
||||||
username = f'@{user.username}'
|
|
||||||
about = 'None' if full_user.about is None else full_user.about
|
about = 'None' if full_user.about is None else full_user.about
|
||||||
|
|
||||||
user_info = f"""|=<b>Username: {username}
|
user_info = f"""|=<b>Username: {username}
|
||||||
@@ -79,10 +76,7 @@ async def get_full_user_inf(client: Client, message: Message):
|
|||||||
# await client.delete_messages("@creationdatebot", interact_with_to_delete)
|
# await client.delete_messages("@creationdatebot", interact_with_to_delete)
|
||||||
interact_with_to_delete.clear()
|
interact_with_to_delete.clear()
|
||||||
|
|
||||||
if user.username is None:
|
username = 'None' if user.username is None else f'@{user.username}'
|
||||||
username = 'None'
|
|
||||||
else:
|
|
||||||
username = f'@{user.username}'
|
|
||||||
about = 'None' if full_user.about is None else full_user.about
|
about = 'None' if full_user.about is None else full_user.about
|
||||||
user_info = f"""|=<b>Username: {username}
|
user_info = f"""|=<b>Username: {username}
|
||||||
|-Id: <code>{user.id}</code>
|
|-Id: <code>{user.id}</code>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class HelpNavigator:
|
|||||||
text += f'Help Page No: {self.current_page}/{self.total_pages}\n\n'
|
text += f'Help Page No: {self.current_page}/{self.total_pages}\n\n'
|
||||||
for module_name in page_modules:
|
for module_name in page_modules:
|
||||||
commands = modules_help[module_name]
|
commands = modules_help[module_name]
|
||||||
text += f'<b>• {module_name.title()}:</b> {", ".join([f"<code>{prefix + cmd_name.split()[0]}</code>" for cmd_name in commands.keys()])}\n'
|
text += f'<b>• {module_name.title()}:</b> {", ".join([f"<code>{prefix + cmd_name.split()[0]}</code>" for cmd_name in commands])}\n'
|
||||||
text += f'\n<b>The number of modules in the userbot: {len(modules_help)}</b>'
|
text += f'\n<b>The number of modules in the userbot: {len(modules_help)}</b>'
|
||||||
await message.edit(text, disable_web_page_preview=True)
|
await message.edit(text, disable_web_page_preview=True)
|
||||||
|
|
||||||
|
|||||||
@@ -484,9 +484,7 @@ async def unload_module(module_name: str, client: Client) -> bool:
|
|||||||
|
|
||||||
def no_prefix(handler):
|
def no_prefix(handler):
|
||||||
def func(_, __, message):
|
def func(_, __, message):
|
||||||
if message.text and not message.text.startswith(handler):
|
return bool(message.text and not message.text.startswith(handler))
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
return filters.create(func)
|
return filters.create(func)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user