From 2127bef8d7464f1c7fcd0b61dc104f090139e4ec Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Tue, 9 Aug 2016 23:56:29 +0200 Subject: [PATCH 1/4] changes to improve event system based on new web ui devs requests --- pokemongo_bot/__init__.py | 25 +++++++++++++++---- .../cell_workers/pokemon_catch_worker.py | 18 +++++++++++-- pokemongo_bot/socketio_server/app.py | 6 ++--- pokemongo_bot/step_walker.py | 11 ++++++++ pokemongo_bot/websocket_remote_control.py | 9 +++++-- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 133bb4631e..7e9e3eaf89 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -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') @@ -268,7 +272,13 @@ 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') @@ -276,7 +286,11 @@ def _register_events(self): '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( @@ -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() diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index d551a68632..345fcabc7e 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -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 } ) @@ -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 @@ -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 } ) diff --git a/pokemongo_bot/socketio_server/app.py b/pokemongo_bot/socketio_server/app.py index 09c237f910..7f3c5040d2 100644 --- a/pokemongo_bot/socketio_server/app.py +++ b/pokemongo_bot/socketio_server/app.py @@ -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) diff --git a/pokemongo_bot/step_walker.py b/pokemongo_bot/step_walker.py index f6c2cbfe96..7727dc6a0c 100644 --- a/pokemongo_bot/step_walker.py +++ b/pokemongo_bot/step_walker.py @@ -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( + '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 diff --git a/pokemongo_bot/websocket_remote_control.py b/pokemongo_bot/websocket_remote_control.py index c4e15362b6..14645e6572 100644 --- a/pokemongo_bot/websocket_remote_control.py +++ b/pokemongo_bot/websocket_remote_control.py @@ -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 } From c556b48aa9a34d5d93e1827784461b42b09c2900 Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Wed, 10 Aug 2016 01:34:40 +0200 Subject: [PATCH 2/4] typo :D --- pokemongo_bot/websocket_remote_control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/websocket_remote_control.py b/pokemongo_bot/websocket_remote_control.py index 14645e6572..023db22ff4 100644 --- a/pokemongo_bot/websocket_remote_control.py +++ b/pokemongo_bot/websocket_remote_control.py @@ -42,7 +42,7 @@ def on_remote_command(self, command): command_handler() def get_player_info(self): - request = self.api.create_request() + request = self.bot.api.create_request() request.get_player() request.get_inventory() response_dict = request.call() From 9c1a9435daaf547acd069a5c40270191b2a16d60 Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Wed, 10 Aug 2016 02:13:21 +0200 Subject: [PATCH 3/4] let's use dict.get a bit to avoid errors --- brantje.py | 9 +++++++++ pokemongo_bot/websocket_remote_control.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 brantje.py diff --git a/brantje.py b/brantje.py new file mode 100644 index 0000000000..0674ceb077 --- /dev/null +++ b/brantje.py @@ -0,0 +1,9 @@ +# coding: utf-8 +from socketIO_client import SocketIO +s = SocketIO('localhost', 4000) +def echo(msg): + print msg + +s.on('get_player_info:d.camata@gmail.com', echo) +s.emit('remote:send_request', {'account': 'd.camata@gmail.com', 'name': 'get_player_info'}) +s.wait(1) diff --git a/pokemongo_bot/websocket_remote_control.py b/pokemongo_bot/websocket_remote_control.py index 023db22ff4..cd5bd5af96 100644 --- a/pokemongo_bot/websocket_remote_control.py +++ b/pokemongo_bot/websocket_remote_control.py @@ -46,8 +46,8 @@ def get_player_info(self): request.get_player() request.get_inventory() response_dict = request.call() - inventory = response_dict['responses']['GET_INVENTORY'] - player_info = response_dict['responses']['GET_PLAYER'] + inventory = response_dict['responses'].get('GET_INVENTORY', {}) + player_info = response_dict['responses'].get('GET_PLAYER', {}) self.sio.emit( 'bot:send_reply', { From 61df52fb4d3b517620fcb48be20345ecadc7e295 Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Wed, 10 Aug 2016 02:13:55 +0200 Subject: [PATCH 4/4] keeping the account in the remote command response --- pokemongo_bot/socketio_server/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/socketio_server/app.py b/pokemongo_bot/socketio_server/app.py index 7f3c5040d2..a970a30479 100644 --- a/pokemongo_bot/socketio_server/app.py +++ b/pokemongo_bot/socketio_server/app.py @@ -20,7 +20,7 @@ def remote_control(sid, command): @sio.on('bot:send_reply') def request_reply(sid, response): event = response.pop('command') - account = response.pop('account') + account = response['account'] event = "{}:{}".format(event, account) sio.emit(event, response)