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 api issues when session stale #5482

Merged
merged 1 commit into from
Sep 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pokemongo_bot/cell_workers/complete_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class CompleteTutorial(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.api = self.bot.api
self.nickname = self.config.get('nickname','')
self.team = self.config.get('team',0)
self.tutorial_run = True
Expand Down Expand Up @@ -96,7 +95,7 @@ def _encounter_tutorial(self):
# You just need to call the API with the pokemon you choose
# Probably can't get MewTwo as first pokemon though
first_pokemon_id = random.choice([1, 4, 7])
response_dict = self.api.encounter_tutorial_complete(
response_dict = self.bot.api.encounter_tutorial_complete(
pokemon_id=first_pokemon_id)
try:
if response_dict['responses']['ENCOUNTER_TUTORIAL_COMPLETE']['result'] == 1:
Expand Down Expand Up @@ -128,7 +127,7 @@ def _random_avatar(self):

def _set_avatar(self):
avatar = self._random_avatar()
response_dict = self.api.set_avatar(player_avatar=avatar)
response_dict = self.bot.api.set_avatar(player_avatar=avatar)
status = response_dict['responses']['SET_AVATAR']['status']
try:
if status == 1:
Expand All @@ -147,7 +146,7 @@ def _set_avatar(self):
return False

def _set_nickname(self, nickname):
response_dict = self.api.claim_codename(codename=nickname)
response_dict = self.bot.api.claim_codename(codename=nickname)
try:
result = response_dict['responses']['CLAIM_CODENAME']['status']
if result == 1:
Expand All @@ -170,7 +169,7 @@ def _set_nickname(self, nickname):
return False

def _set_tutorial_state(self, completed):
response_dict = self.api.mark_tutorial_complete(tutorials_completed=[
response_dict = self.bot.api.mark_tutorial_complete(tutorials_completed=[
completed], send_marketing_emails=False, send_push_notifications=False)
try:
self._player = response_dict['responses'][
Expand All @@ -189,7 +188,7 @@ def _set_team(self):
return True

sleep(10)
response_dict = self.api.set_player_team(team=self.team)
response_dict = self.bot.api.set_player_team(team=self.team)
try:
result = response_dict['responses']['SET_PLAYER_TEAM']['status']
if result == 1:
Expand Down
3 changes: 1 addition & 2 deletions pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(self, bot, config):

def initialize(self):
self.start_time = 0
self.api = self.bot.api
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)
Expand Down Expand Up @@ -148,7 +147,7 @@ def _execute_pokemon_evolve(self, pokemon, cache):
if pokemon.name in cache:
return False

response_dict = self.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
response_dict = self.bot.api.evolve_pokemon(pokemon_id=pokemon.unique_id)
if response_dict.get('responses', {}).get('EVOLVE_POKEMON', {}).get('result', 0) == 1:
xp = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("experience_awarded", 0)
evolution = response_dict.get("responses", {}).get("EVOLVE_POKEMON", {}).get("evolved_pokemon_data", {})
Expand Down
7 changes: 3 additions & 4 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(self, pokemon, bot, config):
super(PokemonCatchWorker, self).__init__(bot, config)

def initialize(self):
self.api = self.bot.api
self.position = self.bot.position
self.pokemon_list = self.bot.pokemon_list
self.inventory = inventory.items()
Expand Down Expand Up @@ -210,7 +209,7 @@ def create_encounter_api_call(self):
player_latitude = self.pokemon['latitude']
player_longitude = self.pokemon['longitude']

request = self.api.create_request()
request = self.bot.api.create_request()
if 'spawn_point_id' in self.pokemon:
spawn_point_id = self.pokemon['spawn_point_id']
self.spawn_point_guid = spawn_point_id
Expand Down Expand Up @@ -348,7 +347,7 @@ def _use_berry(self, berry_id, berry_count, encounter_id, catch_rate_by_ball, cu
}
)

response_dict = self.api.use_item_capture(
response_dict = self.bot.api.use_item_capture(
item_id=berry_id,
encounter_id=encounter_id,
spawn_point_id=self.spawn_point_guid
Expand Down Expand Up @@ -523,7 +522,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
if random() >= self.catch_throw_parameters_hit_rate and not is_vip:
hit_pokemon = 0

response_dict = self.api.catch_pokemon(
response_dict = self.bot.api.catch_pokemon(
encounter_id=encounter_id,
pokeball=current_ball,
normalized_reticle_size=throw_parameters['normalized_reticle_size'],
Expand Down
3 changes: 1 addition & 2 deletions pokemongo_bot/walkers/step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class StepWalker(object):
def __init__(self, bot, dest_lat, dest_lng, dest_alt=None, precision=0.5):
self.bot = bot
self.api = bot.api
self.epsilon = 0.01
self.precision = max(precision, self.epsilon)

Expand Down Expand Up @@ -38,7 +37,7 @@ def step(self, speed=None):

new_position = self.get_next_position(origin_lat, origin_lng, origin_alt, self.dest_lat, self.dest_lng, self.dest_alt, speed)

self.api.set_position(new_position[0], new_position[1], new_position[2])
self.bot.api.set_position(new_position[0], new_position[1], new_position[2])
self.bot.event_manager.emit("position_update",
sender=self,
level="debug",
Expand Down