1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/royalpack/commands/dog.py

182 lines
4.7 KiB
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
2020-07-18 14:29:43 +00:00
class DogCommand(rc.Command):
name: str = "dog"
2020-05-19 16:46:49 +00:00
2020-07-18 14:29:43 +00:00
description: str = "Invia un cane della razza specificata in chat."
2020-05-19 16:46:49 +00:00
2020-07-18 14:53:14 +00:00
syntax: str = "[razza|list]"
_breeds = [
"affenpinscher",
"african",
"airedale",
"akita",
"appenzeller",
2020-08-23 21:52:35 +00:00
"australian/shepherd",
2020-07-18 14:53:14 +00:00
"basenji",
"beagle",
"bluetick",
"borzoi",
"bouvier",
"boxer",
"brabancon",
"briard",
2020-08-23 21:52:35 +00:00
"buhund/norwegian",
"bulldog/boston",
"bulldog/english",
"bulldog/french",
"bullterrier/staffordshire",
2020-07-18 14:53:14 +00:00
"cairn",
2020-08-23 21:52:35 +00:00
"cattledog/australian",
2020-07-18 14:53:14 +00:00
"chihuahua",
"chow",
"clumber",
"cockapoo",
2020-08-23 21:52:35 +00:00
"collie/border",
2020-07-18 14:53:14 +00:00
"coonhound",
2020-08-23 21:52:35 +00:00
"corgi/cardigan",
2020-07-18 14:53:14 +00:00
"cotondetulear",
"dachshund",
"dalmatian",
2020-08-23 21:52:35 +00:00
"dane/great",
"deerhound/scottish",
2020-07-18 14:53:14 +00:00
"dhole",
"dingo",
"doberman",
2020-08-23 21:52:35 +00:00
"elkhound/norwegian",
2020-07-18 14:53:14 +00:00
"entlebucher",
"eskimo",
2020-08-23 21:52:35 +00:00
"finnish/lapphund",
"frise/bichon",
2020-07-18 14:53:14 +00:00
"germanshepherd",
2020-08-23 21:52:35 +00:00
"greyhound/italian",
2020-07-18 14:53:14 +00:00
"groenendael",
"havanese",
2020-08-23 21:52:35 +00:00
"hound/afghan",
"hound/basset",
"hound/blood",
"hound/english",
"hound/ibizan",
"hound/plott",
"hound/walker",
2020-07-18 14:53:14 +00:00
"husky",
"keeshond",
"kelpie",
"komondor",
"kuvasz",
"labrador",
"leonberg",
"lhasa",
"malamute",
"malinois",
"maltese",
2020-08-23 21:52:35 +00:00
"mastiff/bull",
"mastiff/english",
"mastiff/tibetan",
2020-07-18 14:53:14 +00:00
"mexicanhairless",
"mix",
2020-08-23 21:52:35 +00:00
"mountain/bernese",
"mountain/swiss",
2020-07-18 14:53:14 +00:00
"newfoundland",
"otterhound",
2020-08-23 21:52:35 +00:00
"ovcharka/caucasian",
2020-07-18 14:53:14 +00:00
"papillon",
"pekinese",
"pembroke",
2020-08-23 21:52:35 +00:00
"pinscher/miniature",
2020-07-18 14:53:14 +00:00
"pitbull",
2020-08-23 21:52:35 +00:00
"pointer/german",
"pointer/germanlonghair",
2020-07-18 14:53:14 +00:00
"pomeranian",
2020-08-23 21:52:35 +00:00
"poodle/miniature",
"poodle/standard",
"poodle/toy",
2020-07-18 14:53:14 +00:00
"pug",
"puggle",
"pyrenees",
"redbone",
2020-08-23 21:52:35 +00:00
"retriever/chesapeake",
"retriever/curly",
"retriever/flatcoated",
"retriever/golden",
"ridgeback/rhodesian",
2020-07-18 14:53:14 +00:00
"rottweiler",
"saluki",
"samoyed",
"schipperke",
2020-08-23 21:52:35 +00:00
"schnauzer/giant",
"schnauzer/miniature",
"setter/english",
"setter/gordon",
"setter/irish",
"sheepdog/english",
"sheepdog/shetland",
2020-07-18 14:53:14 +00:00
"shiba",
"shihtzu",
2020-08-23 21:52:35 +00:00
"spaniel/blenheim",
"spaniel/brittany",
"spaniel/cocker",
"spaniel/irish",
"spaniel/japanese",
"spaniel/sussex",
"spaniel/welsh",
"springer/english",
2020-07-18 14:53:14 +00:00
"stbernard",
2020-08-23 21:52:35 +00:00
"terrier/american",
"terrier/australian",
"terrier/bedlington",
"terrier/border",
"terrier/dandie",
"terrier/fox",
"terrier/irish",
"terrier/kerryblue",
"terrier/lakeland",
"terrier/norfolk",
"terrier/norwich",
"terrier/patterdale",
"terrier/russell",
"terrier/scottish",
"terrier/sealyham",
"terrier/silky",
"terrier/tibetan",
"terrier/toy",
"terrier/westhighland",
"terrier/wheaten",
"terrier/yorkshire",
2020-07-18 14:53:14 +00:00
"vizsla",
2020-08-23 21:52:35 +00:00
"waterdog/spanish",
2020-07-18 14:53:14 +00:00
"weimaraner",
"whippet",
2020-08-23 21:52:35 +00:00
"wolfhound/irish",
2020-07-18 14:53:14 +00:00
]
2020-05-19 16:46:49 +00:00
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
2020-07-18 14:29:43 +00:00
breed = args.joined()
if breed:
2020-07-18 14:53:14 +00:00
if breed == "list":
2020-07-31 14:17:28 +00:00
await data.reply("\n".join([" Razze disponibili:", *[f"[c]{breed}[/c]" for breed in self._breeds]]))
2020-07-18 14:53:14 +00:00
if breed in self._breeds:
url = f"https://dog.ceo/api/breed/{breed}/images/random"
else:
raise rc.InvalidInputError("Questa razza non è disponibile.\n")
2020-07-18 14:29:43 +00:00
else:
url = f"https://dog.ceo/api/breeds/image/random"
2020-05-19 16:46:49 +00:00
async with aiohttp.ClientSession() as session:
2020-07-18 14:29:43 +00:00
async with session.get(url) as response:
if response.status >= 400:
raise rc.ExternalError(f"Request returned {response.status}")
2020-05-19 16:46:49 +00:00
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))