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/poetry.lock b/poetry.lock index f32d6a5..0edc6a9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -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" @@ -1938,21 +1957,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" @@ -1978,9 +1982,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"] @@ -2026,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" @@ -2151,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" @@ -2169,6 +2206,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" @@ -2183,6 +2231,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" @@ -2200,6 +2249,7 @@ files = [ ] [package.dependencies] +exceptiongroup = {version = "*", markers = "python_version < \"3.11\""} trio = ">=0.11" wsproto = ">=0.14" @@ -2263,6 +2313,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)"] @@ -2570,5 +2621,5 @@ cffi = ["cffi (>=1.11)"] [metadata] lock-version = "2.0" -python-versions = "^3.12" -content-hash = "b75c1473dc6c9b78303fb352ff6058da1ddfc6c939988a9d87d9c6a8b597a67c" +python-versions = "^3.10" +content-hash = "bace2289d58eb80a8509559b88a930e7b7a675eb307cfde6f008da9722bbac18" diff --git a/pyproject.toml b/pyproject.toml index c27e9d9..ea3e26f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" g4f = {extras = ["all"], version = "^0.2.5.4"} -pyrogram = {extras = ["all"], version = "^2.0.106"} +telethon = "^1.34.0" [tool.poetry.group.dev.dependencies] black = "^24.3.0" 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()