1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Handle if the avatar is too large

This commit is contained in:
phxntxm 2017-05-29 16:27:25 -05:00
parent d5b1f0a64d
commit bf5f65b0b7

View file

@ -8,6 +8,7 @@ from bs4 import BeautifulSoup as bs
from . import utils
class Images:
def __init__(self, bot):
self.bot = bot
@ -29,11 +30,10 @@ class Images:
return
image = await utils.download_image(filename)
filename = re.search('.*\/i\/(.*)', filename).group(1)
filename = re.search('.*/i/(.*)', filename).group(1)
f = discord.File(image, filename=filename)
await ctx.send(file=f)
@commands.command(aliases=['dog', 'rd'])
@utils.custom_perms(send_messages=True)
async def doggo(self, ctx):
@ -88,8 +88,11 @@ class Images:
if filedata is None:
await ctx.send(url)
else:
f = discord.File(filedata, filename=filename)
await ctx.send(file=f)
try:
f = discord.File(filedata, filename=filename)
await ctx.send(file=f)
except discord.HTTPException:
await ctx.send("Sorry but that avatar is too large for me to send!")
else:
await ctx.send(url)
@ -149,7 +152,7 @@ class Images:
# Get the image link from the now random page'd and random result from that page
index = random.SystemRandom().randint(0, len(results) - 1)
#image_link = 'https://derpibooru.org/{}'.format(results[index]['id'])
# image_link = 'https://derpibooru.org/{}'.format(results[index]['id'])
image_link = 'https:{}'.format(results[index]['image'])
else:
await ctx.send("No results with that search term, {0}!".format(ctx.message.author.mention))
@ -205,5 +208,6 @@ class Images:
await ctx.send("No results with that tag {}".format(ctx.message.author.mention))
return
def setup(bot):
bot.add_cog(Images(bot))