Skip to content

Commit

Permalink
remove unnecessary stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
aahnik committed Jan 8, 2021
1 parent 6d4cab2 commit ad4458b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 93 deletions.
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A simple script to forward all the messages of one chat (indivisual/group/channe

## Signing in

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

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

## Configuration

- The `from` and `to` in the `config.ini` has to be a username/phone/link/chat_id of the chat.
- **To confirm that you are using the correct `from` and `to` run the `get_chat_info.py` script.**

- The `from` and `to` in the `config.ini` has to be a **username/phone/link/chat_id** of the chat.
- 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)
- 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.

```ini
[name of forward1]
; in the above line give any name as you wish
; the square brackets around the name should remain
from = whatAz
to = testWha
from = https://t.me/someone
to = -1001235055711
offset = 0
; the offset will auto-update, keep it zero initially
[another name]
; the name of section must be unique
from = someone
to = another
from = @username
to = @anothername
offset = 0
```

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

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

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

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.

## Extra

To get all information about any particular chat:

- Run the script `run_chat_info.py`.
- Open Telegram and send `.id` to any chat to get the chat id.
- Send `.info` to any chat to get details of the chat.
- When you are done, come back to your terminal and press <kbd>CTRL</kbd> + <kbd>C</kbd> to stop.
15 changes: 10 additions & 5 deletions forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from telethon.tl.patched import MessageService
from telethon.errors.rpcerrorlist import FloodWaitError
from telethon import TelegramClient
from settings import API_ID, API_HASH, forwards, get_forward, update_offset
from telethon.sessions import StringSession
from settings import API_ID, API_HASH, forwards, get_forward, update_offset, STRING_SESSION


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


def _(string):
def intify(string):
try:
return int(string)
except:
Expand All @@ -24,8 +25,12 @@ def _(string):

async def forward_job():
''' the function that does the job 😂 '''
if STRING_SESSION:
session = StringSession(STRING_SESSION)
else:
session = 'forwarder'

async with TelegramClient('forwarder', API_ID, API_HASH) as client:
async with TelegramClient(session, API_ID, API_HASH) as client:

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

last_id = 0

async for message in client.iter_messages(_(from_chat), reverse=True, offset_id=offset):
async for message in client.iter_messages(intify(from_chat), reverse=True, offset_id=offset):
if isinstance(message, MessageService):
continue
try:
await client.send_message(_(to_chat), message)
await client.send_message(intify(to_chat), message)
last_id = str(message.id)
logging.info('forwarding message with id = %s', last_id)
update_offset(forward, last_id)
Expand Down
27 changes: 0 additions & 27 deletions get_chat_info.py

This file was deleted.

42 changes: 0 additions & 42 deletions run_chat_info.py

This file was deleted.

3 changes: 1 addition & 2 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

API_ID = os.getenv('api_id')
API_HASH = os.getenv('api_hash')
STRING_SESSION = os.getenv('STRING_SESSION')

assert API_ID and API_HASH

Expand All @@ -16,8 +17,6 @@
forwards = configur.sections()




def get_forward(forward: str) -> tuple:
try:
from_chat = configur.get(forward, 'from')
Expand Down

0 comments on commit ad4458b

Please sign in to comment.