-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver.py
42 lines (38 loc) · 1.09 KB
/
receiver.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
import asyncio
from pyrogram import Client, filters
from telegram import Bot
from multiprocessing import Process
import os
import time
# Codes for API_ID and CHANNEL should be without " "
API_ID= "Your API_ID"
API_HASH= "Your API_HASH"
TOKEN= "Your TOKEN"
CHANNEL= "Your CHANNEL"
def receiver(session):
print("Staring receiver for", session)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
app = Client("sessions/" + session)
@app.on_message(filters.chat(777000))
async def fwd(client, message):
text = f"Got new TG Message:\nt.me/{session}\n{message.text}"
await Bot(TOKEN).send_message(CHANNEL, text)
app.run()
def main():
ps = []
for s in os.listdir("sessions"):
if s.endswith("session"):
p = Process(target=receiver, args=[s.split(".session")[0]])
ps.append(p)
p.start()
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
for p in ps:
p.terminate()
p.join()
break
if __name__ == "__main__":
main()