diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..aadd830 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +PHONE=+1234567890 +API_ID=123456789 +API_HASH=0123456789abcdef0123456789abcdef +SOURCE_GROUP_ID=-123456789 +DESTINATION_GROUP_ID=-123456789 diff --git a/.gitignore b/.gitignore index 82f9275..67aee0b 100644 --- a/.gitignore +++ b/.gitignore @@ -106,10 +106,8 @@ ipython_config.py #pdm.lock # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it # in version control. -# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +# https://pdm.fming.dev/#use-with-ide .pdm.toml -.pdm-python -.pdm-build/ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ @@ -160,3 +158,7 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +.idea/ +*.session +*.csv diff --git a/config.py b/config.py new file mode 100644 index 0000000..a26e406 --- /dev/null +++ b/config.py @@ -0,0 +1,11 @@ +import os + +from dotenv import load_dotenv + +load_dotenv() + +phone = os.getenv('PHONE') +api_id = os.getenv('API_ID') +api_hash = os.getenv('API_HASH') +source_group_id = os.getenv('SOURCE_GROUP_ID') +destination_group_id = os.getenv('DESTINATION_GROUP_ID') diff --git a/main.py b/main.py new file mode 100644 index 0000000..e9d2a9f --- /dev/null +++ b/main.py @@ -0,0 +1,25 @@ +import getpass + +from telethon.errors import SessionPasswordNeededError +from telethon.sync import TelegramClient + +from config import * + +# client = TelegramClient(phone, api_id, api_hash) + +# client.connect() +# if not client.is_user_authorized(): +# client.send_code_request(phone) +# try: +# client.sign_in(code=input('Enter code: ')) +# except SessionPasswordNeededError: +# client.sign_in(password=getpass.getpass()) + +# client.start(phone) + +with TelegramClient('session_name', api_id, api_hash) as client: + @client.on(events.NewMessage(chats=source_group_id)) + async def handler(event): + await client.forward_messages(destination_group_id, event.message) + + client.run_until_disconnected() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0ede79f Binary files /dev/null and b/requirements.txt differ