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 fix #5398

Merged
merged 17 commits into from
Sep 12, 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
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _execute_pokemon_evolve(self, pokemon, cache):

self.emit_event(
'pokemon_evolved',
formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [{candy} candies] [+{xp} xp]",
formatted="*Evolved {}* (IV {}) (CP {}) ({} candies) (+{} xp)".format(pokemon.name, pokemon.iv, pokemon.cp, candy.quantity, xp),
data={
'pokemon': pokemon.name,
'iv': pokemon.iv,
Expand Down
6 changes: 3 additions & 3 deletions pokemongo_bot/cell_workers/nickname_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,21 @@ def _nickname_pokemon(self, pokemon):
if result == 0:
self.emit_event(
'unset_pokemon_nickname',
formatted="Pokemon {old_name} nickname unset.",
formatted="Pokemon {} nickname unset.".format(old_nickname),
data={'old_name': old_nickname}
)
pokemon.update_nickname(new_nickname)
elif result == 1:
self.emit_event(
'rename_pokemon',
formatted="Pokemon {old_name} renamed to {current_name}",
formatted="*{} Renamed* to {}".format(old_nickname, new_nickname),
data={'old_name': old_nickname, 'current_name': new_nickname}
)
pokemon.update_nickname(new_nickname)
elif result == 2:
self.emit_event(
'pokemon_nickname_invalid',
formatted="Nickname {nickname} is invalid",
formatted="Nickname {} is invalid".format(new_nickname),
data={'nickname': new_nickname}
)
else:
Expand Down
6 changes: 3 additions & 3 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def work(self, response_dict=None):
self.bot.skipped_pokemon.append(pokemon)
self.emit_event(
'pokemon_appeared',
formatted='Skip ignored {pokemon}! [CP {cp}] [Potential {iv}] [A/D/S {iv_display}]',
formatted='Skip ignored {}! (CP {}) (Potential {}) (A/D/S {})'.format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.iv_display),
data={
'pokemon': pokemon.name,
'cp': pokemon.cp,
Expand All @@ -154,7 +154,7 @@ def work(self, response_dict=None):
# log encounter
self.emit_event(
'pokemon_appeared',
formatted='A wild {pokemon} appeared! [CP {cp}] [NCP {ncp}] [Potential {iv}] [A/D/S {iv_display}]',
formatted='*A wild {} appeared!* (CP: {}) (NCP: {}) (Potential {}) (A/D/S {})'.format(pokemon.name, pokemon.cp, round(pokemon.cp_percent, 2), pokemon.iv, pokemon.iv_display),
data={
'pokemon': pokemon.name,
'ncp': round(pokemon.cp_percent, 2),
Expand Down Expand Up @@ -543,7 +543,7 @@ def _do_catch(self, pokemon, encounter_id, catch_rate_by_ball, is_vip=False):

self.emit_event(
'pokemon_vanished',
formatted='{pokemon} vanished!',
formatted='{} vanished!'.format(pokemon.name),
data={
'pokemon': pokemon.name,
'encounter_id': self.pokemon['encounter_id'],
Expand Down
4 changes: 2 additions & 2 deletions pokemongo_bot/cell_workers/show_best_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def print_pokemons(self, pokemons):
"""
self.emit_event(
'show_best_pokemon',
formatted="{pokemons}",
formatted="*Best Pokemons* {pokemons}",
data={
'pokemons': pokemons
}
Expand Down Expand Up @@ -146,7 +146,7 @@ def get_poke_info_formatted(info, pokemon):
pokemons_ordered = sorted(self.pokemons, key=lambda x: get_poke_info(self.order_by, x), reverse=True)
pokemons_ordered = pokemons_ordered[:self.amount]

poke_info = ['[{}]'.format(', '.join([get_poke_info_formatted(x, p) for x in info_to_show])) for p in pokemons_ordered]
poke_info = ['({})'.format(', '.join([get_poke_info_formatted(x, p) for x in info_to_show])) for p in pokemons_ordered]

line = ' | '.join(poke_info)
return line
9 changes: 5 additions & 4 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,16 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False):
if logic_to_function[cp_iv_logic](*release_results.values()):
self.emit_event(
'future_pokemon_release',
formatted="Releasing {pokemon} [CP {cp}] [IV {iv}] based on rule: CP < {below_cp} {cp_iv_logic} IV < {below_iv}",
formatted="*Releasing {}* CP: {}, IV: {} | based on rule: CP < {} {} IV < {}".format(pokemon.name, pokemon.cp, pokemon.iv,
release_cp, cp_iv_logic.upper(),release_cp),
data={
'pokemon': pokemon.name,
'cp': pokemon.cp,
'iv': pokemon.iv,
'below_cp': release_cp,
'cp_iv_logic': cp_iv_logic.upper(),
'below_iv': release_iv
}
},
)

return logic_to_function[cp_iv_logic](*release_results.values())
Expand Down Expand Up @@ -204,13 +205,13 @@ def release_pokemon(self, pokemon):
self.bot.metrics.released_pokemon()
self.emit_event(
'pokemon_release',
formatted='Exchanged {pokemon} [IV {iv}] [CP {cp}] [{candy} candies]',
data={
'pokemon': pokemon.name,
'iv': pokemon.iv,
'cp': pokemon.cp,
'candy': candy.quantity
}
},
formatted="*{} Released* You now have {} {} candies".format(pokemon.name, candy.quantity, pokemon.name),
)
with self.bot.database as conn:
c = conn.cursor()
Expand Down
26 changes: 11 additions & 15 deletions pokemongo_bot/event_handlers/telegram_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def showtop(self, chatid, num, order):

pkmns = sorted(inventory.pokemons().all(), key=lambda p: getattr(p, order), reverse=True)[:num]

outMsg = "\n".join(["{} CP:{} IV:{} ID:{} Candy:{}".format(p.name, p.cp, p.iv, p.unique_id, inventory.candies().get(p.pokemon_id).quantity) for p in pkmns])
outMsg = "\n".join(["<b>{}</b> \nCP: {} \nIV: {} \nCandy: {}\n".format(p.name, p.cp, p.iv, inventory.candies().get(p.pokemon_id).quantity) for p in pkmns])
self.sendMessage(chat_id=chatid, parse_mode='HTML', text=outMsg)

return
Expand Down Expand Up @@ -460,7 +460,8 @@ def __init__(self, bot, config):
if master == None:
self.master = None
return

else:
self.master = master
with self.bot.database as conn:
# if master is not numeric, try to fetch it from the database
if not unicode(master).isnumeric():
Expand Down Expand Up @@ -489,8 +490,6 @@ def catch_notify(self, pokemon, cp, iv, params):
except:
return False



def handle_event(self, event, sender, level, formatted_msg, data):
if self.tbot is None:
try:
Expand Down Expand Up @@ -520,14 +519,6 @@ def handle_event(self, event, sender, level, formatted_msg, data):
msg = "*You have reached your daily catch limit, quitting.*"
elif event == 'spin_limit':
msg = "*You have reached your daily spin limit, quitting.*"
elif event == 'bot_random_pause':
msg = "Taking a random break until {}.".format(data["resume"])
elif event == 'bot_random_alive_pause':
msg = "Taking a random break until {}.".format(data["resume"])
elif event == 'log_stats':
msg = "{}".format(data["msg"])
elif event == 'show_inventory':
msg = "{}".format(data["msg"])
else:
msg = formatted_msg
except KeyError:
Expand All @@ -543,9 +534,6 @@ def handle_event(self, event, sender, level, formatted_msg, data):
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 All @@ -555,6 +543,14 @@ def handle_event(self, event, sender, level, formatted_msg, data):

if event == 'level_up':
msg = "level up ({})".format(data["current_level"])
elif event == 'log_stats':
msg = "{}".format(data["msg"])
elif event == 'show_inventory':
msg = "{}".format(data["msg"])
elif event == 'bot_random_pause':
msg = "Taking a random break until {}.".format(data["resume"])
elif event == 'bot_random_alive_pause':
msg = "Taking a random break until {}.".format(data["resume"])
elif event == 'pokemon_caught':
if isinstance(self.pokemons, list): # alert_catch is a plain list
if data["pokemon"] in self.pokemons or "all" in self.pokemons:
Expand Down
2 changes: 1 addition & 1 deletion web