sukuinote/sukuinote/plugins/loli.py

45 lines
2.2 KiB
Python
Raw Normal View History

2021-05-07 11:14:24 +00:00
from pyrogram import Client, filters
from pyrogram.types.messages_and_media import Photo
2021-05-07 11:14:24 +00:00
from pyrogram.errors.exceptions.forbidden_403 import Forbidden
from .. import slave, config, help_dict, log_errors, public_log_errors
2021-09-28 15:25:54 +00:00
@Client.on_message(~filters.scheduled & ~filters.forwarded & ~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command(['loli', 'sfwloli', 'sloli', 'nsfwloli', 'nloli'], prefixes=config['config']['prefixes']))
2021-05-07 11:14:24 +00:00
@log_errors
@public_log_errors
async def loli(client, message):
bot = await slave.get_me()
query = ' '.join(message.command)
results = await client.get_inline_bot_results(bot.username or bot.id, query)
result = results.results[0]
to_reply = message
if not getattr(message.reply_to_message, 'empty', True):
to_reply = message.reply_to_message
2021-05-07 13:36:21 +00:00
if result.type != 'photo':
await to_reply.reply_text({'message': result.send_message.message, 'entities': result.send_message.entities}, parse_mode='through')
2021-05-07 13:36:21 +00:00
return
2021-08-20 13:16:09 +00:00
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}
2021-05-07 11:14:24 +00:00
try:
2021-08-20 13:16:09 +00:00
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')
2021-05-07 11:14:24 +00:00
except Forbidden:
2021-08-20 13:16:09 +00:00
await to_reply.reply_text(text, parse_mode='through')
2021-05-07 11:14:24 +00:00
help_dict['loli'] = ('Loli',
'''{prefix}loli <i>[keywords]</i> - Gets a possibly nsfw image of a loli, thanks to lolicon.app
Can also be activated inline with: @{bot} loli <i>[keywords]</i>
{prefix}sfwloli <i>[keywords]</i> - Gets a sfw image of a loli, thanks to lolicon.app
Aliases: {prefix}sloli
Can also be activated inline with: @{bot} sfwloli <i>[keywords]</i> or @{bot} sloli <i>[keywords]</i>
{prefix}nsfwloli <i>[keywords]</i> - Gets an nsfw image of a loli, thanks to lolicon.app
Aliases: {prefix}nloli
Can also be activated inline with: @{bot} nsfwloli <i>[keywords]</i> or @{bot} nloli <i>[keywords]</i>''')