-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (48 loc) · 1.5 KB
/
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
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
"""
Forward messages from chat to other chat.
"""
import pyrogram
import settings
import forwarder
# Initialize Telegram client
client = pyrogram.Client(
name=settings.SESSION_NAME,
api_id=settings.API_ID,
api_hash=settings.API_HASH,
proxy=settings.PROXY if settings.PROXY["scheme"] else None,
device_model="PC",
system_version="Forwarder bot",
)
@client.on_message(pyrogram.filters.chat(settings.TARGET_CHAT_ID))
async def target_chat_handler(_, message: pyrogram.types.Message):
"""
Handle messages from target chat and forward this to forward chat.
:param _:
:param message: Message object
"""
await message.forward(settings.FORWARD_CHAT_ID)
@client.on_message(pyrogram.filters.chat(settings.FORWARD_CHAT_ID))
async def forward_chat_handler(_, message: pyrogram.types.Message):
"""
Handle messages from forward chat and forward this to target chat.
:param _:
:param message: Message object
"""
if not message.reply_to_message:
return
if not message.reply_to_message.forward_from:
return
if message.reply_to_message.from_user.id != client.me.id:
return
if message.from_user.id in settings.IGNORE_USERS_IDS:
return
await forwarder.forward_messages(
client,
chat_id=settings.TARGET_CHAT_ID,
from_chat_id=settings.FORWARD_CHAT_ID,
message_ids=message.id,
drop_author=settings.FORWARD_ANONYMOUS,
)
# Start client
if __name__ == "__main__":
client.run()