diff --git a/configs/config.json.example b/configs/config.json.example index 3527fad4ba..d7b74d830c 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -153,6 +153,7 @@ "type": "EvolvePokemon", "config": { "enabled": false, + "log_interval": 120, "// evolve only pidgey and drowzee": "", "// evolve_list": "pidgey, drowzee", diff --git a/docs/configuration_files.md b/docs/configuration_files.md index 441d70bf48..8eac5b2c4a 100644 --- a/docs/configuration_files.md +++ b/docs/configuration_files.md @@ -193,6 +193,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json` * EvolvePokemon * `enable`: Disable or enable this task. * `evolve_all`: Default `NONE` | Depreciated. Please use evolve_list and donot_evolve_list + * `log_interval`: `Default: 120`. Time (in seconds) to periodically print how far you are from having enough pokemon to evolve (more than `min_pokemon_to_be_evolved`) * `evolve_list`: Default `all` | Set to all, or specifiy different pokemon seperated by a comma * `donot_evolve_list`: Default `none` | Pokemon seperated by comma, will be ignored from evolve_list * `min_evolve_speed`: Default `25` | Minimum seconds to wait between each evolution diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index dddff7da51..2a3cfd66c4 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -117,7 +117,7 @@ def __init__(self, db, config): self.heartbeat_counter = 0 self.last_heartbeat = time.time() self.hb_locked = False # lock hb on snip - + # Inventory refresh limiting self.inventory_refresh_threshold = 10 self.inventory_refresh_counter = 0 @@ -477,6 +477,10 @@ def _register_events(self): 'pokemon_evolved', parameters=('pokemon', 'iv', 'cp', 'candy', 'xp') ) + self.event_manager.register_event( + 'pokemon_evolve_check', + parameters=('has', 'needs') + ) self.event_manager.register_event( 'pokemon_upgraded', parameters=('pokemon', 'iv', 'cp', 'candy', 'stardust') @@ -1476,4 +1480,4 @@ def _refresh_inventory(self): inventory.refresh_inventory() self.last_inventory_refresh = now self.inventory_refresh_counter += 1 - + diff --git a/pokemongo_bot/cell_workers/evolve_pokemon.py b/pokemongo_bot/cell_workers/evolve_pokemon.py index f21c6d9251..e634b9c3db 100644 --- a/pokemongo_bot/cell_workers/evolve_pokemon.py +++ b/pokemongo_bot/cell_workers/evolve_pokemon.py @@ -17,6 +17,8 @@ def __init__(self, bot, config): def initialize(self): self.start_time = 0 + self.next_log_update = None + self.log_interval = self.config.get('log_interval', 120) self.evolve_list = self.config.get('evolve_list', []) self.donot_evolve_list = self.config.get('donot_evolve_list', []) self.min_evolve_speed = self.config.get('min_evolve_speed', 25) @@ -41,7 +43,7 @@ def initialize(self): def _validate_config(self): if isinstance(self.evolve_list, basestring): self.evolve_list = [str(pokemon_name).lower().strip() for pokemon_name in self.evolve_list.split(',')] - + if isinstance(self.donot_evolve_list, basestring): self.donot_evolve_list = [str(pokemon_name).lower().strip() for pokemon_name in self.donot_evolve_list.split(',')] @@ -65,7 +67,10 @@ def work(self): candy = inventory.candies().get(pokemon.pokemon_id) pokemon_to_be_evolved = pokemon_to_be_evolved + min(candy.quantity / (pokemon.evolution_cost - 1), filtered_dict[pokemon.pokemon_id]) - if pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved: + self._log_update_if_should(pokemon_to_be_evolved, self.min_pokemon_to_be_evolved) + + has_minimum_to_evolve = pokemon_to_be_evolved >= self.min_pokemon_to_be_evolved + if has_minimum_to_evolve: if self.use_lucky_egg: self._use_lucky_egg() cache = {} @@ -73,11 +78,26 @@ def work(self): if pokemon.can_evolve_now(): self._execute_pokemon_evolve(pokemon, cache) + def _log_update_if_should(self, has, needs): + self._compute_next_log_update() + if self._should_log_update: + self.emit_event( + 'pokemon_evolve_check', + formatted='Evolvable: {has}/{need}', + data={'has': has, 'needs': needs} + ) + + def _compute_next_log_update(self): + self.next_log_update = datetime.now() + timedelta(seconds=self.log_interval) + + def _should_log_update(self): + return datetime.now() >= self.next_log_update + def _should_run(self): if not self.evolve_list or self.evolve_list[0] == 'none': return False return True - + def _use_lucky_egg(self): using_lucky_egg = time.time() - self.start_time < 1800 if using_lucky_egg: diff --git a/pokemongo_bot/event_handlers/logging_handler.py b/pokemongo_bot/event_handlers/logging_handler.py index b433b7e4b6..d0291c0f0e 100644 --- a/pokemongo_bot/event_handlers/logging_handler.py +++ b/pokemongo_bot/event_handlers/logging_handler.py @@ -61,6 +61,7 @@ class LoggingHandler(EventHandler): 'pokemon_capture_failed': 'red', 'pokemon_caught': 'blue', 'pokemon_evolved': 'green', + 'pokemon_evolve_check': 'green', 'pokemon_fled': 'red', 'pokemon_inventory_full': 'red', 'pokemon_nickname_invalid': 'red',