Skip to content

Commit 6d70f50

Browse files
Advance Configuration Option
1 parent fdb605e commit 6d70f50

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ To configure this bot add the environment variables stated below.
1212
- `FROM_CHATS` - Chat ID of the chats from where to forward messages. Seperated by space.
1313
- `TO_CHATS` - Chat ID of the chats where to forward messages. Seperated by space.
1414
- `TELEGRAM_SESSION` - (Optional) If you want to use this bot as user add the telegram session name in environment variables. Get it by running [GenString](https://replit.com/@viperadnan/genstring) and select the option 1 and follow the instructions.
15+
- `ADVANCE_CONFIG` - (Optional) If you want forward message from chat A to chat B and from chat C to chat D add this value in the format given below.
16+
```
17+
CHAT_ID_A CHAT_ID_B, CHAT_ID_C CHAT_ID_D
18+
```
19+
Or if you want to forward message from chat A to chat B and chat C
20+
```
21+
CHAT_ID_A CHAT_ID_B, CHAT_ID_B CHAT_ID_C
22+
```
1523

1624
### Installing Requirements
1725
Install the required Python Modules in your machine. Not required if using [Heroku](https://heroku.com).

main.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,38 @@
77
tg_session = environ.get("TELEGRAM_SESSION", None)
88
from_chats = list(set(int(x) for x in environ.get("FROM_CHATS").split()))
99
to_chats = list(set(int(x) for x in environ.get("TO_CHATS").split()))
10+
advance_config = environ.get("ADVANCE_CONFIG", None)
1011

1112
if tg_session:
1213
app = Client(tg_session, api_id, api_hash)
1314
else:
1415
app = Client(":memory:", api_id, api_hash, bot_token=bot_token)
1516

17+
if advance_config:
18+
print("Advance Configures detected...")
19+
from_chats = []
20+
chats_data = {}
21+
for chats in advance_config.split(","):
22+
chat = chats.strip().split()
23+
chats_data[int(chat[0])] = int(chat[1])
24+
if not int(chat[0]) in from_chats:
25+
from_chats.append(int(chat[0]))
26+
print(from_chats)
27+
print(chats_data)
28+
1629

1730
@app.on_message(filters.chat(from_chats) & filters.incoming)
1831
def work(client, message):
19-
try:
20-
for chat in to_chats:
21-
message.copy(chat)
22-
except Exception as e:
23-
print(e)
32+
if advance_config:
33+
try:
34+
message.copy(chats_data[int(message.chat.id)])
35+
except Exception as e:
36+
print(e)
37+
else:
38+
try:
39+
for chat in to_chats:
40+
message.copy(chat)
41+
except Exception as e:
42+
print(e)
2443

2544
app.run()

0 commit comments

Comments
 (0)