-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (27 loc) · 991 Bytes
/
main.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
import multiprocessing
from utils import *
from metrics import *
from os.path import join, dirname
from dotenv import dotenv_values
from telethon import TelegramClient, events
dotenv_path = join(dirname(__file__), '.env')
config = dotenv_values(dotenv_path)
keywords = {'планируется перекрытие'}
monitored_chats = ['@gibdd_rme', '@mariroads_testsource']
client = TelegramClient('rb_user_session', config['API_ID'], config['API_HASH'])
@client.on(events.NewMessage(chats=monitored_chats))
async def handler(event):
hasSomeKeyword = False
strippedText = stripAll(event.text)
for keyword in keywords:
if keyword in strippedText:
hasSomeKeyword = True
break
if hasSomeKeyword:
await event.message.forward_to(config['TARGET_CHANEL_ID'])
if __name__ == '__main__':
bg_send_metrics = multiprocessing.Process(target=send_metrics)
bg_send_metrics.start()
client.start()
client.run_until_disconnected()
bg_send_metrics.terminate()