fb43306571
Dockerfile fixes: - edu_master/phpsessid-bot: add --no-install-recommends, pin pip versions - edu_master/webinar-checker: pin pip versions with --no-cache-dir - userbot: add SHELL with pipefail for pipe operations Ruff fixes (173 → 0): - W293/W291/W292: whitespace clean via ruff format - N806: camelCase → snake_case (anilist, safone, hearts, flux, etc.) - ARG001/ARG002: prefix unused params with _ - SIM115: use context managers for file I/O - SIM117: combine nested with statements - S608: noqa on SQL f-strings (module name is validated) - E402/N812/N817: import fixes - B023: pass loop variable as argument - I001: auto-sorted imports - syntax: fixed = vs == in dtek_notif/main.py
71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
from io import BytesIO
|
|
|
|
from aiohttp import ClientSession
|
|
from pyrogram import Client, enums, filters
|
|
from pyrogram.types import Message
|
|
|
|
# noinspection PyUnresolvedReferences
|
|
from utils.misc import modules_help, prefix
|
|
from utils.scripts import format_exc
|
|
|
|
session = ClientSession()
|
|
|
|
|
|
class Post:
|
|
def __init__(self, source: dict, session: ClientSession):
|
|
self._json = source
|
|
self.session = session
|
|
|
|
@property
|
|
async def image(self):
|
|
return (
|
|
self.file_url
|
|
if self.file_url
|
|
else (
|
|
self.large_file_url
|
|
if self.large_file_url
|
|
else (
|
|
self.source
|
|
if self.source and 'pximg' not in self.source
|
|
else await self.pximg
|
|
if self.source
|
|
else None
|
|
)
|
|
)
|
|
)
|
|
|
|
@property
|
|
async def pximg(self):
|
|
async with self.session.get(self.source) as response:
|
|
return BytesIO(await response.read())
|
|
|
|
def __getattr__(self, item):
|
|
return self._json.get(item)
|
|
|
|
|
|
async def random():
|
|
async with session.get(url='https://danbooru.donmai.us/posts/random.json') as response:
|
|
return Post(await response.json(encoding='utf-8'), session)
|
|
|
|
|
|
@Client.on_message(filters.command(['arnd', 'arandom'], prefix) & filters.me)
|
|
async def anime_handler(_client: Client, message: Message):
|
|
try:
|
|
await message.edit('<b>Searching art</b>', parse_mode=enums.ParseMode.HTML)
|
|
ra = await random()
|
|
img = await ra.image
|
|
await message.reply_photo(
|
|
photo=img,
|
|
caption=f'<b>{ra.tag_string_general if ra.tag_string_general else "Untitled"}</b>',
|
|
parse_mode=enums.ParseMode.HTML,
|
|
)
|
|
return await message.delete()
|
|
except Exception as e:
|
|
await message.edit(format_exc(e), parse_mode=enums.ParseMode.HTML)
|
|
|
|
|
|
modules_help['anime'] = {
|
|
'arnd': 'Random anime art (May get caught 18+)',
|
|
'arandom': 'Random anime art (May get caught 18+)',
|
|
}
|