From 8d0eecf0fcb3d556a532c06d9cef77b78fc9a84c Mon Sep 17 00:00:00 2001 From: Pranaya Deomani Date: Mon, 18 Mar 2024 08:08:56 +0000 Subject: [PATCH 1/4] Revert "Introduce the Pyrogram dependency" This reverts commit a6fd7671ceb61c275a83ccbca990ef91be71c1f4. --- poetry.lock | 35 +++++------------------------------ pyproject.toml | 1 - 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/poetry.lock b/poetry.lock index f32d6a5..784f3b1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "aiohttp" @@ -877,13 +877,13 @@ files = [ [[package]] name = "g4f" -version = "0.2.5.4" +version = "0.2.5.3" description = "The official gpt4free repository | various collection of powerful language models" optional = false python-versions = "*" files = [ - {file = "g4f-0.2.5.4-py3-none-any.whl", hash = "sha256:4fcc6b7172573027de295c9476cb08426b8b170594f92261f8dfea209e8471bc"}, - {file = "g4f-0.2.5.4.tar.gz", hash = "sha256:bc1877fee48f4d516b2714eb948cad7e01380ecf9b89ce8ecf7916a877118611"}, + {file = "g4f-0.2.5.3-py3-none-any.whl", hash = "sha256:ee76ee7935b4eb2747b72191eaa2c5407772e90db6c6cb7b54d35962cf492287"}, + {file = "g4f-0.2.5.3.tar.gz", hash = "sha256:de16cd873d042858f073016ad2a8855e61b74051e9c51bdb7714f634e7ece2ec"}, ] [package.dependencies] @@ -1654,16 +1654,6 @@ files = [ mmh3 = "*" pycryptodome = "*" -[[package]] -name = "pyaes" -version = "1.6.1" -description = "Pure-Python Implementation of the AES block-cipher and common modes of operation" -optional = false -python-versions = "*" -files = [ - {file = "pyaes-1.6.1.tar.gz", hash = "sha256:02c1b1405c38d3c370b085fb952dd8bea3fadcee6411ad99f312cc129c536d8f"}, -] - [[package]] name = "pyasn1" version = "0.5.1" @@ -1938,21 +1928,6 @@ files = [ [package.extras] diagrams = ["jinja2", "railroad-diagrams"] -[[package]] -name = "pyrogram" -version = "2.0.106" -description = "Elegant, modern and asynchronous Telegram MTProto API framework in Python for users and bots" -optional = false -python-versions = "~=3.7" -files = [ - {file = "Pyrogram-2.0.106-py3-none-any.whl", hash = "sha256:32b62b3d93030b1080cbe45b88c0e8790cf4e2179cf3321ede810d48edf97bc7"}, - {file = "Pyrogram-2.0.106.tar.gz", hash = "sha256:30202995758fcb6e0f91224704ab7fedefea454297724bd70a6a71a23748c16f"}, -] - -[package.dependencies] -pyaes = "1.6.1" -pysocks = "1.7.1" - [[package]] name = "pysocks" version = "1.7.1" @@ -2571,4 +2546,4 @@ cffi = ["cffi (>=1.11)"] [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "b75c1473dc6c9b78303fb352ff6058da1ddfc6c939988a9d87d9c6a8b597a67c" +content-hash = "7a4d1acbfa1fb382e8e73415374e7684520c06d5cad85f787af71a947bab260e" diff --git a/pyproject.toml b/pyproject.toml index c27e9d9..235d51c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" g4f = {extras = ["all"], version = "^0.2.5.4"} -pyrogram = {extras = ["all"], version = "^2.0.106"} [tool.poetry.group.dev.dependencies] black = "^24.3.0" From 3f45625b2617745a192a1adb8bbbcb7549ac63e8 Mon Sep 17 00:00:00 2001 From: Pranaya Deomani Date: Mon, 18 Mar 2024 08:14:44 +0000 Subject: [PATCH 2/4] Regenerate poetry.lock Change-Id: I4a80879defa5595bf51d6f430cd024a8f20c32db --- poetry.lock | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index 784f3b1..50ba7b3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aiohttp" @@ -87,6 +87,7 @@ files = [ [package.dependencies] aiosignal = ">=1.1.2" +async-timeout = {version = ">=4.0,<5.0", markers = "python_version < \"3.11\""} attrs = ">=17.3.0" frozenlist = ">=1.1.1" multidict = ">=4.5,<7.0" @@ -147,8 +148,10 @@ files = [ ] [package.dependencies] +exceptiongroup = {version = ">=1.0.2", markers = "python_version < \"3.11\""} idna = ">=2.8" sniffio = ">=1.1" +typing-extensions = {version = ">=4.1", markers = "python_version < \"3.11\""} [package.extras] doc = ["Sphinx (>=7)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx-rtd-theme"] @@ -254,6 +257,8 @@ mypy-extensions = ">=0.4.3" packaging = ">=22.0" pathspec = ">=0.9.0" platformdirs = ">=2" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} [package.extras] colorama = ["colorama (>=0.4.3)"] @@ -748,6 +753,20 @@ lxml = ">=5.1.0" [package.extras] dev = ["mypy (>=1.8.0)", "pytest (>=8.0.1)", "ruff (>=0.3.0)"] +[[package]] +name = "exceptiongroup" +version = "1.2.0" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, + {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, +] + +[package.extras] +test = ["pytest (>=6)"] + [[package]] name = "fastapi" version = "0.110.0" @@ -877,13 +896,13 @@ files = [ [[package]] name = "g4f" -version = "0.2.5.3" +version = "0.2.5.4" description = "The official gpt4free repository | various collection of powerful language models" optional = false python-versions = "*" files = [ - {file = "g4f-0.2.5.3-py3-none-any.whl", hash = "sha256:ee76ee7935b4eb2747b72191eaa2c5407772e90db6c6cb7b54d35962cf492287"}, - {file = "g4f-0.2.5.3.tar.gz", hash = "sha256:de16cd873d042858f073016ad2a8855e61b74051e9c51bdb7714f634e7ece2ec"}, + {file = "g4f-0.2.5.4-py3-none-any.whl", hash = "sha256:4fcc6b7172573027de295c9476cb08426b8b170594f92261f8dfea209e8471bc"}, + {file = "g4f-0.2.5.4.tar.gz", hash = "sha256:bc1877fee48f4d516b2714eb948cad7e01380ecf9b89ce8ecf7916a877118611"}, ] [package.dependencies] @@ -1953,9 +1972,11 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} iniconfig = "*" packaging = "*" pluggy = ">=1.4,<2.0" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} [package.extras] testing = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] @@ -2144,6 +2165,17 @@ webencodings = ">=0.4" doc = ["sphinx", "sphinx_rtd_theme"] test = ["flake8", "isort", "pytest"] +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] + [[package]] name = "trio" version = "0.25.0" @@ -2158,6 +2190,7 @@ files = [ [package.dependencies] attrs = ">=23.2.0" cffi = {version = ">=1.14", markers = "os_name == \"nt\" and implementation_name != \"pypy\""} +exceptiongroup = {version = "*", markers = "python_version < \"3.11\""} idna = "*" outcome = "*" sniffio = ">=1.3.0" @@ -2175,6 +2208,7 @@ files = [ ] [package.dependencies] +exceptiongroup = {version = "*", markers = "python_version < \"3.11\""} trio = ">=0.11" wsproto = ">=0.14" @@ -2238,6 +2272,7 @@ files = [ [package.dependencies] click = ">=7.0" h11 = ">=0.8" +typing-extensions = {version = ">=4.0", markers = "python_version < \"3.11\""} [package.extras] standard = ["colorama (>=0.4)", "httptools (>=0.5.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.4)"] @@ -2545,5 +2580,5 @@ cffi = ["cffi (>=1.11)"] [metadata] lock-version = "2.0" -python-versions = "^3.12" -content-hash = "7a4d1acbfa1fb382e8e73415374e7684520c06d5cad85f787af71a947bab260e" +python-versions = "^3.10" +content-hash = "0bcc2f1554e313e16964129c7820e8971c13b4275e6066d3f922ae9d746411f5" From c2a8256c723d68b16da4f5b5948d945d33c20762 Mon Sep 17 00:00:00 2001 From: Pranaya Deomani Date: Mon, 18 Mar 2024 08:23:55 +0000 Subject: [PATCH 3/4] Add Telethon to dependencies Change-Id: I5fff5caed1d49ad04e58e072d2401a84fc117d98 --- poetry.lock | 43 ++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 50ba7b3..0edc6a9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1673,6 +1673,16 @@ files = [ mmh3 = "*" pycryptodome = "*" +[[package]] +name = "pyaes" +version = "1.6.1" +description = "Pure-Python Implementation of the AES block-cipher and common modes of operation" +optional = false +python-versions = "*" +files = [ + {file = "pyaes-1.6.1.tar.gz", hash = "sha256:02c1b1405c38d3c370b085fb952dd8bea3fadcee6411ad99f312cc129c536d8f"}, +] + [[package]] name = "pyasn1" version = "0.5.1" @@ -2022,6 +2032,20 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +[[package]] +name = "rsa" +version = "4.9" +description = "Pure-Python RSA implementation" +optional = false +python-versions = ">=3.6,<4" +files = [ + {file = "rsa-4.9-py3-none-any.whl", hash = "sha256:90260d9058e514786967344d0ef75fa8727eed8a7d2e43ce9f4bcf1b536174f7"}, + {file = "rsa-4.9.tar.gz", hash = "sha256:e38464a49c6c85d7f1351b0126661487a7e0a14a50f1675ec50eb34d4f20ef21"}, +] + +[package.dependencies] +pyasn1 = ">=0.1.3" + [[package]] name = "selenium" version = "4.18.1" @@ -2147,6 +2171,23 @@ anyio = ">=3.4.0,<5" [package.extras] full = ["httpx (>=0.22.0)", "itsdangerous", "jinja2", "python-multipart (>=0.0.7)", "pyyaml"] +[[package]] +name = "telethon" +version = "1.34.0" +description = "Full-featured Telegram client library for Python 3" +optional = false +python-versions = ">=3.5" +files = [ + {file = "Telethon-1.34.0.tar.gz", hash = "sha256:55290809a30081fa0bb5052abb7547cbb25d7fbca94f32f13c147504d521804f"}, +] + +[package.dependencies] +pyaes = "*" +rsa = "*" + +[package.extras] +cryptg = ["cryptg"] + [[package]] name = "tinycss2" version = "1.2.1" @@ -2581,4 +2622,4 @@ cffi = ["cffi (>=1.11)"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "0bcc2f1554e313e16964129c7820e8971c13b4275e6066d3f922ae9d746411f5" +content-hash = "bace2289d58eb80a8509559b88a930e7b7a675eb307cfde6f008da9722bbac18" diff --git a/pyproject.toml b/pyproject.toml index 235d51c..ea3e26f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" g4f = {extras = ["all"], version = "^0.2.5.4"} +telethon = "^1.34.0" [tool.poetry.group.dev.dependencies] black = "^24.3.0" From 07200d8ee4d260e0037c9a553cd213c0a4e6dab4 Mon Sep 17 00:00:00 2001 From: Pranaya Deomani Date: Mon, 18 Mar 2024 09:03:59 +0000 Subject: [PATCH 4/4] Implement a basic bot template Add the gitignore entries for session files as well as create an example env file for reference. --- .env.example | 3 +++ .gitignore | 4 ++++ src/Bot.py | 18 ++++++++++++++++++ src/__main__.py | 4 ++++ 4 files changed, 29 insertions(+) create mode 100644 .env.example create mode 100644 src/Bot.py diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..553ab97 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +API_ID=12345 +API_HASH=0123456789abcdef0123456789abcdef +BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 diff --git a/.gitignore b/.gitignore index fb6655f..5700012 100644 --- a/.gitignore +++ b/.gitignore @@ -316,3 +316,7 @@ pyrightconfig.json # Ignore all local history of files .history .ionide + +### Telethon ### +*.session +*.session-journal diff --git a/src/Bot.py b/src/Bot.py new file mode 100644 index 0000000..87fcdb9 --- /dev/null +++ b/src/Bot.py @@ -0,0 +1,18 @@ +from dotenv import load_dotenv +from telethon import TelegramClient, events +from os import getenv + +def main() -> None: + load_dotenv() + + api_id = getenv("API_ID") + api_hash = getenv("API_HASH") + bot_token = getenv("BOT_TOKEN") + + app = TelegramClient('app', api_id, api_hash).start(bot_token=bot_token) + + @app.on(events.NewMessage(incoming=True, pattern='/start')) + async def start(event): + await event.reply("Hello!") + + app.run_until_disconnected() diff --git a/src/__main__.py b/src/__main__.py index e69de29..59b177a 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -0,0 +1,4 @@ +from Bot import main + +if __name__ == "__main__": + main()