From 4073f2723deecce179d806ff4c9d8107c6f77888 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sat, 22 Jun 2024 18:22:19 +0700 Subject: [PATCH] [Add] init --- .env.example | 5 +++++ .gitignore | 8 +++++--- config.py | 11 +++++++++++ main.py | 25 +++++++++++++++++++++++++ requirements.txt | Bin 0 -> 160 bytes 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 .env.example create mode 100644 config.py create mode 100644 main.py create mode 100644 requirements.txt 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 0000000000000000000000000000000000000000..0ede79fdcefab0e216be984022447e378cc70d70 GIT binary patch literal 160 zcmezWuYjSFA(0`Kp_suI2n`wZ7|ej!kb#$hivc26%#a7^Eirse#x509)=C%m4rY literal 0 HcmV?d00001