fixing issue where trying to fetch a breed before breeds list loaded resulted in trying to fetch sub-breeds and then error

This commit is contained in:
Adam Piontek 2018-08-26 10:41:09 -04:00
parent 755ddc2f36
commit 43f539bdd3

View file

@ -32,16 +32,17 @@ class Doggo(BotPlugin):
# But what if user passed us a sub-breed? # But what if user passed us a sub-breed?
if len(args) > 1 and args[1]: if len(args) > 1 and args[1]:
subbreed = args[1] subbreed = args[1]
if len(self.breeds[breed]) == 0: if subbreed != 'calledbyfunction':
if 'calledbyfunction' not in args:
args.append('calledbyfunction')
self.reloadsubbreeds(msg, args)
if len(self.breeds[breed]) == 0: if len(self.breeds[breed]) == 0:
return 'No sub-breeds available for {}, so we cannot use {}.'.format(breed, subbreed) if 'calledbyfunction' not in args:
if subbreed in self.breeds[breed]: args.append('calledbyfunction')
url = '{}/breed/{}/{}/images/random'.format(self.BASE_URL, breed, subbreed) self.reloadsubbreeds(msg, args)
else: if len(self.breeds[breed]) == 0:
return 'Sub-breed of {} not found: {}. List sub-breeds with !listsubbreeds'.format(breed, subbreed) return 'No sub-breeds available for {}, so we cannot use {}.'.format(breed, subbreed)
if subbreed in self.breeds[breed]:
url = '{}/breed/{}/{}/images/random'.format(self.BASE_URL, breed, subbreed)
else:
return 'Sub-breed of {} not found: {}. List sub-breeds with !listsubbreeds'.format(breed, subbreed)
try: try:
resp = requests.get(url) resp = requests.get(url)