2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-22 10:09:40 +00:00
microbot/ubot/modules/catdog.py

110 lines
3.1 KiB
Python
Raw Normal View History

2020-03-16 21:02:05 -04:00
# SPDX-License-Identifier: GPL-2.0-or-later
2023-10-16 09:46:31 -04:00
2020-06-19 14:40:41 -04:00
from ubot.micro_bot import ldr
2023-10-16 09:46:31 -04:00
CAT_URL = 'http://api.thecatapi.com/v1/images/search'
DOG_URL = 'http://api.thedogapi.com/v1/images/search'
SHIBE_URL = 'http://shibe.online/api/shibes'
BIRD_URL = 'http://shibe.online/api/birds'
CAT_API_KEY = 'e5a56813-be40-481c-9c8a-a6585c37c1fe'
DOG_API_KEY = '105555df-5c50-40fe-bd59-d15a17ce1c2e'
CAT_HEADERS = {"x-api-key": CAT_API_KEY}
DOG_HEADERS = {"x-api-key": DOG_API_KEY}
IMGPARAM = {"mime_types": "jpg,png"}
GIFPARAM = {"mime_types": "gif"}
2020-05-24 12:44:02 -04:00
MIMGPARAM = {"mime_types": "jpg,png", "limit": 6}
2023-10-16 09:46:31 -04:00
async def neko_atsume(params):
2020-05-09 13:15:08 -04:00
async with ldr.aioclient.get(CAT_URL, params=params, headers=CAT_HEADERS) as response:
2023-10-16 09:46:31 -04:00
if response.status == 200:
neko = await response.json()
else:
neko = response.status
return neko
async def inu_atsume(params):
2020-05-09 13:15:08 -04:00
async with ldr.aioclient.get(DOG_URL, params=params, headers=DOG_HEADERS) as response:
2023-10-16 09:46:31 -04:00
if response.status == 200:
inu = await response.json()
else:
inu = response.status
return inu
async def shibe_inu_atsume():
2020-05-09 13:15:08 -04:00
async with ldr.aioclient.get(SHIBE_URL, params=None, headers=None) as response:
2023-10-16 09:46:31 -04:00
if response.status == 200:
shibe_inu = await response.json()
else:
shibe_inu = response.status
return shibe_inu
async def tori_atsume():
2020-05-09 13:15:08 -04:00
async with ldr.aioclient.get(BIRD_URL, params=None, headers=None) as response:
2023-10-16 09:46:31 -04:00
if response.status == 200:
tori = await response.json()
else:
tori = response.status
return tori
@ldr.add("shibe")
2023-10-16 09:46:31 -04:00
async def shibe(event):
shibe_inu = await shibe_inu_atsume()
if isinstance(shibe_inu, int):
2020-06-06 11:04:14 -04:00
await event.reply(f"There was an error finding the shibes! :( -> **{shibe_inu}**")
2023-10-16 09:46:31 -04:00
return
await event.reply(file=shibe_inu[0])
@ldr.add("bird")
2023-10-16 09:46:31 -04:00
async def bird(event):
tori = await tori_atsume()
if isinstance(tori, int):
2020-06-06 11:04:14 -04:00
await event.reply(f"There was an error finding the birdies! :( -> **{tori}**")
2023-10-16 09:46:31 -04:00
return
await event.reply(file=tori[0])
2020-06-16 17:26:04 -04:00
@ldr.add_list(["cat", "pussy"], pattern_extra="(gif|)(f|)")
2023-10-16 09:46:31 -04:00
async def cat(event):
2020-06-16 17:26:04 -04:00
neko = await neko_atsume(GIFPARAM if event.pattern_match.group(1) else IMGPARAM)
2023-10-16 09:46:31 -04:00
if isinstance(neko, int):
2020-06-06 11:04:14 -04:00
await event.reply(f"There was an error finding the cats! :( -> **{neko}**")
2023-10-16 09:46:31 -04:00
return
2020-06-16 17:26:04 -04:00
await event.reply(file=neko[0]["url"], force_document=bool(event.pattern_match.group(2)))
2023-10-16 09:46:31 -04:00
2020-06-16 17:26:04 -04:00
@ldr.add_list(["dog", "bitch"], pattern_extra="(gif|)(f|)")
2023-10-16 09:46:31 -04:00
async def dog(event):
2020-06-16 17:26:04 -04:00
inu = await inu_atsume(GIFPARAM if event.pattern_match.group(1) else IMGPARAM)
2023-10-16 09:46:31 -04:00
if isinstance(inu, int):
2020-06-06 11:04:14 -04:00
await event.reply(f"There was an error finding the dogs! :( -> **{inu}**")
2023-10-16 09:46:31 -04:00
return
2020-06-16 17:26:04 -04:00
await event.reply(file=inu[0]["url"], force_document=bool(event.pattern_match.group(2)))
2020-05-24 12:35:53 -04:00
@ldr.add_inline_photo("cat", default="cat")
async def cat_inline(event):
2020-05-24 12:44:02 -04:00
return [neko["url"] for neko in await neko_atsume(MIMGPARAM)]
2020-05-24 12:35:53 -04:00
@ldr.add_inline_photo("dog", default="dog")
async def dog_inline(event):
2020-05-24 12:44:02 -04:00
return [inu["url"] for inu in await inu_atsume(MIMGPARAM)]