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:
+1
-4
@@ -15,10 +15,7 @@ def prettify(val: int) -> str:
|
||||
async def ghoul_counter(_, message: Message):
|
||||
await message.delete()
|
||||
|
||||
if len(message.command) > 1 and message.command[1].isdigit():
|
||||
counter = int(message.command[1])
|
||||
else:
|
||||
counter = 1000
|
||||
counter = int(message.command[1]) if len(message.command) > 1 and message.command[1].isdigit() else 1000
|
||||
|
||||
msg = await message.reply(prettify(counter), quote=False)
|
||||
|
||||
|
||||
+1
-4
@@ -47,10 +47,7 @@ async def afk_handler(_, message: types.Message):
|
||||
|
||||
@Client.on_message(filters.command('afk', prefix) & filters.me)
|
||||
async def afk(_, message):
|
||||
if len(message.text.split()) >= 2:
|
||||
reason = message.text.split(' ', maxsplit=1)[1]
|
||||
else:
|
||||
reason = 'None'
|
||||
reason = message.text.split(' ', maxsplit=1)[1] if len(message.text.split()) >= 2 else 'None'
|
||||
|
||||
afk_info['start'] = int(datetime.datetime.now().timestamp())
|
||||
afk_info['is_afk'] = True
|
||||
|
||||
+2
-8
@@ -108,10 +108,7 @@ async def imposter_cmd(client: Client, message: Message):
|
||||
text = f'{user.first_name} {choice(imps)}.'
|
||||
else:
|
||||
args = message.text.split()[1:]
|
||||
if args:
|
||||
text = ' '.join(args)
|
||||
else:
|
||||
text = f'{message.from_user.first_name} {choice(imps)}.'
|
||||
text = ' '.join(args) if args else f'{message.from_user.first_name} {choice(imps)}.'
|
||||
|
||||
text += f'\n{remain} impostor(s) remain.'
|
||||
imposter_file = await get_imposter_img(text)
|
||||
@@ -128,10 +125,7 @@ async def imp_animation(client: Client, message: Message):
|
||||
name = ' '.join(message.command[1:]) if len(message.command) > 1 else ''
|
||||
if not name:
|
||||
reply = message.reply_to_message
|
||||
if reply:
|
||||
name = reply.from_user.first_name
|
||||
else:
|
||||
name = message.from_user.first_name
|
||||
name = reply.from_user.first_name if reply else message.from_user.first_name
|
||||
cmd = message.command[0].lower()
|
||||
|
||||
text1 = await edit_or_reply(message, 'Uhmm... Something is wrong here!!')
|
||||
|
||||
+1
-1
@@ -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>')
|
||||
return
|
||||
|
||||
inference_params = dict(width=1024, height=1024, steps=50, cfg_scale=9.0)
|
||||
inference_params = {'width': 1024, 'height': 1024, 'steps': 50, 'cfg_scale': 9.0}
|
||||
|
||||
model_prediction = Model(
|
||||
'https://clarifai.com/stability-ai/stable-diffusion-2/models/stable-diffusion-xl'
|
||||
|
||||
+4
-4
@@ -36,7 +36,7 @@ def set_filters_chat(chat_id, filters_):
|
||||
|
||||
|
||||
async def contains_filter(_, __, m):
|
||||
return m.text and m.text.lower() in get_filters_chat(m.chat.id).keys()
|
||||
return m.text and m.text.lower() in get_filters_chat(m.chat.id)
|
||||
|
||||
|
||||
contains = filters.create(contains_filter)
|
||||
@@ -115,7 +115,7 @@ async def filter_handler(client: Client, message: Message):
|
||||
return await message.edit(f'<b>Usage</b>: <code>{prefix}filter [name] (Reply required)</code>')
|
||||
name = message.text.split(maxsplit=1)[1].lower()
|
||||
chat_filters = get_filters_chat(message.chat.id)
|
||||
if name in chat_filters.keys():
|
||||
if name in chat_filters:
|
||||
return await message.edit(f'<b>Filter</b> <code>{name}</code> already exists.')
|
||||
if not message.reply_to_message:
|
||||
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()
|
||||
chat_filters = get_filters_chat(message.chat.id)
|
||||
if name not in chat_filters.keys():
|
||||
if name not in chat_filters:
|
||||
return await message.edit(
|
||||
f"<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()
|
||||
chat_filters = get_filters_chat(message.chat.id)
|
||||
if name not in chat_filters.keys():
|
||||
if name not in chat_filters:
|
||||
return await message.edit(
|
||||
f"<b>Filter</b> <code>{name}</code> doesn't exists.",
|
||||
)
|
||||
|
||||
+1
-4
@@ -89,10 +89,7 @@ async def flip(client: Client, message: Message):
|
||||
text = ' '.join(message.command[1:])
|
||||
final_str = ''
|
||||
for char in text:
|
||||
if char in REPLACEMENT_MAP:
|
||||
new_char = REPLACEMENT_MAP[char]
|
||||
else:
|
||||
new_char = char
|
||||
new_char = REPLACEMENT_MAP.get(char, char)
|
||||
final_str += new_char
|
||||
if text != final_str:
|
||||
await message.edit(final_str)
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ async def help_cmd(_, message: Message):
|
||||
command_name = message.command[1].lower()
|
||||
module_found = False
|
||||
for module_name, commands in modules_help.items():
|
||||
for command in commands.keys():
|
||||
for command in commands:
|
||||
if command.split()[0] == command_name:
|
||||
cmd = command.split(maxsplit=1)
|
||||
cmd_desc = commands[command]
|
||||
|
||||
@@ -25,7 +25,7 @@ def get_marine_life_details(species_name):
|
||||
species = observation['taxon']['name']
|
||||
common_name = observation['taxon']['preferred_common_name']
|
||||
photo_url = observation['photos'][0]['url'] if observation['photos'] else 'No photo available'
|
||||
description = observation['description'] if 'description' in observation else 'No description available.'
|
||||
description = observation.get('description', 'No description available.')
|
||||
return {
|
||||
'species': species,
|
||||
'common_name': common_name,
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
import base64
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
import aiofiles
|
||||
import aiohttp
|
||||
import requests
|
||||
from PIL import Image, ImageEnhance
|
||||
from pyrogram import Client, enums, filters
|
||||
from pyrogram.errors import MediaCaptionTooLong, MessageTooLong
|
||||
from pyrogram.types import InputMediaPhoto, Message
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import os
|
||||
|
||||
import requests
|
||||
@@ -101,10 +102,8 @@ async def delete_search_data(client, chat_id, message_id):
|
||||
search_key = f'{chat_id}_{key}'
|
||||
if search_key in search_results and search_results[search_key]['message_id'] == message_id:
|
||||
del search_results[search_key]
|
||||
try:
|
||||
with contextlib.suppress(BaseException):
|
||||
await client.delete_messages(chat_id, message_id)
|
||||
except:
|
||||
pass
|
||||
break
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ async def notes(_, message: Message):
|
||||
await message.edit('<b>Loading...</b>')
|
||||
text = 'Available notes:\n\n'
|
||||
collection = db.get_collection('core.notes')
|
||||
for note in collection.keys():
|
||||
for note in collection:
|
||||
if note[:4] == 'note':
|
||||
text += f'<code>{note[4:]}</code>\n'
|
||||
await message.edit(text)
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ async def pdf2md(client: Client, message: Message):
|
||||
if not message.reply_to_message.document:
|
||||
await message.edit('Reply to a pdf file')
|
||||
return
|
||||
if not message.reply_to_message.document.mime_type == 'application/pdf':
|
||||
if message.reply_to_message.document.mime_type != 'application/pdf':
|
||||
await message.edit('Reply to a pdf file')
|
||||
return
|
||||
if gemini_key == '':
|
||||
|
||||
@@ -25,7 +25,7 @@ async def prussian_cmd(_, message: Message):
|
||||
splitted = message.reply_to_message.text.split()
|
||||
|
||||
for i in range(0, len(splitted), random.randint(2, 3)):
|
||||
for j in range(1, 2):
|
||||
for _j in range(1, 2):
|
||||
splitted.insert(i, random.choice(words))
|
||||
|
||||
await message.edit(' '.join(splitted), parse_mode=enums.ParseMode.HTML)
|
||||
|
||||
+1
-4
@@ -101,10 +101,7 @@ async def spin_handler(client: Client, message: Message):
|
||||
filename = 'sticker.webp'
|
||||
elif message.reply_to_message.text:
|
||||
result = await quote_cmd(client, message)
|
||||
if result[1]:
|
||||
filename = 'sticker.png'
|
||||
else:
|
||||
filename = 'sticker.webp'
|
||||
filename = 'sticker.png' if result[1] else 'sticker.webp'
|
||||
open('downloads/' + filename, 'wb').write(result[0].getbuffer())
|
||||
coro = False
|
||||
else:
|
||||
|
||||
+1
-4
@@ -40,10 +40,7 @@ async def kang(client: Client, message: types.Message):
|
||||
return
|
||||
|
||||
pack = message.command[1]
|
||||
if len(message.command) >= 3:
|
||||
emoji = message.command[2]
|
||||
else:
|
||||
emoji = '✨'
|
||||
emoji = message.command[2] if len(message.command) >= 3 else '✨'
|
||||
|
||||
await client.unblock_user('@stickers')
|
||||
await interact_with(await client.send_message('@stickers', '/cancel', parse_mode=enums.ParseMode.MARKDOWN))
|
||||
|
||||
@@ -35,10 +35,7 @@ async def get_user_inf(client: Client, message: Message):
|
||||
user = response.users[0]
|
||||
full_user = response.full_user
|
||||
|
||||
if user.username is None:
|
||||
username = 'None'
|
||||
else:
|
||||
username = f'@{user.username}'
|
||||
username = 'None' if user.username is None else f'@{user.username}'
|
||||
about = 'None' if full_user.about is None else full_user.about
|
||||
|
||||
user_info = f"""|=<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)
|
||||
interact_with_to_delete.clear()
|
||||
|
||||
if user.username is None:
|
||||
username = 'None'
|
||||
else:
|
||||
username = f'@{user.username}'
|
||||
username = 'None' if user.username is None else f'@{user.username}'
|
||||
about = 'None' if full_user.about is None else full_user.about
|
||||
user_info = f"""|=<b>Username: {username}
|
||||
|-Id: <code>{user.id}</code>
|
||||
|
||||
Reference in New Issue
Block a user