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

Telegram optimization #5445

Merged
merged 3 commits into from
Sep 15, 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
23 changes: 11 additions & 12 deletions pokemongo_bot/cell_workers/catch_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(self):
def work(self):
# make sure we have SOME balls
if sum([inventory.items().get(ball.value).count for ball in
[Item.ITEM_POKE_BALL, Item.ITEM_GREAT_BALL, Item.ITEM_ULTRA_BALL]]) <= 0:
[Item.ITEM_POKE_BALL, Item.ITEM_GREAT_BALL, Item.ITEM_ULTRA_BALL]]) <= 0:
return WorkerResult.ERROR

# check if we have already loaded a list
Expand Down Expand Up @@ -65,22 +65,21 @@ def get_visible_pokemon(self):
for pokemon in pokemon_to_catch:
# Update web UI
with open(user_web_catchable, 'w') as outfile:
json.dump(pokemon, outfile)

json.dump(pokemon, outfile)

self.emit_event(
'catchable_pokemon',
level='debug',
data={
'pokemon_id': pokemon['pokemon_id'],
'spawn_point_id': pokemon['spawn_point_id'],
'encounter_id': pokemon['encounter_id'],
'latitude': pokemon['latitude'],
'longitude': pokemon['longitude'],
'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'],
'pokemon_name': Pokemons.name_for(pokemon['pokemon_id']),
}
)
'pokemon_id': pokemon['pokemon_id'],
'spawn_point_id': pokemon['spawn_point_id'],
'encounter_id': pokemon['encounter_id'],
'latitude': pokemon['latitude'],
'longitude': pokemon['longitude'],
'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'],
'pokemon_name': Pokemons.name_for(pokemon['pokemon_id']),
}
)

self.add_pokemon(pokemon)

Expand Down
29 changes: 28 additions & 1 deletion pokemongo_bot/event_handlers/telegram_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ def display_events(self, update):
# no filter
event_filter = ".*"
events = filter(lambda k: re.match(event_filter, k), self.bot.event_manager._registered_events.keys())
events.remove('vanish_log')
events.remove('eggs_hatched_log')
events.remove('catch_log')
events.remove('pokestop_log')
events.remove('load_cached_location')
events.remove('location_cache_ignored')
events.remove('softban_log')
events.remove('loaded_cached_forts')
events.remove('login_log')
events.remove('evolve_log')
events.remove('transfer_log')
events.remove('catchable_pokemon')
self.sendMessage(chat_id=update.message.chat_id, parse_mode='HTML', text=("\n".join(events)))

def showtop(self, chatid, num, order):
Expand Down Expand Up @@ -530,10 +542,25 @@ def handle_event(self, event, sender, level, formatted_msg, data):
for sub in subs:
(uid, params, event_type) = sub
if event != 'pokemon_caught' or self.catch_notify(data["pokemon"], int(data["cp"]), float(data["iv"]), params):
if event_type == "debug":
if event == 'vanish_log' \
or event == 'eggs_hatched_log' \
or event == 'catch_log' \
or event == 'pokestop_log' \
or event == 'load_cached_location' \
or event == 'location_cache_ignored' \
or event == 'softban_log' \
or event == 'loaded_cached_forts' \
or event == 'login_log' \
or event == 'evolve_log' \
or event == 'catchable_pokemon' \
or event == 'transfer_log':
pass
elif event_type == "debug":
self.bot.logger.info("[{}] {}".format(event, msg))

else:
self.tbot.sendMessage(chat_id=uid, parse_mode='Markdown', text=msg)

if hasattr(self, "master") and self.master:
if not unicode(self.master).isnumeric():
# master not numeric?...
Expand Down