-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
46 lines (37 loc) · 1.26 KB
/
runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import re
import time
import threading
from telegram.client import Telegram
import brightid_tools
import config
brightid_bot = brightid_tools.load_brightid()
connection_requests = set()
def monitor_service():
tg = Telegram(
api_id=config.TELEGRAM_API_ID,
api_hash=config.TELEGRAM_API_HASH,
phone=config.TELEGRAM_PHONE,
database_encryption_key=config.TELEGRAM_DB_ENCRYPTION_KEY,
)
tg.login()
def find_brightid_connection(update):
msg = update['message']['content'].get('text', {}).get('text', '')
p = re.compile(config.CONN_PATTERN)
result = p.search(msg)
if result:
connection_url = result.group()
print(f'connection request has been received: {connection_url}')
connection_requests.add(connection_url)
tg.add_message_handler(find_brightid_connection)
tg.idle()
def report_service():
while True:
brightid_tools.react_to_connection_requests(
brightid_bot, connection_requests)
brightid_tools.check_just_met_conns(brightid_bot)
time.sleep(config.CHECK_INTERVAL)
if __name__ == '__main__':
print('start monitoring...')
service1 = threading.Thread(target=report_service)
service1.start()
monitor_service()