Try fixing AttributeErrors

This commit is contained in:
blank X 2021-08-20 20:16:09 +07:00
parent a6c52162e6
commit 10c8a1ebab
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 27 additions and 11 deletions

View File

@ -33,9 +33,16 @@ async def anilist(client, message):
await message.reply_text(f'There are only {len(results.results)} results')
except (Forbidden, ChatInlineSendForbidden):
text = {'message': results.results[page].send_message.message, 'entities': results.results[page].send_message.entities}
try:
photo = url = None
if getattr(result, 'photo', None) is not None:
photo = Photo._parse(client, results.results[page].photo)
await message.reply_cached_media(photo.file_id, caption=text, parse_mode='through')
else:
url = results.results[page].content.url
try:
if photo is not None:
await message.reply_cached_media(photo.file_id, caption=text, parse_mode='through')
else:
await message.reply_photo(url, caption=text, parse_mode='through')
except Forbidden:
await message.reply_text(text, disable_web_page_preview=True, parse_mode='through')

View File

@ -17,11 +17,19 @@ async def loli(client, message):
if result.type != 'photo':
await to_reply.reply_text({'message': result.send_message.message, 'entities': result.send_message.entities}, parse_mode='through')
return
photo = Photo._parse(client, result.photo)
photo = url = None
if getattr(result, 'photo', None) is not None:
photo = Photo._parse(client, result.photo)
else:
url = result.content.url
text = {'message': result.send_message.message, 'entities': result.send_message.entities}
try:
await to_reply.reply_cached_media(photo.file_id, caption={'message': result.send_message.message, 'entities': result.send_message.entities}, parse_mode='through')
if photo is not None:
await to_reply.reply_cached_media(photo.file_id, caption=text, parse_mode='through')
else:
await to_reply.reply_photo(url, caption=text, parse_mode='through')
except Forbidden:
await to_reply.reply_text({'message': result.send_message.message, 'entities': result.send_message.entities}, parse_mode='through')
await to_reply.reply_text(text, parse_mode='through')
help_dict['loli'] = ('Loli',
'''{prefix}loli <i>[keywords]</i> - Gets a possibly nsfw image of a loli, thanks to lolicon.app

View File

@ -1,6 +1,7 @@
import os
import logging
import requests
from urllib.parse import urlparse
from pyrogram import Client, filters
from pyrogram.types.messages_and_media import Photo, Animation
from pyrogram.errors.exceptions.forbidden_403 import Forbidden
@ -19,14 +20,14 @@ def _generate(i):
to_reply = message
if not getattr(message.reply_to_message, 'empty', True):
to_reply = message.reply_to_message
if result.type == 'photo':
file = Photo._parse(client, result.photo)
else:
file = Animation._parse(client, result.document, result.document.attributes, 'hello.mp4')
try:
await to_reply.reply_cached_media(file.file_id, caption=result.send_message.message, parse_mode=None)
animation = os.path.splitext(urlparse(result.send_message.message).path)[1] == '.gif'
if animation:
await to_reply.reply_animation(result.send_message.message, caption=result.send_message.message)
else:
await to_reply.reply_photo(result.send_message.message, caption=result.send_message.message)
except Forbidden:
await to_reply.reply_text(result.send_message.message, parse_mode=None)
await to_reply.reply_text(result.send_message.message)
return func
try: