2020-06-04 20:29:55 -04:00
|
|
|
import io
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2020-09-13 13:50:36 -04:00
|
|
|
from ubot import ldr
|
2020-05-07 13:03:06 -04:00
|
|
|
|
|
|
|
NEKO_URL = "https://nekos.life/api/v2/img/"
|
2022-08-02 17:22:15 -04:00
|
|
|
NEKO_TYPES_NSFW = ['lewd', 'gasm', 'spank']
|
|
|
|
NEKO_TYPES = ['neko', 'smug', 'cuddle', 'hug', 'goose', 'waifu', 'slap', 'pat', 'woof', 'kiss']
|
|
|
|
REPLY_TYPES = ['cuddle', 'hug', 'slap', 'spank', 'pat', 'kiss']
|
2020-05-07 13:03:06 -04:00
|
|
|
|
|
|
|
|
2020-06-29 10:19:33 -04:00
|
|
|
@ldr.add_list(NEKO_TYPES_NSFW, nsfw=True, pattern_extra="(f|)", userlocking=True)
|
|
|
|
@ldr.add_list(NEKO_TYPES, pattern_extra="(f|)", userlocking=True)
|
2020-05-07 13:03:06 -04:00
|
|
|
async def supernekoatsume(event):
|
2021-01-14 16:42:32 -05:00
|
|
|
nekotype = event.object.pattern
|
2020-06-22 21:53:11 -04:00
|
|
|
as_file = bool(event.other_args[0])
|
2020-05-07 13:03:06 -04:00
|
|
|
|
2022-11-26 12:37:59 -05:00
|
|
|
if nekotype in REPLY_TYPES and event.is_reply:
|
|
|
|
reply_to = await event.get_reply_message()
|
2020-05-07 13:20:52 -04:00
|
|
|
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:
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply(f"An error occurred, response code: **{response.status}**")
|
2020-05-07 13:03:06 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2023-04-26 10:37:38 -04:00
|
|
|
await event.respond(file=image_url, force_document=as_file, reply_to=reply_to, spoiler=event.chat_db.spoiler_nsfw and event.object.nsfw)
|
2020-05-07 13:03:06 -04:00
|
|
|
except:
|
2020-06-06 11:04:14 -04:00
|
|
|
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:
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply(f"An error occurred, response code: **{response.status}**")
|
2020-06-04 20:29:55 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
async with ldr.aioclient.get(image_url) as response:
|
|
|
|
if response.status == 200:
|
|
|
|
image_data = await response.read()
|
|
|
|
else:
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply(f"An error occurred, response code: **{response.status}**")
|
2020-06-04 20:29:55 -04:00
|
|
|
return
|
|
|
|
|
2020-12-04 21:03:55 -05:00
|
|
|
try:
|
|
|
|
await event.reply(file=await ldr.run_async(eightballsync, image_data))
|
|
|
|
except:
|
|
|
|
await event.reply("Failed to send 8ball! :(")
|
|
|
|
|
|
|
|
|
|
|
|
def eightballsync(image_data):
|
2020-06-04 20:29:55 -04:00
|
|
|
sticker_image = Image.open(io.BytesIO(image_data))
|
2020-12-04 21:03:55 -05:00
|
|
|
sticker_image = sticker_image.resize((512, 512), Image.BILINEAR)
|
2020-06-04 20:29:55 -04:00
|
|
|
sticker_io = io.BytesIO()
|
|
|
|
sticker_image.save(sticker_io, "WebP", quality=99)
|
|
|
|
sticker_io.seek(0)
|
|
|
|
sticker_io.name = "sticker.webp"
|
|
|
|
|
2020-12-04 21:03:55 -05:00
|
|
|
return sticker_io
|