catethon 1.46.1__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.
- catethon-1.46.1/.gitignore +17 -0
- catethon-1.46.1/LICENSE +21 -0
- catethon-1.46.1/NOTICE +20 -0
- catethon-1.46.1/PKG-INFO +192 -0
- catethon-1.46.1/README.md +163 -0
- catethon-1.46.1/catethon/__init__.py +13 -0
- catethon-1.46.1/catethon/_updates/__init__.py +3 -0
- catethon-1.46.1/catethon/_updates/entitycache.py +62 -0
- catethon-1.46.1/catethon/_updates/messagebox.py +825 -0
- catethon-1.46.1/catethon/_updates/session.py +198 -0
- catethon-1.46.1/catethon/cat/__init__.py +36 -0
- catethon-1.46.1/catethon/cat/config.py +113 -0
- catethon-1.46.1/catethon/cat/keys/thecat-prod-rsa.pub +9 -0
- catethon-1.46.1/catethon/cat/proxy.py +51 -0
- catethon-1.46.1/catethon/cat/rsapad.py +111 -0
- catethon-1.46.1/catethon/cat/server.py +185 -0
- catethon-1.46.1/catethon/cat/session.py +85 -0
- catethon-1.46.1/catethon/client/__init__.py +25 -0
- catethon-1.46.1/catethon/client/account.py +243 -0
- catethon-1.46.1/catethon/client/auth.py +677 -0
- catethon-1.46.1/catethon/client/bots.py +72 -0
- catethon-1.46.1/catethon/client/buttons.py +104 -0
- catethon-1.46.1/catethon/client/chats.py +1336 -0
- catethon-1.46.1/catethon/client/dialogs.py +610 -0
- catethon-1.46.1/catethon/client/downloads.py +1092 -0
- catethon-1.46.1/catethon/client/messageparse.py +233 -0
- catethon-1.46.1/catethon/client/messages.py +1637 -0
- catethon-1.46.1/catethon/client/telegrambaseclient.py +979 -0
- catethon-1.46.1/catethon/client/telegramclient.py +13 -0
- catethon-1.46.1/catethon/client/updates.py +733 -0
- catethon-1.46.1/catethon/client/uploads.py +870 -0
- catethon-1.46.1/catethon/client/users.py +620 -0
- catethon-1.46.1/catethon/crypto/__init__.py +10 -0
- catethon-1.46.1/catethon/crypto/aes.py +111 -0
- catethon-1.46.1/catethon/crypto/aesctr.py +42 -0
- catethon-1.46.1/catethon/crypto/authkey.py +63 -0
- catethon-1.46.1/catethon/crypto/cdndecrypter.py +105 -0
- catethon-1.46.1/catethon/crypto/factorization.py +67 -0
- catethon-1.46.1/catethon/crypto/libssl.py +140 -0
- catethon-1.46.1/catethon/crypto/rsa.py +165 -0
- catethon-1.46.1/catethon/custom.py +1 -0
- catethon-1.46.1/catethon/errors/__init__.py +46 -0
- catethon-1.46.1/catethon/errors/common.py +180 -0
- catethon-1.46.1/catethon/errors/rpcbaseerrors.py +131 -0
- catethon-1.46.1/catethon/errors/rpcerrorlist.py +5356 -0
- catethon-1.46.1/catethon/events/__init__.py +140 -0
- catethon-1.46.1/catethon/events/album.py +343 -0
- catethon-1.46.1/catethon/events/callbackquery.py +346 -0
- catethon-1.46.1/catethon/events/chataction.py +458 -0
- catethon-1.46.1/catethon/events/common.py +186 -0
- catethon-1.46.1/catethon/events/inlinequery.py +247 -0
- catethon-1.46.1/catethon/events/messagedeleted.py +57 -0
- catethon-1.46.1/catethon/events/messageedited.py +52 -0
- catethon-1.46.1/catethon/events/messageread.py +143 -0
- catethon-1.46.1/catethon/events/newmessage.py +223 -0
- catethon-1.46.1/catethon/events/raw.py +53 -0
- catethon-1.46.1/catethon/events/userupdate.py +310 -0
- catethon-1.46.1/catethon/extensions/__init__.py +6 -0
- catethon-1.46.1/catethon/extensions/binaryreader.py +201 -0
- catethon-1.46.1/catethon/extensions/html.py +208 -0
- catethon-1.46.1/catethon/extensions/markdown.py +193 -0
- catethon-1.46.1/catethon/extensions/messagepacker.py +111 -0
- catethon-1.46.1/catethon/functions.py +1 -0
- catethon-1.46.1/catethon/helpers.py +436 -0
- catethon-1.46.1/catethon/hints.py +72 -0
- catethon-1.46.1/catethon/network/__init__.py +14 -0
- catethon-1.46.1/catethon/network/authenticator.py +212 -0
- catethon-1.46.1/catethon/network/connection/__init__.py +12 -0
- catethon-1.46.1/catethon/network/connection/connection.py +440 -0
- catethon-1.46.1/catethon/network/connection/http.py +39 -0
- catethon-1.46.1/catethon/network/connection/tcpabridged.py +33 -0
- catethon-1.46.1/catethon/network/connection/tcpfull.py +62 -0
- catethon-1.46.1/catethon/network/connection/tcpintermediate.py +46 -0
- catethon-1.46.1/catethon/network/connection/tcpmtproxy.py +165 -0
- catethon-1.46.1/catethon/network/connection/tcpobfuscated.py +62 -0
- catethon-1.46.1/catethon/network/mtprotoplainsender.py +56 -0
- catethon-1.46.1/catethon/network/mtprotosender.py +942 -0
- catethon-1.46.1/catethon/network/mtprotostate.py +285 -0
- catethon-1.46.1/catethon/network/requeststate.py +19 -0
- catethon-1.46.1/catethon/password.py +194 -0
- catethon-1.46.1/catethon/requestiter.py +134 -0
- catethon-1.46.1/catethon/sessions/__init__.py +4 -0
- catethon-1.46.1/catethon/sessions/abstract.py +172 -0
- catethon-1.46.1/catethon/sessions/memory.py +260 -0
- catethon-1.46.1/catethon/sessions/sqlite.py +385 -0
- catethon-1.46.1/catethon/sessions/string.py +63 -0
- catethon-1.46.1/catethon/sync.py +74 -0
- catethon-1.46.1/catethon/tl/__init__.py +1 -0
- catethon-1.46.1/catethon/tl/alltlobjects.py +2666 -0
- catethon-1.46.1/catethon/tl/core/__init__.py +26 -0
- catethon-1.46.1/catethon/tl/core/gzippacked.py +48 -0
- catethon-1.46.1/catethon/tl/core/messagecontainer.py +47 -0
- catethon-1.46.1/catethon/tl/core/rpcresult.py +35 -0
- catethon-1.46.1/catethon/tl/core/tlmessage.py +34 -0
- catethon-1.46.1/catethon/tl/custom/__init__.py +14 -0
- catethon-1.46.1/catethon/tl/custom/adminlogevent.py +475 -0
- catethon-1.46.1/catethon/tl/custom/button.py +347 -0
- catethon-1.46.1/catethon/tl/custom/chatgetter.py +150 -0
- catethon-1.46.1/catethon/tl/custom/conversation.py +529 -0
- catethon-1.46.1/catethon/tl/custom/dialog.py +172 -0
- catethon-1.46.1/catethon/tl/custom/draft.py +191 -0
- catethon-1.46.1/catethon/tl/custom/file.py +146 -0
- catethon-1.46.1/catethon/tl/custom/forward.py +51 -0
- catethon-1.46.1/catethon/tl/custom/inlinebuilder.py +450 -0
- catethon-1.46.1/catethon/tl/custom/inlineresult.py +176 -0
- catethon-1.46.1/catethon/tl/custom/inlineresults.py +83 -0
- catethon-1.46.1/catethon/tl/custom/inputsizedfile.py +9 -0
- catethon-1.46.1/catethon/tl/custom/message.py +1248 -0
- catethon-1.46.1/catethon/tl/custom/messagebutton.py +154 -0
- catethon-1.46.1/catethon/tl/custom/participantpermissions.py +138 -0
- catethon-1.46.1/catethon/tl/custom/qrlogin.py +119 -0
- catethon-1.46.1/catethon/tl/custom/sendergetter.py +102 -0
- catethon-1.46.1/catethon/tl/functions/__init__.py +717 -0
- catethon-1.46.1/catethon/tl/functions/account.py +4034 -0
- catethon-1.46.1/catethon/tl/functions/aicompose.py +260 -0
- catethon-1.46.1/catethon/tl/functions/auth.py +1057 -0
- catethon-1.46.1/catethon/tl/functions/bots.py +1497 -0
- catethon-1.46.1/catethon/tl/functions/channels.py +2254 -0
- catethon-1.46.1/catethon/tl/functions/chatlists.py +425 -0
- catethon-1.46.1/catethon/tl/functions/communities.py +359 -0
- catethon-1.46.1/catethon/tl/functions/contacts.py +1034 -0
- catethon-1.46.1/catethon/tl/functions/ephemeral.py +456 -0
- catethon-1.46.1/catethon/tl/functions/folders.py +44 -0
- catethon-1.46.1/catethon/tl/functions/fragment.py +39 -0
- catethon-1.46.1/catethon/tl/functions/help.py +672 -0
- catethon-1.46.1/catethon/tl/functions/langpack.py +178 -0
- catethon-1.46.1/catethon/tl/functions/messages.py +11597 -0
- catethon-1.46.1/catethon/tl/functions/payments.py +2917 -0
- catethon-1.46.1/catethon/tl/functions/phone.py +1794 -0
- catethon-1.46.1/catethon/tl/functions/photos.py +282 -0
- catethon-1.46.1/catethon/tl/functions/premium.py +188 -0
- catethon-1.46.1/catethon/tl/functions/smsjobs.py +180 -0
- catethon-1.46.1/catethon/tl/functions/stats.py +332 -0
- catethon-1.46.1/catethon/tl/functions/stickers.py +440 -0
- catethon-1.46.1/catethon/tl/functions/stories.py +1574 -0
- catethon-1.46.1/catethon/tl/functions/toncenter.py +75 -0
- catethon-1.46.1/catethon/tl/functions/updates.py +139 -0
- catethon-1.46.1/catethon/tl/functions/upload.py +300 -0
- catethon-1.46.1/catethon/tl/functions/users.py +285 -0
- catethon-1.46.1/catethon/tl/functions/wallet.py +928 -0
- catethon-1.46.1/catethon/tl/patched/__init__.py +20 -0
- catethon-1.46.1/catethon/tl/tlobject.py +222 -0
- catethon-1.46.1/catethon/tl/types/__init__.py +56275 -0
- catethon-1.46.1/catethon/tl/types/account.py +1501 -0
- catethon-1.46.1/catethon/tl/types/aicompose.py +75 -0
- catethon-1.46.1/catethon/tl/types/auth.py +972 -0
- catethon-1.46.1/catethon/tl/types/bots.py +229 -0
- catethon-1.46.1/catethon/tl/types/channels.py +307 -0
- catethon-1.46.1/catethon/tl/types/chatlists.py +276 -0
- catethon-1.46.1/catethon/tl/types/communities.py +135 -0
- catethon-1.46.1/catethon/tl/types/contacts.py +548 -0
- catethon-1.46.1/catethon/tl/types/ephemeral.py +66 -0
- catethon-1.46.1/catethon/tl/types/fragment.py +55 -0
- catethon-1.46.1/catethon/tl/types/help.py +1248 -0
- catethon-1.46.1/catethon/tl/types/messages.py +4044 -0
- catethon-1.46.1/catethon/tl/types/payments.py +1965 -0
- catethon-1.46.1/catethon/tl/types/phone.py +368 -0
- catethon-1.46.1/catethon/tl/types/photos.py +135 -0
- catethon-1.46.1/catethon/tl/types/premium.py +209 -0
- catethon-1.46.1/catethon/tl/types/smsjobs.py +100 -0
- catethon-1.46.1/catethon/tl/types/stats.py +396 -0
- catethon-1.46.1/catethon/tl/types/stickers.py +35 -0
- catethon-1.46.1/catethon/tl/types/storage.py +197 -0
- catethon-1.46.1/catethon/tl/types/stories.py +563 -0
- catethon-1.46.1/catethon/tl/types/toncenter.py +70 -0
- catethon-1.46.1/catethon/tl/types/updates.py +447 -0
- catethon-1.46.1/catethon/tl/types/upload.py +196 -0
- catethon-1.46.1/catethon/tl/types/users.py +191 -0
- catethon-1.46.1/catethon/tl/types/wallet.py +663 -0
- catethon-1.46.1/catethon/types.py +1 -0
- catethon-1.46.1/catethon/utils.py +1584 -0
- catethon-1.46.1/catethon/version.py +15 -0
- catethon-1.46.1/pyproject.toml +65 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Generated code (upstream gitignores these; the fork commits the generated TL,
|
|
2
|
+
# so this only matters if someone runs the generator over the tree).
|
|
3
|
+
/dist/
|
|
4
|
+
/build/
|
|
5
|
+
*.egg-info/
|
|
6
|
+
|
|
7
|
+
# Python bytecode and caches.
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
.coverage
|
|
12
|
+
htmlcov/
|
|
13
|
+
|
|
14
|
+
# Local session files and media. A session string is a login; never commit one.
|
|
15
|
+
*.session
|
|
16
|
+
*.session-journal
|
|
17
|
+
/usermedia/
|
catethon-1.46.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-Present LonamiWebs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
catethon-1.46.1/NOTICE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
catethon
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
This product includes software developed as part of Telethon
|
|
5
|
+
(https://codeberg.org/Lonami/Telethon), Copyright (c) 2016-Present LonamiWebs,
|
|
6
|
+
licensed under the MIT License. The full upstream licence text is in LICENSE
|
|
7
|
+
and is unchanged.
|
|
8
|
+
|
|
9
|
+
Source of the imported base: Telethon 1.46.0 (layer 233), PyPI sdist
|
|
10
|
+
telethon-1.46.0.tar.gz, sha256
|
|
11
|
+
8357f5719376a9c1ddf0999136a44594a5b21b453647f1e146c169483b6a67df.
|
|
12
|
+
|
|
13
|
+
Modifications for catethon, all by the cat-server project:
|
|
14
|
+
|
|
15
|
+
* import package renamed telethon -> catethon
|
|
16
|
+
* packaging metadata renamed and re-pointed at the renamed package
|
|
17
|
+
* catethon/cat/, a helper package, and tests/telethon/cat/
|
|
18
|
+
|
|
19
|
+
Everything else is upstream's work, unmodified except as listed.
|
|
20
|
+
UPSTREAM_SYNC.md records the full change list per upstream release.
|
catethon-1.46.1/PKG-INFO
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: catethon
|
|
3
|
+
Version: 1.46.1
|
|
4
|
+
Summary: Python client for Cat Messenger (The Cat): a Telethon fork that speaks to Cat Messenger's own MTProto servers
|
|
5
|
+
Project-URL: Homepage, https://catroom.ir
|
|
6
|
+
Project-URL: Source, https://github.com/mrfelfel/catethon
|
|
7
|
+
Project-URL: Fork of, https://codeberg.org/Lonami/Telethon
|
|
8
|
+
Project-URL: Documentation, https://docs.telethon.dev
|
|
9
|
+
Project-URL: Reference, https://tl.telethon.dev
|
|
10
|
+
Author: CatGram / the cat project
|
|
11
|
+
Author-email: Lonami Exo <totufals@hotmail.com>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
License-File: NOTICE
|
|
15
|
+
Keywords: api,cat-messenger,chat,client,library,messaging,mtproto,the-cat
|
|
16
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Topic :: Communications :: Chat
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: pyaes
|
|
23
|
+
Requires-Dist: rsa
|
|
24
|
+
Provides-Extra: cryptg
|
|
25
|
+
Requires-Dist: cryptg; extra == 'cryptg'
|
|
26
|
+
Provides-Extra: socks
|
|
27
|
+
Requires-Dist: python-socks[asyncio]; extra == 'socks'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# catethon
|
|
31
|
+
|
|
32
|
+
**catethon is the Python client for Cat Messenger (`The Cat`).**
|
|
33
|
+
|
|
34
|
+
It speaks MTProto to Cat Messenger's own servers — not to Telegram's cloud —
|
|
35
|
+
so a Python program can log in, read chats, send messages, and fetch media on
|
|
36
|
+
The Cat the same way a phone app does.
|
|
37
|
+
|
|
38
|
+
catethon is a fork of [Telethon](https://codeberg.org/Lonami/Telethon), the
|
|
39
|
+
long-standing asyncio MTProto library. The protocol engine is Telethon's; what
|
|
40
|
+
this fork adds is the Cat Messenger server, its public key, and sensible
|
|
41
|
+
defaults, so that connecting is one line instead of a runbook.
|
|
42
|
+
|
|
43
|
+
- Import name: `catethon`
|
|
44
|
+
- Distribution name: `catethon`
|
|
45
|
+
- Version: `1.46.1` (Telethon 1.46.0 base, layer 233)
|
|
46
|
+
- Licence: MIT (upstream's, unchanged — see [`NOTICE`](https://github.com/mrfelfel/catethon/blob/catethon/main/NOTICE))
|
|
47
|
+
- Cat Messenger: <https://catroom.ir> · source: <https://github.com/mrfelfel/catethon>
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install catethon
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Behind a SOCKS proxy (many networks need one to reach Cat Messenger):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install "catethon[socks]"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Python 3.9 or newer.
|
|
62
|
+
|
|
63
|
+
If PyPI is unreachable, install straight from the repository instead:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install "catethon @ git+https://github.com/mrfelfel/catethon.git@catethon/main"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Which channel is live is in [`PUBLISHING.md`](https://github.com/mrfelfel/catethon/blob/catethon/main/PUBLISHING.md); it also records
|
|
70
|
+
what a release needs, so the two do not drift apart.
|
|
71
|
+
|
|
72
|
+
## Connect to Cat Messenger
|
|
73
|
+
|
|
74
|
+
This is the whole thing:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import asyncio
|
|
78
|
+
from catethon.cat import prepare
|
|
79
|
+
|
|
80
|
+
async def main():
|
|
81
|
+
# api_id / api_hash come from Cat Messenger (the same values the official
|
|
82
|
+
# apps use); see "Application id" below.
|
|
83
|
+
prepared = prepare()
|
|
84
|
+
client = prepared.make_client(api_id=17349, api_hash="...")
|
|
85
|
+
|
|
86
|
+
await client.connect()
|
|
87
|
+
if not await client.is_user_authorized():
|
|
88
|
+
await client.send_code_request("+98...")
|
|
89
|
+
await client.sign_in("+98...", input("code: "))
|
|
90
|
+
|
|
91
|
+
async for dialog in client.iter_dialogs():
|
|
92
|
+
print(dialog.name)
|
|
93
|
+
|
|
94
|
+
await client.disconnect()
|
|
95
|
+
|
|
96
|
+
asyncio.run(main())
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`prepare()` points the client at the Cat Messenger server, registers that
|
|
100
|
+
server's public key, and picks the transport. You do not choose a DC or paste
|
|
101
|
+
a key.
|
|
102
|
+
|
|
103
|
+
### What `prepare()` sets
|
|
104
|
+
|
|
105
|
+
| value | default | override |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| host | `62.220.127.238` | `prepare(host=...)` |
|
|
108
|
+
| port | `30001` | `prepare(port=...)` |
|
|
109
|
+
| DC id | `2` | `prepare(dc_id=...)` |
|
|
110
|
+
| transport | TCP full | `prepare(transport="http")` |
|
|
111
|
+
| server key | bundled, fingerprint-checked | — |
|
|
112
|
+
|
|
113
|
+
The server's public key ships in
|
|
114
|
+
[`catethon/cat/keys/thecat-prod-rsa.pub`](https://github.com/mrfelfel/catethon/blob/catethon/main/catethon/cat/keys/thecat-prod-rsa.pub)
|
|
115
|
+
and its SHA-256 is checked when it loads, so a corrupted checkout fails at
|
|
116
|
+
import instead of as a handshake timeout. That is the same key the production
|
|
117
|
+
server announces during key exchange (fingerprint `0x19a8af0a0c89b11a`).
|
|
118
|
+
|
|
119
|
+
### Application id
|
|
120
|
+
|
|
121
|
+
MTProto requires an `api_id` / `api_hash` pair that identifies the
|
|
122
|
+
*application*, not the user. Cat Messenger uses the published Telegram Desktop
|
|
123
|
+
pair, which is what `catethon.cat.config` defaults to; you can leave it alone:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from catethon.cat import from_env
|
|
127
|
+
settings = from_env() # api_id=17349, api_hash=..., proxy from env
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Your phone number, login code and 2FA password are your own account
|
|
131
|
+
credentials and are never bundled or stored by this library.
|
|
132
|
+
|
|
133
|
+
### Proxy
|
|
134
|
+
|
|
135
|
+
If your network needs a SOCKS proxy, set it once and both the URL parsing and
|
|
136
|
+
the session wiring are handled:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
export SOCKS5_PROXY=socks5h://127.0.0.1:1080
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from catethon.cat import from_env, parse_proxy
|
|
144
|
+
settings = from_env()
|
|
145
|
+
client = prepared.make_client(
|
|
146
|
+
settings.api_id, settings.api_hash, proxy=parse_proxy(settings.proxy_url))
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`parse_proxy` accepts `socks5://`, `socks5h://` (remote DNS), `socks4://` and
|
|
150
|
+
`http://`. It needs the `socks` extra.
|
|
151
|
+
|
|
152
|
+
## Sessions
|
|
153
|
+
|
|
154
|
+
Two ways to stay logged in:
|
|
155
|
+
|
|
156
|
+
- **A file session** — pass a filename: `make_client` works with Telethon's
|
|
157
|
+
usual file-backed session, so the login persists on disk.
|
|
158
|
+
- **A session string** — export it once and reuse it:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from catethon.cat import session_from_env, string_session_for
|
|
162
|
+
session = session_from_env() # reads CATETHON_SESSION / TELETHON_SESSION
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Session strings use Telethon's documented format, so a string made by another
|
|
166
|
+
Telethon tool is readable here. Treat a session string like a password: anyone
|
|
167
|
+
who has it is logged in as you.
|
|
168
|
+
|
|
169
|
+
## Documentation
|
|
170
|
+
|
|
171
|
+
Everything Telethon documents still applies — the client, the raw API, the
|
|
172
|
+
event handlers. Only the import root changed:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
# Telethon docs say: catethon says:
|
|
176
|
+
from telethon import ... # from catethon import ...
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Upstream docs: <https://docs.telethon.dev> · raw API reference:
|
|
180
|
+
<https://tl.telethon.dev>. Substitute `catethon` for `telethon` in import
|
|
181
|
+
paths.
|
|
182
|
+
|
|
183
|
+
Fork specifics — what changed, what was left alone, and how to rebase onto a
|
|
184
|
+
new Telethon release — are in [`FORK.md`](https://github.com/mrfelfel/catethon/blob/catethon/main/FORK.md) and
|
|
185
|
+
[`UPSTREAM_SYNC.md`](https://github.com/mrfelfel/catethon/blob/catethon/main/UPSTREAM_SYNC.md).
|
|
186
|
+
|
|
187
|
+
## Licence and provenance
|
|
188
|
+
|
|
189
|
+
MIT, exactly as upstream. Telethon is Copyright (c) 2016-Present LonamiWebs;
|
|
190
|
+
that notice is kept in [`LICENSE`](https://github.com/mrfelfel/catethon/blob/catethon/main/LICENSE) and the provenance statement is in
|
|
191
|
+
[`NOTICE`](https://github.com/mrfelfel/catethon/blob/catethon/main/NOTICE). The fork changes the import package name and adds
|
|
192
|
+
`catethon/cat/`; it does not relicense anything.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# catethon
|
|
2
|
+
|
|
3
|
+
**catethon is the Python client for Cat Messenger (`The Cat`).**
|
|
4
|
+
|
|
5
|
+
It speaks MTProto to Cat Messenger's own servers — not to Telegram's cloud —
|
|
6
|
+
so a Python program can log in, read chats, send messages, and fetch media on
|
|
7
|
+
The Cat the same way a phone app does.
|
|
8
|
+
|
|
9
|
+
catethon is a fork of [Telethon](https://codeberg.org/Lonami/Telethon), the
|
|
10
|
+
long-standing asyncio MTProto library. The protocol engine is Telethon's; what
|
|
11
|
+
this fork adds is the Cat Messenger server, its public key, and sensible
|
|
12
|
+
defaults, so that connecting is one line instead of a runbook.
|
|
13
|
+
|
|
14
|
+
- Import name: `catethon`
|
|
15
|
+
- Distribution name: `catethon`
|
|
16
|
+
- Version: `1.46.1` (Telethon 1.46.0 base, layer 233)
|
|
17
|
+
- Licence: MIT (upstream's, unchanged — see [`NOTICE`](https://github.com/mrfelfel/catethon/blob/catethon/main/NOTICE))
|
|
18
|
+
- Cat Messenger: <https://catroom.ir> · source: <https://github.com/mrfelfel/catethon>
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install catethon
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Behind a SOCKS proxy (many networks need one to reach Cat Messenger):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install "catethon[socks]"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Python 3.9 or newer.
|
|
33
|
+
|
|
34
|
+
If PyPI is unreachable, install straight from the repository instead:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install "catethon @ git+https://github.com/mrfelfel/catethon.git@catethon/main"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Which channel is live is in [`PUBLISHING.md`](https://github.com/mrfelfel/catethon/blob/catethon/main/PUBLISHING.md); it also records
|
|
41
|
+
what a release needs, so the two do not drift apart.
|
|
42
|
+
|
|
43
|
+
## Connect to Cat Messenger
|
|
44
|
+
|
|
45
|
+
This is the whole thing:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import asyncio
|
|
49
|
+
from catethon.cat import prepare
|
|
50
|
+
|
|
51
|
+
async def main():
|
|
52
|
+
# api_id / api_hash come from Cat Messenger (the same values the official
|
|
53
|
+
# apps use); see "Application id" below.
|
|
54
|
+
prepared = prepare()
|
|
55
|
+
client = prepared.make_client(api_id=17349, api_hash="...")
|
|
56
|
+
|
|
57
|
+
await client.connect()
|
|
58
|
+
if not await client.is_user_authorized():
|
|
59
|
+
await client.send_code_request("+98...")
|
|
60
|
+
await client.sign_in("+98...", input("code: "))
|
|
61
|
+
|
|
62
|
+
async for dialog in client.iter_dialogs():
|
|
63
|
+
print(dialog.name)
|
|
64
|
+
|
|
65
|
+
await client.disconnect()
|
|
66
|
+
|
|
67
|
+
asyncio.run(main())
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`prepare()` points the client at the Cat Messenger server, registers that
|
|
71
|
+
server's public key, and picks the transport. You do not choose a DC or paste
|
|
72
|
+
a key.
|
|
73
|
+
|
|
74
|
+
### What `prepare()` sets
|
|
75
|
+
|
|
76
|
+
| value | default | override |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| host | `62.220.127.238` | `prepare(host=...)` |
|
|
79
|
+
| port | `30001` | `prepare(port=...)` |
|
|
80
|
+
| DC id | `2` | `prepare(dc_id=...)` |
|
|
81
|
+
| transport | TCP full | `prepare(transport="http")` |
|
|
82
|
+
| server key | bundled, fingerprint-checked | — |
|
|
83
|
+
|
|
84
|
+
The server's public key ships in
|
|
85
|
+
[`catethon/cat/keys/thecat-prod-rsa.pub`](https://github.com/mrfelfel/catethon/blob/catethon/main/catethon/cat/keys/thecat-prod-rsa.pub)
|
|
86
|
+
and its SHA-256 is checked when it loads, so a corrupted checkout fails at
|
|
87
|
+
import instead of as a handshake timeout. That is the same key the production
|
|
88
|
+
server announces during key exchange (fingerprint `0x19a8af0a0c89b11a`).
|
|
89
|
+
|
|
90
|
+
### Application id
|
|
91
|
+
|
|
92
|
+
MTProto requires an `api_id` / `api_hash` pair that identifies the
|
|
93
|
+
*application*, not the user. Cat Messenger uses the published Telegram Desktop
|
|
94
|
+
pair, which is what `catethon.cat.config` defaults to; you can leave it alone:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from catethon.cat import from_env
|
|
98
|
+
settings = from_env() # api_id=17349, api_hash=..., proxy from env
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Your phone number, login code and 2FA password are your own account
|
|
102
|
+
credentials and are never bundled or stored by this library.
|
|
103
|
+
|
|
104
|
+
### Proxy
|
|
105
|
+
|
|
106
|
+
If your network needs a SOCKS proxy, set it once and both the URL parsing and
|
|
107
|
+
the session wiring are handled:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
export SOCKS5_PROXY=socks5h://127.0.0.1:1080
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from catethon.cat import from_env, parse_proxy
|
|
115
|
+
settings = from_env()
|
|
116
|
+
client = prepared.make_client(
|
|
117
|
+
settings.api_id, settings.api_hash, proxy=parse_proxy(settings.proxy_url))
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`parse_proxy` accepts `socks5://`, `socks5h://` (remote DNS), `socks4://` and
|
|
121
|
+
`http://`. It needs the `socks` extra.
|
|
122
|
+
|
|
123
|
+
## Sessions
|
|
124
|
+
|
|
125
|
+
Two ways to stay logged in:
|
|
126
|
+
|
|
127
|
+
- **A file session** — pass a filename: `make_client` works with Telethon's
|
|
128
|
+
usual file-backed session, so the login persists on disk.
|
|
129
|
+
- **A session string** — export it once and reuse it:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from catethon.cat import session_from_env, string_session_for
|
|
133
|
+
session = session_from_env() # reads CATETHON_SESSION / TELETHON_SESSION
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Session strings use Telethon's documented format, so a string made by another
|
|
137
|
+
Telethon tool is readable here. Treat a session string like a password: anyone
|
|
138
|
+
who has it is logged in as you.
|
|
139
|
+
|
|
140
|
+
## Documentation
|
|
141
|
+
|
|
142
|
+
Everything Telethon documents still applies — the client, the raw API, the
|
|
143
|
+
event handlers. Only the import root changed:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
# Telethon docs say: catethon says:
|
|
147
|
+
from telethon import ... # from catethon import ...
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Upstream docs: <https://docs.telethon.dev> · raw API reference:
|
|
151
|
+
<https://tl.telethon.dev>. Substitute `catethon` for `telethon` in import
|
|
152
|
+
paths.
|
|
153
|
+
|
|
154
|
+
Fork specifics — what changed, what was left alone, and how to rebase onto a
|
|
155
|
+
new Telethon release — are in [`FORK.md`](https://github.com/mrfelfel/catethon/blob/catethon/main/FORK.md) and
|
|
156
|
+
[`UPSTREAM_SYNC.md`](https://github.com/mrfelfel/catethon/blob/catethon/main/UPSTREAM_SYNC.md).
|
|
157
|
+
|
|
158
|
+
## Licence and provenance
|
|
159
|
+
|
|
160
|
+
MIT, exactly as upstream. Telethon is Copyright (c) 2016-Present LonamiWebs;
|
|
161
|
+
that notice is kept in [`LICENSE`](https://github.com/mrfelfel/catethon/blob/catethon/main/LICENSE) and the provenance statement is in
|
|
162
|
+
[`NOTICE`](https://github.com/mrfelfel/catethon/blob/catethon/main/NOTICE). The fork changes the import package name and adds
|
|
163
|
+
`catethon/cat/`; it does not relicense anything.
|
|
@@ -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,62 @@
|
|
|
1
|
+
from .session import EntityType, Entity
|
|
2
|
+
from ..tl import types
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
_sentinel = object()
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class EntityCache:
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
hash_map: dict = _sentinel,
|
|
12
|
+
self_id: int = None,
|
|
13
|
+
self_bot: bool = None
|
|
14
|
+
):
|
|
15
|
+
self.hash_map = {} if hash_map is _sentinel else hash_map
|
|
16
|
+
self.self_id = self_id
|
|
17
|
+
self.self_bot = self_bot
|
|
18
|
+
|
|
19
|
+
def set_self_user(self, id, bot, hash):
|
|
20
|
+
self.self_id = id
|
|
21
|
+
self.self_bot = bot
|
|
22
|
+
if hash:
|
|
23
|
+
self.hash_map[id] = (hash, EntityType.BOT if bot else EntityType.USER)
|
|
24
|
+
|
|
25
|
+
def get(self, id):
|
|
26
|
+
try:
|
|
27
|
+
hash, ty = self.hash_map[id]
|
|
28
|
+
return Entity(ty, id, hash)
|
|
29
|
+
except KeyError:
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
def extend(self, users, chats):
|
|
33
|
+
# See https://core.telegram.org/api/min for "issues" with "min constructors".
|
|
34
|
+
self.hash_map.update(
|
|
35
|
+
(u.id, (
|
|
36
|
+
u.access_hash,
|
|
37
|
+
EntityType.BOT if u.bot else EntityType.USER,
|
|
38
|
+
))
|
|
39
|
+
for u in users
|
|
40
|
+
if getattr(u, 'access_hash', None) and not u.min
|
|
41
|
+
)
|
|
42
|
+
self.hash_map.update(
|
|
43
|
+
(c.id, (
|
|
44
|
+
c.access_hash,
|
|
45
|
+
EntityType.COMMUNITY if isinstance(c, types.Community) else (
|
|
46
|
+
EntityType.MEGAGROUP if getattr(c, 'megagroup', None) else (
|
|
47
|
+
EntityType.GIGAGROUP if getattr(c, 'gigagroup', None) else EntityType.CHANNEL
|
|
48
|
+
)
|
|
49
|
+
),
|
|
50
|
+
))
|
|
51
|
+
for c in chats
|
|
52
|
+
if getattr(c, 'access_hash', None) and not getattr(c, 'min', None)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def put(self, entity):
|
|
56
|
+
self.hash_map[entity.id] = (entity.hash, entity.ty)
|
|
57
|
+
|
|
58
|
+
def retain(self, filter):
|
|
59
|
+
self.hash_map = {k: v for k, v in self.hash_map.items() if filter(k)}
|
|
60
|
+
|
|
61
|
+
def __len__(self):
|
|
62
|
+
return len(self.hash_map)
|