2020-05-07 13:03:06 -04:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2020-06-04 20:29:55 -04:00
|
|
|
import io
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2020-05-07 13:03:06 -04:00
|
|
|
from ubot.micro_bot import micro_bot
|
|
|
|
|
|
|
|
ldr = micro_bot.loader
|
|
|
|
|
|
|
|
NEKO_URL = "https://nekos.life/api/v2/img/"
|
2020-06-05 21:28:37 -04:00
|
|
|
NEKO_TYPES = "neko|lewd|smug|tits|trap|anal|cuddle|hug|goose|waifu|gasm|slap|spank|pat|feet|woof|baka"
|
|
|
|
REPLY_TYPES = "cuddle hug slap spank pat baka"
|
2020-05-07 13:03:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
@ldr.add(f"({NEKO_TYPES})(f|)")
|
|
|
|
async def supernekoatsume(event):
|
|
|
|
nekotype = event.pattern_match.group(1)
|
|
|
|
as_file = bool(event.pattern_match.group(2))
|
|
|
|
|
2020-05-07 13:20:52 -04:00
|
|
|
if nekotype in REPLY_TYPES:
|
|
|
|
reply_to = await event.get_reply_message() or event
|
|
|
|
else:
|
|
|
|
reply_to = event
|
|
|
|
|
2020-05-09 13:15:08 -04:00
|
|
|
async with ldr.aioclient.get(NEKO_URL + nekotype) as response:
|
2020-05-07 13:03:06 -04:00
|
|
|
if response.status == 200:
|
|
|
|
image_url = (await response.json())["url"]
|
|
|
|
else:
|
|
|
|
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2020-05-07 13:20:52 -04:00
|
|
|
await event.client.send_file(event.chat_id, file=image_url, force_document=as_file, reply_to=reply_to)
|
2020-05-07 13:03:06 -04:00
|
|
|
except:
|
|
|
|
await event.reply(f"`Failed to fetch media for query: `**{nekotype}**")
|
2020-06-04 20:29:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
@ldr.add("8ball")
|
|
|
|
async def eightball(event):
|
|
|
|
async with ldr.aioclient.get(NEKO_URL + "8ball") as response:
|
|
|
|
if response.status == 200:
|
|
|
|
image_url = (await response.json())["url"]
|
|
|
|
else:
|
|
|
|
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
|
|
|
return
|
|
|
|
|
|
|
|
async with ldr.aioclient.get(image_url) as response:
|
|
|
|
if response.status == 200:
|
|
|
|
image_data = await response.read()
|
|
|
|
else:
|
|
|
|
await event.reply(f"`An error occurred, response code: `**{response.status}**")
|
|
|
|
return
|
|
|
|
|
|
|
|
sticker_image = Image.open(io.BytesIO(image_data))
|
|
|
|
sticker_io = io.BytesIO()
|
|
|
|
sticker_image.save(sticker_io, "WebP", quality=99)
|
|
|
|
sticker_io.seek(0)
|
|
|
|
sticker_io.name = "sticker.webp"
|
|
|
|
|
|
|
|
try:
|
|
|
|
await event.reply(file=sticker_io)
|
|
|
|
except:
|
|
|
|
await event.reply(f"`Failed to send 8ball! :(`")
|