-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlg.py
68 lines (59 loc) · 1.89 KB
/
tlg.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
import asyncio
import logging
from pathlib import Path
from telethon import TelegramClient, events
from iqlogger import Logger
from tlg_constants import TelegramConstants
# your main work, never block this thread
async def main():
i = 0
while True:
i += 1
await asyncio.sleep(1)
c = TelegramConstants()
sys.stdout = Logger(Path(__file__).parent.absolute())
tlgSessionPath = Path.joinpath(Path(__file__).parent.absolute(), 'tlgdb', 'leo123') # change this last name to your session variable
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
level=logging.WARNING)
tlg = TelegramClient(
session=str(tlgSessionPath),
api_id=c.api_id,
api_hash=c.api_hash,
)
@tlg.on(events.NewMessage)
async def my_handler(update):
"""update properties:
id
reply_to_msg_id
chat_id
raw_text
await update.get_chat()
await update.get_sender()"""
# chat = await update.get_chat()
# sender = await update.get_sender()
print(f'chat_id: {update.chat_id}')
print(f'id: {update.id}')
print(f'msg: {update.raw_text}')
print(f'is_channel: {update.is_channel}')
print('-----------------')
@tlg.on(events.MessageDeleted)
async def delete_handler(update):
# chat = await update.get_chat()
# sender = await update.get_sender()
# print(update.chat_id)
# print(update.raw_text)
# print('-----------------')
print(f'chat_id: {update.chat_id}')
print(f'is_channel: {update.is_channel}')
for msg_id in update.deleted_ids:
print('id: ', msg_id)
print(update)
print('-----------------')
try:
print(f'escutando para o número: {c.phone}')
tlg.start(c.phone)
asyncio.get_event_loop().run_until_complete(main())
except KeyboardInterrupt:
print('\nEvent removed and program finished.')
tlg.remove_event_handler(my_handler)