herokutl 2.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. herokutl-2.0.5/.gitignore +23 -0
  2. herokutl-2.0.5/LICENSE.md +19 -0
  3. herokutl-2.0.5/PKG-INFO +81 -0
  4. herokutl-2.0.5/README.rst +52 -0
  5. herokutl-2.0.5/hatch_build.py +133 -0
  6. herokutl-2.0.5/herokutl/__init__.py +13 -0
  7. herokutl-2.0.5/herokutl/_updates/__init__.py +3 -0
  8. herokutl-2.0.5/herokutl/_updates/entitycache.py +59 -0
  9. herokutl-2.0.5/herokutl/_updates/messagebox.py +825 -0
  10. herokutl-2.0.5/herokutl/_updates/session.py +195 -0
  11. herokutl-2.0.5/herokutl/client/__init__.py +26 -0
  12. herokutl-2.0.5/herokutl/client/account.py +243 -0
  13. herokutl-2.0.5/herokutl/client/auth.py +677 -0
  14. herokutl-2.0.5/herokutl/client/bots.py +72 -0
  15. herokutl-2.0.5/herokutl/client/buttons.py +101 -0
  16. herokutl-2.0.5/herokutl/client/chats.py +1336 -0
  17. herokutl-2.0.5/herokutl/client/dialogs.py +610 -0
  18. herokutl-2.0.5/herokutl/client/downloads.py +1089 -0
  19. herokutl-2.0.5/herokutl/client/messageparse.py +233 -0
  20. herokutl-2.0.5/herokutl/client/messages.py +1642 -0
  21. herokutl-2.0.5/herokutl/client/payments.py +133 -0
  22. herokutl-2.0.5/herokutl/client/telegrambaseclient.py +968 -0
  23. herokutl-2.0.5/herokutl/client/telegramclient.py +13 -0
  24. herokutl-2.0.5/herokutl/client/updates.py +731 -0
  25. herokutl-2.0.5/herokutl/client/uploads.py +919 -0
  26. herokutl-2.0.5/herokutl/client/users.py +631 -0
  27. herokutl-2.0.5/herokutl/crypto/__init__.py +10 -0
  28. herokutl-2.0.5/herokutl/crypto/aes.py +111 -0
  29. herokutl-2.0.5/herokutl/crypto/aesctr.py +42 -0
  30. herokutl-2.0.5/herokutl/crypto/authkey.py +63 -0
  31. herokutl-2.0.5/herokutl/crypto/cdndecrypter.py +105 -0
  32. herokutl-2.0.5/herokutl/crypto/factorization.py +67 -0
  33. herokutl-2.0.5/herokutl/crypto/libssl.py +140 -0
  34. herokutl-2.0.5/herokutl/crypto/rsa.py +165 -0
  35. herokutl-2.0.5/herokutl/custom.py +1 -0
  36. herokutl-2.0.5/herokutl/errors/__init__.py +46 -0
  37. herokutl-2.0.5/herokutl/errors/common.py +188 -0
  38. herokutl-2.0.5/herokutl/errors/rpcbaseerrors.py +131 -0
  39. herokutl-2.0.5/herokutl/events/__init__.py +140 -0
  40. herokutl-2.0.5/herokutl/events/album.py +343 -0
  41. herokutl-2.0.5/herokutl/events/callbackquery.py +346 -0
  42. herokutl-2.0.5/herokutl/events/chataction.py +458 -0
  43. herokutl-2.0.5/herokutl/events/common.py +186 -0
  44. herokutl-2.0.5/herokutl/events/inlinequery.py +247 -0
  45. herokutl-2.0.5/herokutl/events/messagedeleted.py +57 -0
  46. herokutl-2.0.5/herokutl/events/messageedited.py +52 -0
  47. herokutl-2.0.5/herokutl/events/messageread.py +143 -0
  48. herokutl-2.0.5/herokutl/events/newmessage.py +223 -0
  49. herokutl-2.0.5/herokutl/events/raw.py +53 -0
  50. herokutl-2.0.5/herokutl/events/userupdate.py +310 -0
  51. herokutl-2.0.5/herokutl/extensions/__init__.py +6 -0
  52. herokutl-2.0.5/herokutl/extensions/binaryreader.py +201 -0
  53. herokutl-2.0.5/herokutl/extensions/html.py +423 -0
  54. herokutl-2.0.5/herokutl/extensions/markdown.py +197 -0
  55. herokutl-2.0.5/herokutl/extensions/messagepacker.py +111 -0
  56. herokutl-2.0.5/herokutl/functions.py +1 -0
  57. herokutl-2.0.5/herokutl/helpers.py +436 -0
  58. herokutl-2.0.5/herokutl/hints.py +72 -0
  59. herokutl-2.0.5/herokutl/network/__init__.py +14 -0
  60. herokutl-2.0.5/herokutl/network/authenticator.py +212 -0
  61. herokutl-2.0.5/herokutl/network/connection/__init__.py +12 -0
  62. herokutl-2.0.5/herokutl/network/connection/connection.py +440 -0
  63. herokutl-2.0.5/herokutl/network/connection/http.py +39 -0
  64. herokutl-2.0.5/herokutl/network/connection/tcpabridged.py +33 -0
  65. herokutl-2.0.5/herokutl/network/connection/tcpfull.py +62 -0
  66. herokutl-2.0.5/herokutl/network/connection/tcpintermediate.py +46 -0
  67. herokutl-2.0.5/herokutl/network/connection/tcpmtproxy.py +468 -0
  68. herokutl-2.0.5/herokutl/network/connection/tcpobfuscated.py +62 -0
  69. herokutl-2.0.5/herokutl/network/mtprotoplainsender.py +56 -0
  70. herokutl-2.0.5/herokutl/network/mtprotosender.py +924 -0
  71. herokutl-2.0.5/herokutl/network/mtprotostate.py +285 -0
  72. herokutl-2.0.5/herokutl/network/requeststate.py +19 -0
  73. herokutl-2.0.5/herokutl/password.py +194 -0
  74. herokutl-2.0.5/herokutl/requestiter.py +134 -0
  75. herokutl-2.0.5/herokutl/sessions/__init__.py +4 -0
  76. herokutl-2.0.5/herokutl/sessions/abstract.py +172 -0
  77. herokutl-2.0.5/herokutl/sessions/memory.py +260 -0
  78. herokutl-2.0.5/herokutl/sessions/sqlite.py +385 -0
  79. herokutl-2.0.5/herokutl/sessions/string.py +63 -0
  80. herokutl-2.0.5/herokutl/sync.py +74 -0
  81. herokutl-2.0.5/herokutl/tl/__init__.py +1 -0
  82. herokutl-2.0.5/herokutl/tl/core/__init__.py +26 -0
  83. herokutl-2.0.5/herokutl/tl/core/gzippacked.py +48 -0
  84. herokutl-2.0.5/herokutl/tl/core/messagecontainer.py +47 -0
  85. herokutl-2.0.5/herokutl/tl/core/rpcresult.py +35 -0
  86. herokutl-2.0.5/herokutl/tl/core/tlmessage.py +34 -0
  87. herokutl-2.0.5/herokutl/tl/custom/__init__.py +15 -0
  88. herokutl-2.0.5/herokutl/tl/custom/adminlogevent.py +475 -0
  89. herokutl-2.0.5/herokutl/tl/custom/button.py +354 -0
  90. herokutl-2.0.5/herokutl/tl/custom/chatgetter.py +150 -0
  91. herokutl-2.0.5/herokutl/tl/custom/conversation.py +529 -0
  92. herokutl-2.0.5/herokutl/tl/custom/dialog.py +171 -0
  93. herokutl-2.0.5/herokutl/tl/custom/draft.py +191 -0
  94. herokutl-2.0.5/herokutl/tl/custom/file.py +146 -0
  95. herokutl-2.0.5/herokutl/tl/custom/forward.py +51 -0
  96. herokutl-2.0.5/herokutl/tl/custom/inlinebuilder.py +450 -0
  97. herokutl-2.0.5/herokutl/tl/custom/inlineresult.py +176 -0
  98. herokutl-2.0.5/herokutl/tl/custom/inlineresults.py +83 -0
  99. herokutl-2.0.5/herokutl/tl/custom/inputsizedfile.py +9 -0
  100. herokutl-2.0.5/herokutl/tl/custom/message.py +1318 -0
  101. herokutl-2.0.5/herokutl/tl/custom/messagebutton.py +154 -0
  102. herokutl-2.0.5/herokutl/tl/custom/participantpermissions.py +138 -0
  103. herokutl-2.0.5/herokutl/tl/custom/qrlogin.py +119 -0
  104. herokutl-2.0.5/herokutl/tl/custom/sendergetter.py +102 -0
  105. herokutl-2.0.5/herokutl/tl/custom/stargift.py +473 -0
  106. herokutl-2.0.5/herokutl/tl/patched/__init__.py +20 -0
  107. herokutl-2.0.5/herokutl/tl/tlobject.py +357 -0
  108. herokutl-2.0.5/herokutl/types.py +1 -0
  109. herokutl-2.0.5/herokutl/utils.py +1629 -0
  110. herokutl-2.0.5/herokutl/version.py +3 -0
  111. herokutl-2.0.5/pyproject.toml +62 -0
  112. herokutl-2.0.5/telethon_generator/__init__.py +1 -0
  113. herokutl-2.0.5/telethon_generator/data/api.tl +2979 -0
  114. herokutl-2.0.5/telethon_generator/data/errors.csv +535 -0
  115. herokutl-2.0.5/telethon_generator/data/friendly.csv +26 -0
  116. herokutl-2.0.5/telethon_generator/data/html/404.html +44 -0
  117. herokutl-2.0.5/telethon_generator/data/html/core.html +179 -0
  118. herokutl-2.0.5/telethon_generator/data/html/css/docs.dark.css +185 -0
  119. herokutl-2.0.5/telethon_generator/data/html/css/docs.h4x0r.css +229 -0
  120. herokutl-2.0.5/telethon_generator/data/html/css/docs.light.css +182 -0
  121. herokutl-2.0.5/telethon_generator/data/html/img/arrow.svg +35 -0
  122. herokutl-2.0.5/telethon_generator/data/html/js/search.js +244 -0
  123. herokutl-2.0.5/telethon_generator/data/methods.csv +365 -0
  124. herokutl-2.0.5/telethon_generator/data/mtproto.tl +116 -0
  125. herokutl-2.0.5/telethon_generator/docswriter.py +295 -0
  126. herokutl-2.0.5/telethon_generator/generators/__init__.py +3 -0
  127. herokutl-2.0.5/telethon_generator/generators/docs.py +649 -0
  128. herokutl-2.0.5/telethon_generator/generators/errors.py +60 -0
  129. herokutl-2.0.5/telethon_generator/generators/tlobject.py +723 -0
  130. herokutl-2.0.5/telethon_generator/parsers/__init__.py +3 -0
  131. herokutl-2.0.5/telethon_generator/parsers/errors.py +85 -0
  132. herokutl-2.0.5/telethon_generator/parsers/methods.py +67 -0
  133. herokutl-2.0.5/telethon_generator/parsers/tlobject/__init__.py +3 -0
  134. herokutl-2.0.5/telethon_generator/parsers/tlobject/parser.py +148 -0
  135. herokutl-2.0.5/telethon_generator/parsers/tlobject/tlarg.py +256 -0
  136. herokutl-2.0.5/telethon_generator/parsers/tlobject/tlobject.py +155 -0
  137. herokutl-2.0.5/telethon_generator/sourcebuilder.py +65 -0
  138. herokutl-2.0.5/telethon_generator/syncerrors.py +55 -0
  139. herokutl-2.0.5/telethon_generator/utils.py +8 -0
