From 399d8a206c3cff7d47853830ea43c2cbfd1dcf32 Mon Sep 17 00:00:00 2001 From: blank X Date: Fri, 7 May 2021 18:14:24 +0700 Subject: [PATCH] Add loli --- example-config.yaml | 1 + sukuinote/plugins/loli.py | 27 ++++++++++++++++++++++++++ sukuinote/slave-plugins/loli.py | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 sukuinote/plugins/loli.py create mode 100644 sukuinote/slave-plugins/loli.py diff --git a/example-config.yaml b/example-config.yaml index 705f694..a0afdc9 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -12,6 +12,7 @@ config: log_chat: -1001278205033 spamwatch_api: https://t.me/SpamWatchBot saucenao_api: https://saucenao.com/user.php?page=search-api + lolicon_api: https://t.me/setu_robot log_user_joins: false log_user_adds: true log_reports: true diff --git a/sukuinote/plugins/loli.py b/sukuinote/plugins/loli.py new file mode 100644 index 0000000..08d21f2 --- /dev/null +++ b/sukuinote/plugins/loli.py @@ -0,0 +1,27 @@ +from pyrogram import Client, filters +from pyrogram.errors.exceptions.forbidden_403 import Forbidden +from .. import slave, config, help_dict, log_errors, public_log_errors + +@Client.on_message(~filters.forwarded & ~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command(['loli', 'sfwloli', 'sloli', 'nsfwloli', 'nloli'], prefixes=config['config']['prefixes'])) +@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) + try: + await message.reply_inline_bot_result(results.query_id, results.results[0].id) + except Forbidden: + await message.reply_text({'message': results.results[0].send_message.message, 'entities': results.results[0].send_message.entities}, disable_web_page_preview=True, parse_mode='through') + +help_dict['loli'] = ('Loli', +'''{prefix}loli [keywords] - Gets a possibly nsfw image of a loli, thanks to lolicon.app +Can also be activated inline with: @{bot} loli [keywords] + +{prefix}sfwloli [keywords] - Gets a sfw image of a loli, thanks to lolicon.app +Aliases: {prefix}sloli +Can also be activated inline with: @{bot} sfwloli [keywords] or @{bot} sloli [keywords] + +{prefix}nsfwloli [keywords] - Gets an nsfw image of a loli, thanks to lolicon.app +Aliases: {prefix}nloli +Can also be activated inline with: @{bot} nsfwloli [keywords] or @{bot} nloli [keywords]''') diff --git a/sukuinote/slave-plugins/loli.py b/sukuinote/slave-plugins/loli.py new file mode 100644 index 0000000..9fd25f5 --- /dev/null +++ b/sukuinote/slave-plugins/loli.py @@ -0,0 +1,34 @@ +import html +from urllib.parse import quote as urlencode +from pyrogram import Client, filters +from pyrogram.types import InputTextMessageContent, InlineQueryResultArticle, InlineQueryResultPhoto +from .. import log_errors, session, app_user_ids, config + +@Client.on_inline_query(filters.regex(f'^(s(?:fw)?|n(?:sfw)?)?loli(.*)$')) +@log_errors +async def loli(client, inline_query): + if inline_query.from_user.id not in app_user_ids: + await inline_query.answer([InlineQueryResultArticle('...no', InputTextMessageContent('...no'))], cache_time=3600, is_personal=True) + return + match = inline_query.matches[0] + if mode := match.group(1): + if mode.startswith('s'): + mode = 0 + else: + mode = 1 + else: + mode = 2 + async with session.get(f'https://api.lolicon.app/setu?num=1&r18={mode}&keyword={urlencode(match.group(2).strip())}&apikey={urlencode(config["config"].get("lollicon_api", ""))}') as resp: + data = await resp.json() + if data['code'] or data['msg']: + item = InlineQueryResultArticle(f'Error {data["code"]}', InputTextMessageContent(f'{html.escape(str(data["code"]))}: {html.escape(data["msg"])}', description=data['msg'] or None, parse_mode='html')) + else: + data = data['data'][0] + title = f'{data["title"]} by {data["author"]}' + description = None + caption = f'{html.escape(data["title"])} by {html.escape(data["author"]}\n' + if data['tags']: + caption += f'Tags: {html.escape(", ".join(data["tags"]))}' + description = f'Tags: {", ".join(data["tags"])}' + item = InlineQueryResultPhoto(data['url'], title=title, description=description, caption=caption, parse_mode='html') + await inline_query.answer([item], cache_time=0)