Browse Source

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

master
Adam Piontek 1 year ago
parent
commit
43f539bdd3
1 changed files with 10 additions and 9 deletions
  1. +10
    -9
      doggo.py

+ 10
- 9
doggo.py View File

@@ -32,16 +32,17 @@ class Doggo(BotPlugin):
# But what if user passed us a sub-breed?
if len(args) > 1 and args[1]:
subbreed = args[1]
if len(self.breeds[breed]) == 0:
if 'calledbyfunction' not in args:
args.append('calledbyfunction')
self.reloadsubbreeds(msg, args)
if subbreed != 'calledbyfunction':
if len(self.breeds[breed]) == 0:
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)
if 'calledbyfunction' not in args:
args.append('calledbyfunction')
self.reloadsubbreeds(msg, args)
if len(self.breeds[breed]) == 0:
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:
resp = requests.get(url)

Loading…
Cancel
Save