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

Implemented more granular parameters for Telegram notifications #4874

Merged
merged 3 commits into from
Aug 29, 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
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"])):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's good logic operator code in the pokemon catch worker, would you like to use that code @DBa2016

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