@@ -0,0 +1,23 @@
1
+ # Generated code
2
+ /telethon/tl/functions/
3
+ /telethon/tl/types/
4
+ /telethon/tl/alltlobjects.py
5
+ /telethon/errors/rpcerrorlist.py
6
+
7
+ # User session
8
+ *.session
9
+ /usermedia/
10
+
11
+ # Builds and testing
12
+ __pycache__/
13
+ /dist/
14
+ /build/
15
+ /*.egg-info/
16
+ /readthedocs/_build/
17
+ /.tox/
18
+
19
+ # API reference docs
20
+ /docs/
21
+
22
+ # File used to manually test new changes, contains sensitive data
23
+ /example.py
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2026 - 2030 Codrago
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,81 @@
1
+ Metadata-Version: 2.4
2
+ Name: herokutl
3
+ Version: 2.0.5
4
+ Summary: This library is built for the Heroku userbot and is based on Telethon.
5
+ Project-URL: Homepage, https://github.com/coddrago/heroku-tl
6
+ Project-URL: Source, https://github.com/coddrago/heroku-tl
7
+ Project-URL: Download, https://pypi.org/project/herokutl/
8
+ Project-URL: Documentation, https://docs.telethon.dev
9
+ Project-URL: Reference, https://tl.telethon.dev
10
+ Author-email: Codrago <codrago@xyecoc.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE.md
13
+ Keywords: api,chat,client,library,messaging,mtproto,telegram
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.5
18
+ Classifier: Programming Language :: Python :: 3.6
19
+ Classifier: Programming Language :: Python :: 3.7
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Topic :: Communications :: Chat
22
+ Requires-Python: >=3.5
23
+ Requires-Dist: bs4==0.0.2
24
+ Requires-Dist: pyaes
25
+ Requires-Dist: rsa
26
+ Provides-Extra: cryptg
27
+ Requires-Dist: cryptg; extra == 'cryptg'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # Herokutl
31
+
32
+ > ⭐️ Thanks **everyone** who has starred the project, it means a lot!
33
+
34
+ ![logo](logo.svg) **Telethon** is an [asyncio](https://docs.python.org/3/library/asyncio.html) **Python 3** [MTProto](https://core.telegram.org/mtproto) library to interact with [Telegram](https://telegram.org)'s API as a user or through a bot account (bot API alternative).
35
+
36
+ > **Important**: If you have code using Telethon before its 1.0 version, you must read [Compatibility and Convenience](https://docs.telethon.dev/en/stable/misc/compatibility-and-convenience.html) to learn how to migrate. As with any third-party library for Telegram, be careful not to break [Telegram's ToS](https://core.telegram.org/api/terms) or [Telegram can ban the account](https://docs.telethon.dev/en/stable/quick-references/faq.html#my-account-was-deleted-limited-when-using-the-library).
37
+
38
+ ## What is this?
39
+
40
+ Telegram is a popular messaging application. This library is meant to make it easy for you to write Python programs that can interact with Telegram. Think of it as a wrapper that has already done the heavy job for you, so you can focus on developing an application.
41
+
42
+ ## Installing
43
+
44
+ ```sh
45
+ pip3 install herokutl
46
+ ```
47
+
48
+ ## Creating a client
49
+
50
+ ```python
51
+ from herokutl import TelegramClient, events, sync
52
+
53
+ # These example values won't work. You must get your own api_id and
54
+ # api_hash from https://my.telegram.org, under API Development.
55
+ api_id = 12345
56
+ api_hash = '0123456789abcdef0123456789abcdef'
57
+
58
+ client = TelegramClient('session_name', api_id, api_hash)
59
+ client.start()
60
+ ```
61
+
62
+ ## Doing stuff
63
+
64
+ ```python
65
+ print(client.get_me().stringify())
66
+
67
+ client.send_message('username', 'Hello! Talking to you from Telethon')
68
+ client.send_file('username', '/home/myself/Pictures/holidays.jpg')
69
+
70
+ client.download_profile_photo('me')
71
+ messages = client.get_messages('username')
72
+ messages[0].download_media()
73
+
74
+ @client.on(events.NewMessage(pattern='(?i)hi|hello'))
75
+ async def handler(event):
76
+ await event.respond('Hey!')
77
+ ```
78
+
79
+ ## Next steps
80
+
81
+ Do you like how Telethon looks? Check out [Read The Docs](https://docs.telethon.dev) for a more in-depth explanation, with examples, troubleshooting issues, and more useful information.
@@ -0,0 +1,52 @@
1
+ # Herokutl
2
+
3
+ > ⭐️ Thanks **everyone** who has starred the project, it means a lot!
4
+
5
+ ![logo](logo.svg) **Telethon** is an [asyncio](https://docs.python.org/3/library/asyncio.html) **Python 3** [MTProto](https://core.telegram.org/mtproto) library to interact with [Telegram](https://telegram.org)'s API as a user or through a bot account (bot API alternative).
6
+
7
+ > **Important**: If you have code using Telethon before its 1.0 version, you must read [Compatibility and Convenience](https://docs.telethon.dev/en/stable/misc/compatibility-and-convenience.html) to learn how to migrate. As with any third-party library for Telegram, be careful not to break [Telegram's ToS](https://core.telegram.org/api/terms) or [Telegram can ban the account](https://docs.telethon.dev/en/stable/quick-references/faq.html#my-account-was-deleted-limited-when-using-the-library).
8
+
9
+ ## What is this?
10
+
11
+ Telegram is a popular messaging application. This library is meant to make it easy for you to write Python programs that can interact with Telegram. Think of it as a wrapper that has already done the heavy job for you, so you can focus on developing an application.
12
+
13
+ ## Installing
14
+
15
+ ```sh
16
+ pip3 install herokutl
17
+ ```
18
+
19
+ ## Creating a client
20
+
21
+ ```python
22
+ from herokutl import TelegramClient, events, sync
23
+
24
+ # These example values won't work. You must get your own api_id and
25
+ # api_hash from https://my.telegram.org, under API Development.
26
+ api_id = 12345
27
+ api_hash = '0123456789abcdef0123456789abcdef'
28
+
29
+ client = TelegramClient('session_name', api_id, api_hash)
30
+ client.start()
31
+ ```
32
+
33
+ ## Doing stuff
34
+
35
+ ```python
36
+ print(client.get_me().stringify())
37
+
38
+ client.send_message('username', 'Hello! Talking to you from Telethon')
39
+ client.send_file('username', '/home/myself/Pictures/holidays.jpg')
40
+
41
+ client.download_profile_photo('me')
42
+ messages = client.get_messages('username')
43
+ messages[0].download_media()
44
+
45
+ @client.on(events.NewMessage(pattern='(?i)hi|hello'))
46
+ async def handler(event):
47
+ await event.respond('Hey!')
48
+ ```
49
+
50
+ ## Next steps
51
+
52
+ Do you like how Telethon looks? Check out [Read The Docs](https://docs.telethon.dev) for a more in-depth explanation, with examples, troubleshooting issues, and more useful information.
@@ -0,0 +1,133 @@
1
+ """Custom Hatch build hook to generate Python from .tl definitions."""
2
+
3
+ import itertools
4
+ import shutil
5
+ import sys
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ _BuildHookInterface: Any
10
+ try:
11
+ from hatchling.builders.hooks.plugin.interface import (
12
+ BuildHookInterface as _BuildHookInterface,
13
+ )
14
+ except ImportError:
15
+
16
+ class _FallbackBuildHookInterface:
17
+ pass
18
+
19
+ _BuildHookInterface = _FallbackBuildHookInterface
20
+
21
+
22
+ BuildHookInterface: Any = _BuildHookInterface
23
+
24
+
25
+ # Needed since we're importing local files
26
+ GENERATOR_DIR = Path("telethon_generator")
27
+ LIBRARY_DIR = Path("herokutl")
28
+
29
+ ERRORS_IN = GENERATOR_DIR / "data/errors.csv"
30
+ ERRORS_OUT = LIBRARY_DIR / "errors/rpcerrorlist.py"
31
+
32
+ METHODS_IN = GENERATOR_DIR / "data/methods.csv"
33
+
34
+ # Which raw API methods are covered by *friendly* methods in the client?
35
+ FRIENDLY_IN = GENERATOR_DIR / "data/friendly.csv"
36
+
37
+ TLOBJECT_IN_TLS = [Path(x) for x in GENERATOR_DIR.glob("data/*.tl")]
38
+ TLOBJECT_OUT = LIBRARY_DIR / "tl"
39
+ IMPORT_DEPTH = 2
40
+
41
+
42
+ class CustomBuildHook(BuildHookInterface):
43
+ def _root(self) -> Path:
44
+ return Path(self.root)
45
+
46
+ def _build_dir(self) -> Path:
47
+ return Path(self.directory)
48
+
49
+ def _clean_generated_artifacts(self) -> None:
50
+ build_dir = self._build_dir().resolve()
51
+ root = self._root().resolve()
52
+ generated_package = build_dir / LIBRARY_DIR
53
+
54
+ if build_dir == root:
55
+ clean_tl_dir = root / TLOBJECT_OUT
56
+ clean_errors_file = root / ERRORS_OUT
57
+ else:
58
+ clean_tl_dir = generated_package / "tl"
59
+ clean_errors_file = generated_package / "errors/rpcerrorlist.py"
60
+
61
+ from telethon_generator.generators import clean_tlobjects
62
+
63
+ clean_tlobjects(clean_tl_dir)
64
+ if clean_errors_file.is_file():
65
+ clean_errors_file.unlink()
66
+
67
+ if build_dir != root and generated_package.is_dir():
68
+ shutil.rmtree(generated_package)
69
+
70
+ def clean(self, versions: list[str]) -> None:
71
+ if self.root not in sys.path:
72
+ sys.path.insert(0, self.root)
73
+
74
+ self._clean_generated_artifacts()
75
+
76
+ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
77
+ if self.root not in sys.path:
78
+ sys.path.insert(0, self.root)
79
+
80
+ self.clean([])
81
+ if self.target_name == "sdist":
82
+ return
83
+
84
+ from telethon_generator.parsers import (
85
+ parse_errors,
86
+ parse_methods,
87
+ parse_tl,
88
+ find_layer,
89
+ )
90
+
91
+ from telethon_generator.generators import generate_errors, generate_tlobjects
92
+
93
+ root = self._root()
94
+ build_dir = self._build_dir()
95
+ generated_tl_dir = build_dir / TLOBJECT_OUT
96
+ generated_errors = build_dir / ERRORS_OUT
97
+
98
+ layer = next(filter(None, map(lambda p: find_layer(root / p), TLOBJECT_IN_TLS)))
99
+ errors = list(parse_errors(root / ERRORS_IN))
100
+ methods = list(
101
+ parse_methods(
102
+ root / METHODS_IN,
103
+ root / FRIENDLY_IN,
104
+ {e.str_code: e for e in errors},
105
+ )
106
+ )
107
+
108
+ tlobjects = list(
109
+ itertools.chain(
110
+ *(parse_tl(root / file, layer, methods) for file in TLOBJECT_IN_TLS)
111
+ )
112
+ )
113
+
114
+ generate_tlobjects(tlobjects, layer, IMPORT_DEPTH, generated_tl_dir)
115
+ generated_errors.parent.mkdir(parents=True, exist_ok=True)
116
+ with generated_errors.open("w") as file:
117
+ generate_errors(errors, file)
118
+
119
+ build_data["force_include"][str(generated_tl_dir / "functions")] = str(
120
+ TLOBJECT_OUT / "functions"
121
+ )
122
+ build_data["force_include"][str(generated_tl_dir / "types")] = str(
123
+ TLOBJECT_OUT / "types"
124
+ )
125
+ build_data["force_include"][str(generated_tl_dir / "alltlobjects.py")] = str(
126
+ TLOBJECT_OUT / "alltlobjects.py"
127
+ )
128
+ build_data["force_include"][str(generated_errors)] = str(ERRORS_OUT)
129
+
130
+ def finalize(
131
+ self, version: str, build_data: dict[str, Any], artifact_path: str
132
+ ) -> None:
133
+ self.clean([])
@@ -0,0 +1,13 @@
1
+ from .client.telegramclient import TelegramClient
2
+ from .network import connection
3
+ from .tl.custom import Button
4
+ from .tl import patched as _ # import for its side-effects
5
+ from . import version, events, utils, errors, types, functions, custom
6
+
7
+ __version__ = version.__version__
8
+
9
+ __all__ = [
10
+ 'TelegramClient', 'Button',
11
+ 'types', 'functions', 'custom', 'errors',
12
+ 'events', 'utils', 'connection'
13
+ ]
@@ -0,0 +1,3 @@
1
+ from .entitycache import EntityCache
2
+ from .messagebox import MessageBox, GapError, PrematureEndReason
3
+ from .session import SessionState, ChannelState, Entity, EntityType
@@ -0,0 +1,59 @@
1
+ from .session import EntityType, Entity
2
+
3
+
4
+ _sentinel = object()
5
+
6
+
7
+ class EntityCache:
8
+ def __init__(
9
+ self,
10
+ hash_map: dict = _sentinel,
11
+ self_id: int = None,
12
+ self_bot: bool = None
13
+ ):
14
+ self.hash_map = {} if hash_map is _sentinel else hash_map
15
+ self.self_id = self_id
16
+ self.self_bot = self_bot
17
+
18
+ def set_self_user(self, id, bot, hash):
19
+ self.self_id = id
20
+ self.self_bot = bot
21
+ if hash:
22
+ self.hash_map[id] = (hash, EntityType.BOT if bot else EntityType.USER)
23
+
24
+ def get(self, id):
25
+ try:
26
+ hash, ty = self.hash_map[id]
27
+ return Entity(ty, id, hash)
28
+ except KeyError:
29
+ return None
30
+
31
+ def extend(self, users, chats):
32
+ # See https://core.telegram.org/api/min for "issues" with "min constructors".
33
+ self.hash_map.update(
34
+ (u.id, (
35
+ u.access_hash,
36
+ EntityType.BOT if u.bot else EntityType.USER,
37
+ ))
38
+ for u in users
39
+ if getattr(u, 'access_hash', None) and not u.min
40
+ )
41
+ self.hash_map.update(
42
+ (c.id, (
43
+ c.access_hash,
44
+ EntityType.MEGAGROUP if c.megagroup else (
45
+ EntityType.GIGAGROUP if getattr(c, 'gigagroup', None) else EntityType.CHANNEL
46
+ ),
47
+ ))
48
+ for c in chats
49
+ if getattr(c, 'access_hash', None) and not getattr(c, 'min', None)
50
+ )
51
+
52
+ def put(self, entity):
53
+ self.hash_map[entity.id] = (entity.hash, entity.ty)
54
+
55
+ def retain(self, filter):
56
+ self.hash_map = {k: v for k, v in self.hash_map.items() if filter(k)}
57
+
58
+ def __len__(self):
59
+ return len(self.hash_map)