Handle if the avatar is too large
This commit is contained in:
parent
d5b1f0a64d
commit
bf5f65b0b7
|
@ -8,6 +8,7 @@ from bs4 import BeautifulSoup as bs
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
class Images:
|
class Images:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -29,11 +30,10 @@ class Images:
|
||||||
return
|
return
|
||||||
|
|
||||||
image = await utils.download_image(filename)
|
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)
|
f = discord.File(image, filename=filename)
|
||||||
await ctx.send(file=f)
|
await ctx.send(file=f)
|
||||||
|
|
||||||
|
|
||||||
@commands.command(aliases=['dog', 'rd'])
|
@commands.command(aliases=['dog', 'rd'])
|
||||||
@utils.custom_perms(send_messages=True)
|
@utils.custom_perms(send_messages=True)
|
||||||
async def doggo(self, ctx):
|
async def doggo(self, ctx):
|
||||||
|
@ -88,8 +88,11 @@ class Images:
|
||||||
if filedata is None:
|
if filedata is None:
|
||||||
await ctx.send(url)
|
await ctx.send(url)
|
||||||
else:
|
else:
|
||||||
f = discord.File(filedata, filename=filename)
|
try:
|
||||||
await ctx.send(file=f)
|
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:
|
else:
|
||||||
await ctx.send(url)
|
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
|
# Get the image link from the now random page'd and random result from that page
|
||||||
index = random.SystemRandom().randint(0, len(results) - 1)
|
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'])
|
image_link = 'https:{}'.format(results[index]['image'])
|
||||||
else:
|
else:
|
||||||
await ctx.send("No results with that search term, {0}!".format(ctx.message.author.mention))
|
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))
|
await ctx.send("No results with that tag {}".format(ctx.message.author.mention))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Images(bot))
|
bot.add_cog(Images(bot))
|
||||||
|
|
Loading…
Reference in a new issue