Skip to content

Commit

Permalink
changes to improve event system based on new web ui devs requests
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascamata committed Aug 9, 2016
1 parent b94d369 commit 2127bef
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
25 changes: 20 additions & 5 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def _register_events(self):
'cp',
'iv',
'iv_display',
'encounter_id',
'latitude',
'longitude',
'pokemon_id'
)
)
self.event_manager.register_event('no_pokeballs')
Expand Down Expand Up @@ -268,15 +272,25 @@ def _register_events(self):
)
self.event_manager.register_event(
'pokemon_vanished',
parameters=('pokemon',)
parameters=(
'pokemon',
'encounter_id',
'latitude',
'longitude',
'pokemon_id'
)
)
self.event_manager.register_event('pokemon_not_in_range')
self.event_manager.register_event('pokemon_inventory_full')
self.event_manager.register_event(
'pokemon_caught',
parameters=(
'pokemon',
'cp', 'iv', 'iv_display', 'exp'
'cp', 'iv', 'iv_display', 'exp',
'encounter_id',
'latitude',
'longitude',
'pokemon_id'
)
)
self.event_manager.register_event(
Expand Down Expand Up @@ -988,9 +1002,10 @@ def heartbeat(self):
pass

def update_web_location_worker(self):
while True:
self.web_update_queue.get()
self.update_web_location()
pass
# while True:
# self.web_update_queue.get()
# self.update_web_location()

def get_inventory_count(self, what):
response_dict = self.get_inventory()
Expand Down
18 changes: 16 additions & 2 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def work(self, response_dict=None):
'cp': pokemon.cp,
'iv': pokemon.iv,
'iv_display': pokemon.iv_display,
'encounter_id': self.pokemon['encounter_id'],
'latitude': self.pokemon['latitude'],
'longitude': self.pokemon['longitude'],
'pokemon_id': pokemon.num
}
)

Expand Down Expand Up @@ -370,7 +374,13 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
self.emit_event(
'pokemon_vanished',
formatted='{pokemon} vanished!',
data={'pokemon': pokemon.name}
data={
'pokemon': pokemon.name,
'encounter_id': self.pokemon['encounter_id'],
'latitude': self.pokemon['latitude'],
'longitude': self.pokemon['longitude'],
'pokemon_id': pokemon.num
}
)
if self._pct(catch_rate_by_ball[current_ball]) == 100:
self.bot.softban = True
Expand All @@ -386,7 +396,11 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):
'cp': pokemon.cp,
'iv': pokemon.iv,
'iv_display': pokemon.iv_display,
'exp': sum(response_dict['responses']['CATCH_POKEMON']['capture_award']['xp'])
'exp': sum(response_dict['responses']['CATCH_POKEMON']['capture_award']['xp']),
'encounter_id': self.pokemon['encounter_id'],
'latitude': self.pokemon['latitude'],
'longitude': self.pokemon['longitude'],
'pokemon_id': pokemon.num
}
)

Expand Down
6 changes: 3 additions & 3 deletions pokemongo_bot/socketio_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def request_reply(sid, response):

@sio.on('bot:broadcast')
def bot_broadcast(sid, env):
event = env.pop('event')
account = env.pop('account')
event = env['event']
account = env['account']
event_name = "{}:{}".format(event, account)
sio.emit(event_name, data=env['data'])
sio.emit(event_name, data=env)
11 changes: 11 additions & 0 deletions pokemongo_bot/step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ def step(self):
cLng = self.initLng + scaledDLng + random_lat_long_delta()

self.api.set_position(cLat, cLng, 0)
self.bot.event_manager.emit(

This comment has been minimized.

Copy link
@salavert

salavert Aug 10, 2016

No need to spam current position

This comment has been minimized.

Copy link
@douglascamata

douglascamata Aug 10, 2016

Author Member

It's not spammed, it's in debug level (users only see info level by default) and if we want new web UIs to show the bot slowly walking we will need this.

This comment has been minimized.

Copy link
@salavert

salavert Aug 10, 2016

I see, then what do you think about formatting it?

dist = distance(
            cLat,
            cLng,
            self.initLat,
            self.initLng
        )

formatted="Walking from {last_position} to {current_position} ({distance} {distance_unit})",

This comment has been minimized.

Copy link
@douglascamata

douglascamata Aug 10, 2016

Author Member

@salavert not really necessary, because this is meant for debugging purposes. Only devs are supposed no analyse debug level logs The default event msg will be enough.

This comment has been minimized.

Copy link
@nearalias

This comment has been minimized.

Copy link
@douglascamata

douglascamata Aug 11, 2016

Author Member

@nearalias #3431 is not related to the default LoggingHandler, but to the coloured one, which has a very poor implementation.

'position_update',
sender=self,
level='debug',
data={
'current_position': (cLat, cLng),
'last_position': (self.initLat, self.initLng),
'distance': '',
'distance_unit': ''
}
)
self.bot.heartbeat()

sleep(1) # sleep one second plus a random delta
Expand Down
9 changes: 7 additions & 2 deletions pokemongo_bot/websocket_remote_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ def on_remote_command(self, command):
command_handler()

def get_player_info(self):
player_info = self.bot.get_inventory()['responses']['GET_INVENTORY']
request = self.api.create_request()
request.get_player()
request.get_inventory()
response_dict = request.call()
inventory = response_dict['responses']['GET_INVENTORY']
player_info = response_dict['responses']['GET_PLAYER']
self.sio.emit(
'bot:send_reply',
{
'result': player_info,
'result': {'inventory': inventory, 'player': player_info},
'command': 'get_player_info',
'account': self.bot.config.username
}
Expand Down

0 comments on commit 2127bef

Please sign in to comment.