Skip to content

Commit

Permalink
Don't kill bot in case of unexpected moveset, use fallback + better e…
Browse files Browse the repository at this point in the history
…rror message
  • Loading branch information
amal committed Aug 11, 2016
1 parent 5df73ec commit 0dcb305
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pokemongo_bot/inventory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import os

from pokemongo_bot.base_dir import _base_dir
Expand Down Expand Up @@ -482,7 +483,7 @@ def __init__(self, data):
self.max_cp = self._static_data['max_cp']

self.fast_attack = FastAttacks.data_for(data['move_1'])
self.charged_attack = ChargedAttacks.data_for(data['move_2'])
self.charged_attack = ChargedAttacks.data_for(data['move_2']) # type: ChargedAttack

# Internal values (IV) perfection percent
self.iv = self._compute_iv_perfection()
Expand Down Expand Up @@ -608,8 +609,13 @@ def _get_moveset(self):
break

if current_moveset is None:
raise Exception("Unexpected moveset [{}, {}] for #{} {}".format(
move1, move2, self.pokemon_id, self.name))
error = "Unexpected moveset [{}, {}] for #{} {}," \
" please update info in pokemon.json and create issue/PR"\
.format(move1, move2, self.pokemon_id, self.name)
# raise ValueError(error)
logging.getLogger(type(self).__name__).error(error)
current_moveset = Moveset(
move1, move2, self._static_data['types'], self.pokemon_id)

return current_moveset

Expand Down Expand Up @@ -676,6 +682,9 @@ def is_charged(self):
class Moveset(object):
def __init__(self, fm, chm, pokemon_types=(), pokemon_id=-1):
# type: (Attack, ChargedAttack, List[string], int) -> None
if len(pokemon_types) <= 0 < pokemon_id:
pokemon_types = Pokemons.data_for(pokemon_id)['types']

self.pokemon_id = pokemon_id
self.fast_attack = fm
self.charged_attack = chm
Expand Down

0 comments on commit 0dcb305

Please sign in to comment.