forked from khoben/telemirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
telecopy.py
41 lines (35 loc) · 1.04 KB
/
telecopy.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
"""
Make full copy of telegram channel
"""
import time
from telethon.sessions import StringSession
from telethon.sync import TelegramClient
from telethon.tl.types import MessageService
# put your values
# Telegram API
API_HASH = "xxx"
API_ID = "xxx"
# Session string by login.py
SESSION_STRING = "xxx"
SOURCE_CHAT = '@xxx'
TARGET_CHAT = '@xxx'
# Timeout after 50 messages
LIMIT_TO_WAIT = 50
def do_full_copy():
with TelegramClient(StringSession(SESSION_STRING), API_ID, API_HASH) as client:
amount_sended = 0
for message in client.iter_messages(SOURCE_CHAT):
# skip if service messages
if isinstance(message, MessageService):
continue
try:
client.send_message(TARGET_CHAT, message)
amount_sended += 1
if amount_sended >= LIMIT_TO_WAIT:
amount_sended = 0
time.sleep(1)
except Exception as e:
print(e)
print("Done")
if __name__ == "__main__":
do_full_copy()