diff --git a/configs/config.json.example b/configs/config.json.example index 634ab60b13..5cb0d9c2d9 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -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} + } } }, { diff --git a/pokemongo_bot/event_handlers/telegram_handler.py b/pokemongo_bot/event_handlers/telegram_handler.py index b32a083225..4052e8c4ea 100644 --- a/pokemongo_bot/event_handlers/telegram_handler.py +++ b/pokemongo_bot/event_handlers/telegram_handler.py @@ -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)