Skip to content

Commit

Permalink
Merge pull request #5544 from DBa2016/fix_chat_handler
Browse files Browse the repository at this point in the history
Fixing issues in event fitlering (/events command in chat handler)
  • Loading branch information
Gobberwart authored Sep 22, 2016
2 parents 7de764a + 19760bc commit e12bae9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
28 changes: 6 additions & 22 deletions pokemongo_bot/event_handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def get_player_stats(self):
"*" + self.bot.config.username + "*",
"_Level:_ " + str(stats["level"]),
"_XP:_ " + str(stats["experience"]) + "/" + str(stats["next_level_xp"]),
"_Pokemons Captured:_ " + str(stats["pokemons_captured"]) + " (" + str(catch_day) + " _last 24h_)",
"_Poke Stop Visits:_ " + str(stats["poke_stop_visits"]) + " (" + str(ps_day) + " _last 24h_)",
"_KM Walked:_ " + str("%.2f" % stats["km_walked"])
"_Pokemons Captured:_ " + str(stats.get("pokemons_captured",0)) + " (" + str(catch_day) + " _last 24h_)",
"_Poke Stop Visits:_ " + str(stats.get("poke_stop_visits",0)) + " (" + str(ps_day) + " _last 24h_)",
"_KM Walked:_ " + str("%.2f" % stats.get("km_walked",0))
)
return (res)
else:
Expand Down Expand Up @@ -65,27 +65,11 @@ def get_events(self, update):
cmd = update.message.text.split(" ", 1)
if len(cmd) > 1:
# we have a filter
event_filter = ".*{}-*".format(cmd[1])
event_filter = ".*{}.*".format(cmd[1])
else:
# 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')
events = sorted(events)
return events


return sorted(filter(lambda k: re.match(event_filter, k), self.bot.event_manager._registered_events.keys()))

def sendMessage(self, chat_id=None, parse_mode='Markdown', text=None):
try:
Expand Down Expand Up @@ -276,4 +260,4 @@ def evolve(self, chatid, uid):
def upgrade(self, chatid, uid):
# TODO: here comes upgrade logic (later)
self.sendMessage(chat_id=chatid, parse_mode='HTML', text="Upgrade logic not implemented yet")
return
return
5 changes: 4 additions & 1 deletion pokemongo_bot/event_handlers/telegram_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ def showsubs(self, chatid):
subs = []
with self.bot.database as conn:
for sub in conn.execute("select uid, event_type, parameters from telegram_subscriptions where uid = ?", [chatid]).fetchall():
subs.append("{} -> {}".format(sub[1], sub[2]))
if "{}".format(sub[2]) not in ["", " "]:
subs.append("<b>{}</b> -&gt; .{}.".format(sub[1], sub[2]))
else:
subs.append("<b>{}</b>".format(sub[1]))
if subs == []: subs.append("No subscriptions found. Subscribe using /sub EVENTNAME. For a list of events, send /events")
self.chat_handler.sendMessage(chat_id=chatid, parse_mode='HTML', text="\n".join(subs))

Expand Down

0 comments on commit e12bae9

Please sign in to comment.