1
0
Fork 0
mirror of synced 2024-06-03 03:04:33 +12:00

Added a soft fail if there is no result found for the search for the e621 command

This commit is contained in:
Phxntxm 2016-07-21 07:30:04 -05:00
parent 65c0628a0b
commit 42090a39f6

View file

@ -247,7 +247,13 @@ class Core:
request = urllib.request.Request(url, headers={'User-Agent': 'Bonfire/1.0'})
with urllib.request.urlopen(request) as response:
data = json.loads(response.read().decode('utf-8'))
rand_image = data[random.randint(0, len(data)-1)]['file_url']
if len(data) == 0:
await self.bot.say("No results with that image {}".format(ctx.message.author.mention))
return
elif len(data) == 1:
rand_image data[0]['file_url']
else:
rand_image = data[random.randint(0, len(data)-1)]['file_url']
await self.bot.say(rand_image)