Skip to content

Commit

Permalink
Implemented more granularity in the "alert_catch" parameter for Telegram
Browse files Browse the repository at this point in the history
alerts.
  • Loading branch information
DBa2016 committed Aug 28, 2016
1 parent ec35ab2 commit e43f8f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
"config": {
"enabled": false,
"master": null,
"alert_catch": ["all"]
"// old syntax, still supported: alert_catch": ["all"],
"// new syntax:": {},
"alert_catch": {
"all": {"operator": "and", "cp": 1300, "iv": 0.95},
"Snorlax": {"operator": "or", "cp": 900, "iv": 0.9}
}
}
},
{
Expand Down
18 changes: 15 additions & 3 deletions pokemongo_bot/event_handlers/telegram_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@ def handle_event(self, event, sender, level, formatted_msg, data):
if event == 'level_up':
msg = "level up ({})".format(data["current_level"])
elif event == 'pokemon_caught':
if data["pokemon"] in self.pokemons or self.pokemons[0]=="all":
msg = "Caught {} CP: {}, IV: {}".format(data["pokemon"],data["cp"],data["iv"])
if isinstance(self.pokemons, list):
if data["pokemon"] in self.pokemons or "all" in self.pokemons:
msg = "Caught {} CP: {}, IV: {}".format(data["pokemon"],data["cp"],data["iv"])
else:
return
else:
return
if data["pokemon"] in self.pokemons:
trigger = self.pokemons[data["pokemon"]]
elif "all" in self.pokemons:
trigger = self.pokemons["all"]
else:
return
if (not "operator" in trigger or trigger["operator"] == "and") and data["cp"] >= trigger["cp"] and data["iv"] >= trigger["iv"] or ("operator" in trigger and trigger["operator"] == "or" and (data["cp"] >= trigger["cp"] or data["iv"] >= trigger["iv"])):
msg = "Caught {} CP: {}, IV: {}".format(data["pokemon"],data["cp"],data["iv"])
else:
return
else:
return
self.tbot.sendMessage(chat_id=master, parse_mode='Markdown', text=msg)
Expand Down

0 comments on commit e43f8f9

Please sign in to comment.