refactor: userbot to subtree
This commit is contained in:
1 parent
1930600c40
commit
69ffd3682e
134 files changed
+224
-15451
No files matched your search
@@ -1,70 +0,0 @@
|
||||
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+)',
|
||||
}
|
||||
Reference in new issue
Block a user