1
0
Fork 0
mirror of synced 2024-05-02 03:32:24 +12:00

Change dog APIs, first one was failing

This commit is contained in:
Dan Hess 2021-03-25 17:54:01 -08:00
parent c03e228063
commit f048e532e0

View file

@ -24,12 +24,7 @@ class Images(commands.Cog):
else: else:
e = discord.Embed(title="Source", url=credit) e = discord.Embed(title="Source", url=credit)
e.set_image(url=url) e.set_image(url=url)
try: await ctx.send(embed=e)
await ctx.send(embed=e)
except discord.HTTPException:
await ctx.send(
f"File too large to send as attachment, here is the URL: {url}"
)
@commands.command(aliases=["rc"]) @commands.command(aliases=["rc"])
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
@ -42,18 +37,9 @@ class Images(commands.Cog):
opts = {"format": "src"} opts = {"format": "src"}
result = await utils.request(url, attr="url", payload=opts) result = await utils.request(url, attr="url", payload=opts)
try: e = discord.Embed(title="Source", url=str(result))
image = await utils.download_image(result) e.set_image(url=str(result))
except (ValueError, AttributeError): await ctx.send(embed=e)
await ctx.send("I couldn't connect! Sorry no cats right now ;w;")
f = discord.File(image, filename=result.name)
try:
await ctx.send(file=f)
except discord.HTTPException:
await ctx.send(
f"File to large to send as attachment, here is the URL: {url}"
)
@commands.command(aliases=["dog", "rd"]) @commands.command(aliases=["dog", "rd"])
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)
@ -62,22 +48,14 @@ class Images(commands.Cog):
EXAMPLE: !doggo EXAMPLE: !doggo
RESULT: A beautiful picture of a dog o3o""" RESULT: A beautiful picture of a dog o3o"""
result = await utils.request("https://random.dog/woof.json") result = await utils.request("https://dog.ceo/api/breeds/image/random")
try: try:
url = result.get("url") url = result.get("message")
filename = re.match("https://random.dog/(.*)", url).group(1) e = discord.Embed(title="Source", url=str(url))
e.set_image(url=str(url))
await ctx.send(embed=e)
except AttributeError: except AttributeError:
await ctx.send("I couldn't connect! Sorry no dogs right now ;w;") await ctx.send("I couldn't connect! Sorry no dogs right now ;w;")
return
image = await utils.download_image(url)
f = discord.File(image, filename=filename)
try:
await ctx.send(file=f)
except discord.HTTPException:
await ctx.send(
f"File to large to send as attachment, here is the URL: {url}"
)
@commands.command(aliases=["snake"]) @commands.command(aliases=["snake"])
@utils.can_run(send_messages=True) @utils.can_run(send_messages=True)