Skip to content

Commit

Permalink
add telegram check messages interval (#4919)
Browse files Browse the repository at this point in the history
* add telegram check messages interval

* config changed

* fix config

* telegram doc update
  • Loading branch information
askovpen authored and mjmadsen committed Aug 30, 2016
1 parent d7cf555 commit 94c4343
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
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

0 comments on commit 94c4343

Please sign in to comment.