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

add telegram check messages interval #4919

Merged
merged 4 commits into from
Aug 30, 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
11 changes: 6 additions & 5 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
"config": {
"enabled": false,
"master": null,
"min_interval": 120,
"// 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}
}
"// new syntax:": {},
"alert_catch": {
"all": {"operator": "and", "cp": 1300, "iv": 0.95},
"Snorlax": {"operator": "or", "cp": 900, "iv": 0.9}
}
}
},
{
Expand Down
13 changes: 8 additions & 5 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,9 @@ Bot answer on command '/info' self stats.
### Options

* `telegram_token` : bot token (getting [there](https://core.telegram.org/bots#6-botfather) - one token per bot)
* `master` : id (without quotes) or username (in quotes, first character @) of bot owner, who will gett announces.
* `alert_catch` : array of pokemons, which will be announced on catch. if first array item `all` - announce all pokemons.
* `master` : id (without quotes) of bot owner, who will gett announces.
* `alert_catch` : dict of rules pokemons catch.
* `min_interval`: min interval check messages from telegram.

### Sample configuration
[[back to top](#table-of-contents)]
Expand All @@ -1000,9 +1001,11 @@ Bot answer on command '/info' self stats.
"config": {
"enabled": true,
"master": 12345678,
"//master": "@username",
"alert_catch": ["Lapras","Dragonite"],
"//alert_catch": ["all"]
"min_interval": 120,
"alert_catch": {
"all": {"operator": "and", "cp": 1300, "iv": 0.95},
"Snorlax": {"operator": "or", "cp": 900, "iv": 0.9}
}
}
}
```
11 changes: 9 additions & 2 deletions pokemongo_bot/cell_workers/telegram_task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import datetime
import telegram
import os
import logging
Expand All @@ -17,7 +18,9 @@ class TelegramTask(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
update_id = None
tbot = None

min_interval=None
next_job=None

def initialize(self):
if not self.enabled:
return
Expand All @@ -35,10 +38,14 @@ def initialize(self):
self.update_id = self.tbot.getUpdates()[0].update_id
except IndexError:
self.update_id = None

self.min_interval=self.config.get('min_interval',120)
self.next_job=datetime.now() + timedelta(seconds=self.min_interval)
def work(self):
if not self.enabled:
return
if datetime.now()<self.next_job:
return
self.next_job=datetime.now() + timedelta(seconds=self.min_interval)
for update in self.tbot.getUpdates(offset=self.update_id, timeout=10):
self.update_id = update.update_id+1
if update.message:
Expand Down