Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nickname #5031

Merged
merged 9 commits into from
Sep 1, 2016
10 changes: 6 additions & 4 deletions pokemongo_bot/cell_workers/move_to_map_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ def get_pokemon_from_social(self):
pokemon['longitude'],
)

if pokemon['dist'] > self.config['max_sniping_distance'] and self.config['snipe']:
# If distance to pokemon greater than the max_sniping_distance, then ignore regardless of "snipe" setting
if pokemon['dist'] > self.config.get('max_sniping_distance', 10000):
continue

if pokemon['dist'] > self.config['max_walking_distance'] and not self.config['snipe']:

# If distance bigger than walking distance, ignore if sniping is not active
if pokemon['dist'] > self.config.get('max_walking_distance', 1000) and not self.config.get('snipe', False):
continue

# pokemon not reachable with mean walking speed (by config)
# if pokemon not reachable with mean walking speed (by config)
mean_walk_speed = (self.bot.config.walk_max + self.bot.config.walk_min) / 2
if pokemon['dist'] > ((pokemon['disappear_time'] - now) * mean_walk_speed) and not self.config['snipe']:
continue
Expand Down
20 changes: 11 additions & 9 deletions pokemongo_bot/cell_workers/nickname_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import json
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.human_behaviour import sleep, action_delay
from pokemongo_bot.inventory import pokemons, Pokemon, Attack

import re
Expand Down Expand Up @@ -210,9 +210,9 @@ def work(self):
for pokemon in pokemons().all(): # type: Pokemon
if not pokemon.is_favorite or not self.ignore_favorites:
if pokemon.iv >= self.nickname_above_iv:
# Make the bot appears more human
action_delay(self.nickname_wait_min, self.nickname_wait_max)
self._nickname_pokemon(pokemon)
if self._nickname_pokemon(pokemon):
# Make the bot appears more human
action_delay(self.nickname_wait_min, self.nickname_wait_max)

def _localize(self, string):
if self.translate and string in self.translate:
Expand All @@ -221,7 +221,8 @@ def _localize(self, string):
return string

def _nickname_pokemon(self, pokemon):
# type: (Pokemon) -> None
# type: (Pokemon) -> bool
# returns False if no wait needed (no API calls tried before return), True if wait is needed
"""
Nicknaming process
"""
Expand All @@ -233,7 +234,7 @@ def _nickname_pokemon(self, pokemon):
'api_error',
formatted='Failed to get pokemon name, will not rename.'
)
return
return False

# Generate new nickname
old_nickname = pokemon.nickname
Expand All @@ -245,11 +246,11 @@ def _nickname_pokemon(self, pokemon):
formatted="Unable to nickname {} due to bad template ({})"
.format(old_nickname, bad_key)
)
return
return False

# Skip if pokemon is already well named
if pokemon.nickname_raw == new_nickname:
return
return False

# Send request
response = self.bot.api.nickname_pokemon(
Expand All @@ -265,7 +266,7 @@ def _nickname_pokemon(self, pokemon):
'api_error',
formatted='Attempt to nickname received bad response from server.'
)
return
return True

# Nickname unset
if result == 0:
Expand Down Expand Up @@ -294,6 +295,7 @@ def _nickname_pokemon(self, pokemon):
formatted='Attempt to nickname received unexpected result'
' from server ({}).'.format(result)
)
return True

def _generate_new_nickname(self, pokemon, template):
# type: (Pokemon, string) -> string
Expand Down