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

changes to improve event system based on new web ui devs requests #3352

Merged
merged 4 commits into from
Aug 10, 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
9 changes: 9 additions & 0 deletions brantje.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# coding: utf-8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this mean to be committed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove in future commit, sorry :P

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)
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
8 changes: 4 additions & 4 deletions pokemongo_bot/socketio_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ 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)

@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(
'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.bot.api.create_request()
request.get_player()
request.get_inventory()
response_dict = request.call()
inventory = response_dict['responses'].get('GET_INVENTORY', {})
player_info = response_dict['responses'].get('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