1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00
royalnet/royalpack/commands/pug.py

27 lines
881 B
Python
Raw Normal View History

2020-05-19 16:46:49 +00:00
from typing import *
import royalnet.commands as rc
import aiohttp
import io
class PugCommand(rc.Command):
name: str = "pug"
description: str = "Invia un carlino casuale in chat."
syntax: str = ""
aliases = ["carlino", "carlo", "mallllco"]
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
async with aiohttp.ClientSession() as session:
async with session.get("https://dog.ceo/api/breed/pug/images/random") as response:
result = await response.json()
assert "status" in result
assert result["status"] == "success"
assert "message" in result
url = result["message"]
async with session.get(url) as response:
img = await response.content.read()
await data.reply_image(image=io.BytesIO(img))