Skip to content

Commit ad4458b

Browse files
committed
remove unnecessary stuff
1 parent 6d4cab2 commit ad4458b

File tree

5 files changed

+19
-93
lines changed

5 files changed

+19
-93
lines changed

README.md

+8-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A simple script to forward all the messages of one chat (indivisual/group/channe
88

99
## Signing in
1010

11-
First of all you need to have your Telegram account's `api_id` and `api_hash`.
11+
First of all you need to have your Telegram account's `api_id` and `api_hash`.
1212
Learn [how to get](https://docs.telethon.dev/en/latest/basic/signing-in.html) them.
1313

1414
## Installation
@@ -44,23 +44,22 @@ After this you need to create and fill up the `config.ini` file with your forwar
4444

4545
## Configuration
4646

47-
- The `from` and `to` in the `config.ini` has to be a username/phone/link/chat_id of the chat.
48-
- **To confirm that you are using the correct `from` and `to` run the `get_chat_info.py` script.**
49-
47+
- The `from` and `to` in the `config.ini` has to be a **username/phone/link/chat_id** of the chat.
48+
- The chat id is the best way for configurations. It will always be accurate. To get the chat id of a chat, forward any message of the chat to [@userinfobot](https://telegram.me/userinfobot)
5049
- You may have as many as forwarding pairs as you wish. Make sure to give a unique header to each pair. Follow the syntax shown below.
5150

5251
```ini
5352
[name of forward1]
5453
; in the above line give any name as you wish
5554
; the square brackets around the name should remain
56-
from = whatAz
57-
to = testWha
55+
from = https://t.me/someone
56+
to = -1001235055711
5857
offset = 0
5958
; the offset will auto-update, keep it zero initially
6059
[another name]
6160
; the name of section must be unique
62-
from = someone
63-
to = another
61+
from = @username
62+
to = @anothername
6463
offset = 0
6564
```
6665

@@ -83,15 +82,7 @@ python3 forwarder.py
8382

8483
You have to login for the first time using your phone number (inter-national format) and login code.
8584

86-
A session file called `forwarder.session` will be generated. Please don't delete this and make sure to keep this file secret.
85+
A session file called `forwarder.session` will be generated. **Please don't delete this and make sure to keep this file secret.**
8786

8887
Feel free to ask your questions in the [Discussion section](https://github.com/aahnik/telegram-chat-forward/discussions). For bugs and feature requests use the [issues](https://github.com/aahnik/telegram-chat-forward/issues/new) section of this repo.
8988

90-
## Extra
91-
92-
To get all information about any particular chat:
93-
94-
- Run the script `run_chat_info.py`.
95-
- Open Telegram and send `.id` to any chat to get the chat id.
96-
- Send `.info` to any chat to get details of the chat.
97-
- When you are done, come back to your terminal and press <kbd>CTRL</kbd> + <kbd>C</kbd> to stop.

forwarder.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from telethon.tl.patched import MessageService
77
from telethon.errors.rpcerrorlist import FloodWaitError
88
from telethon import TelegramClient
9-
from settings import API_ID, API_HASH, forwards, get_forward, update_offset
9+
from telethon.sessions import StringSession
10+
from settings import API_ID, API_HASH, forwards, get_forward, update_offset, STRING_SESSION
1011

1112

1213
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
@@ -15,7 +16,7 @@
1516
SENT_VIA = f'\n__Sent via__ `{str(__file__)}`'
1617

1718

18-
def _(string):
19+
def intify(string):
1920
try:
2021
return int(string)
2122
except:
@@ -24,8 +25,12 @@ def _(string):
2425

2526
async def forward_job():
2627
''' the function that does the job 😂 '''
28+
if STRING_SESSION:
29+
session = StringSession(STRING_SESSION)
30+
else:
31+
session = 'forwarder'
2732

28-
async with TelegramClient('forwarder', API_ID, API_HASH) as client:
33+
async with TelegramClient(session, API_ID, API_HASH) as client:
2934

3035
confirm = ''' IMPORTANT 🛑
3136
Are you sure that your `config.ini` is correct ?
@@ -46,11 +51,11 @@ async def forward_job():
4651

4752
last_id = 0
4853

49-
async for message in client.iter_messages(_(from_chat), reverse=True, offset_id=offset):
54+
async for message in client.iter_messages(intify(from_chat), reverse=True, offset_id=offset):
5055
if isinstance(message, MessageService):
5156
continue
5257
try:
53-
await client.send_message(_(to_chat), message)
58+
await client.send_message(intify(to_chat), message)
5459
last_id = str(message.id)
5560
logging.info('forwarding message with id = %s', last_id)
5661
update_offset(forward, last_id)

get_chat_info.py

-27
This file was deleted.

run_chat_info.py

-42
This file was deleted.

settings.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
API_ID = os.getenv('api_id')
99
API_HASH = os.getenv('api_hash')
10+
STRING_SESSION = os.getenv('STRING_SESSION')
1011

1112
assert API_ID and API_HASH
1213

@@ -16,8 +17,6 @@
1617
forwards = configur.sections()
1718

1819

19-
20-
2120
def get_forward(forward: str) -> tuple:
2221
try:
2322
from_chat = configur.get(forward, 'from')

0 commit comments

Comments
 (0)