Skip to content

Commit 5734faf

Browse files
committed
Update: 2.4.0 (#38)
Layer 228, Communities, Monoforum, Ephemeral edit methods, Rich Messages, Guard Bot, and more. Layer Updates - Updated API schema through layers 221 -> 228. - Added ephemeral.editMessage and updateEphemeralBotCallbackQuery to the TL schema (missing from upstream layer 228 dump). Communities - New communities.* namespace with 10 methods, including add_chat_to_community and get_joined_communities. - Documented the separate community ID space (no -100 prefix) in the FAQ. Monoforum / Direct Messages - New methods: toggle_direct_messages, get_monoforum_dialogs, get_monoforum_history, read_monoforum_history, delete_monoforum_history. Ephemeral Messages - New ephemeral.* namespace: send/delete/report/get_callback_answer. - New edit methods: edit_ephemeral_message_text, _caption, _media, _reply_markup. Rich Messages (Bot API 10.1) - New types: RichMessage, RichText, RichBlock, InputRichMessage, PollLink. - New methods: send_rich_message, send_rich_message_draft, translate_rich_message, compose_rich_message_with_ai, request_chat_join_web_view. Guard Bot & Join Request Queries - set_chat_guard_bot, answer_guard_bot_query, answer_chat_join_request_query, send_chat_join_request_web_app. Streaming Text - send_streaming_text. Bot & Browser Settings - get/edit_bot_access_settings, confirm_bot_connection, get/update_web_browser_settings, toggle/delete_web_browser_exception(s). User & Chat - New User/Chat fields (color, profile_color, linked_community_id, monoforum, etc.), new PeerColor type, ChatPrivileges additions. Styled Keyboards - InlineKeyboardButton/KeyboardButton style parameter, new KeyboardButtonStyle enum. Bug Fixes - Session reconnect deadlock fixed. - account.* namespace corrected for web browser methods and confirm_bot_connection. - Fixed message_thread_id, EmojiStatusUntil AttributeError, PeerID invalid. - Fixed messages.chatInviteJoinResultWebView TL ID/schema. - Fixed messages.composedRichMessageWithAI TL ID/schema. - Fixed TypeError on send_message from missing ephemeral_receiver_bot_id. Build - Migrated scrape-errors CI to uv. - docs.json regenerated for layers 225, 227, 228. - invoke() now has a generic return type. - Fixed async/asyncio compatibility for Python 3.13 & 3.14.
1 parent d83820e commit 5734faf

183 files changed

Lines changed: 11076 additions & 2079 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/python.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,24 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest, macos-latest]
16-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
16+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1717

1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
2121

22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v5
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v5
2424
with:
2525
python-version: ${{ matrix.python-version }}
26-
cache: "pip"
2726

28-
- name: Upgrade pip and install dependencies
29-
run: |
30-
python -m pip install --upgrade pip
31-
pip install --upgrade tox wheel setuptools
27+
- name: Install dependencies
28+
run: uv sync --extra dev
3229

3330
- name: Generate API
34-
run: |
35-
make venv
36-
make api
31+
run: make api
3732

38-
- name: Run tests with tox
33+
- name: Run tests
3934
env:
4035
PYTHONWARNINGS: "ignore"
41-
run: tox
36+
run: uv run pytest

.github/workflows/scrape-errors.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,29 @@ jobs:
1414

1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 1
2020

21-
- name: Set up Python 3.9
22-
uses: actions/setup-python@v3
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v5
2323
with:
24-
python-version: '3.9'
24+
python-version: "3.10"
2525

2626
- name: Install Python dependencies and run scripts
2727
run: |
28-
set -e # Exit immediately if a command exits with a non-zero status
29-
echo "-------------------- Installing dependencies --------------------"
30-
cd compiler/errors/
31-
python -m pip install --upgrade pip setuptools wheel
32-
python -m pip install requests==2.28.1
28+
set -e
3329
echo "-------------------- Running scrape script --------------------"
34-
python sort.py scrape
30+
uv run --with requests compiler/errors/sort.py scrape
3531
echo "-------------------- Running sort script --------------------"
36-
python sort.py sort
32+
uv run --with requests compiler/errors/sort.py sort
3733
3834
- name: Check for changes and commit
3935
run: |
4036
git config --local user.email "github-actions[bot]@users.noreply.github.com"
4137
git config --local user.name "GitHub Actions Bot"
4238
43-
if ! git diff --quiet; then # Check if there are any changes
39+
if ! git diff --quiet; then
4440
echo "Changes detected in error files."
4541
git add .
4642
git commit -m "Automated update of unknown_errors"
@@ -50,4 +46,4 @@ jobs:
5046
echo "No changes detected in error files. Skipping commit and push."
5147
fi
5248
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@ venv.bak/
130130
docs_build.sh
131131
.buildinfo
132132
json_docs.py
133+
/scripts
134+
/tests
135+
/uv.lock
136+
/examples
137+
/changelogs

Makefile

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
VENV := venv
2-
PYTHON := $(VENV)/bin/python
3-
ifeq ($(OS),Windows_NT)
4-
PYTHON := $(VENV)/Scripts/python.exe
5-
endif
6-
71
HOST := $(shell ifconfig | grep "inet " | tail -1 | cut -d\ -f2 2>/dev/null || echo "127.0.0.1")
82
TAG := v$(shell grep -E '__version__ = ".*"' pyrogram/__init__.py | cut -d\" -f2)
93

104
RM := rm -rf
115

12-
NUM_CORES := $(shell $(PYTHON) -c "import os; print(os.cpu_count())")
6+
NUM_CORES := $(shell uv run python -c "import os; print(os.cpu_count())" 2>/dev/null || echo 1)
137

14-
.PHONY: venv clean-build clean-api clean api build docs clean-docs tag dtag
8+
.PHONY: venv test clean-build clean-api clean api build docs clean-docs tag dtag tagall
159

1610
venv:
17-
$(RM) $(VENV)
18-
python3 -m venv $(VENV)
19-
$(PYTHON) -m pip install -U pip wheel setuptools
20-
$(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt
21-
@echo "Created venv with $$($(PYTHON) --version)"
11+
uv sync --extra dev --extra docs
12+
@echo "Synced venv with $$(uv run python --version)"
13+
14+
test:
15+
uv run pytest
2216

2317
clean-build:
2418
$(RM) *.egg-info build dist
@@ -40,18 +34,17 @@ clean-docs:
4034
$(RM) docs/source/api/bound-methods docs/source/api/methods docs/source/api/types docs/source/telegram
4135

4236
api:
43-
cd compiler/api && ../../$(PYTHON) compiler.py
44-
cd compiler/errors && ../../$(PYTHON) compiler.py
37+
cd compiler/api && uv run python compiler.py
38+
cd compiler/errors && uv run python compiler.py
4539

4640
docs:
4741
make clean-docs
48-
cd compiler/docs && ../../$(PYTHON) compiler.py
49-
$(PYTHON) -m sphinx -b html "docs/source" "docs/build/html" -j$(NUM_CORES)
42+
cd compiler/docs && uv run python compiler.py
43+
uv run python -m sphinx -b html "docs/source" "docs/build/html" -j$(NUM_CORES)
5044

5145
build:
5246
make clean
53-
$(PYTHON) setup.py sdist
54-
$(PYTHON) setup.py bdist_wheel
47+
uv build
5548

5649
tag:
5750
git tag $(TAG)
@@ -60,3 +53,22 @@ tag:
6053
dtag:
6154
git tag -d $(TAG)
6255
git push origin -d $(TAG)
56+
57+
tagall:
58+
echo "Creating automatic tags for all version bumps..."
59+
for hash in $$(git log --grep="Bump version\|Version bump\|v[0-9]\+\.[0-9]\+\.[0-9]\+" --format="%H"); do \
60+
msg=$$(git log -1 --format="%s" $$hash); \
61+
versions=$$(echo "$$msg" | grep -o "v[0-9]\+\.[0-9]\+\.[0-9]\+"); \
62+
for version in $$versions; do \
63+
if [ -n "$$version" ]; then \
64+
if git show-ref --tags --quiet --verify "refs/tags/$$version"; then \
65+
echo "Tag $$version already exists, skipping."; \
66+
else \
67+
echo "Creating tag $$version for commit $$hash"; \
68+
git tag -a "$$version" "$$hash" -m "Automatic tag $$version"; \
69+
fi; \
70+
fi; \
71+
done; \
72+
done
73+
echo "Pushing all tags to the remote..."
74+
git push origin --tags

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Documentation
1414
</a>
1515
16-
<a href="https://t.me/pyrogrammodnews">
16+
<a href="https://telegram.me/pyrogrammodnews">
1717
News
1818
</a>
1919
</p>
@@ -67,8 +67,8 @@ pip3 install https://github.com/PyrogramMod/PyrogramMod/archive/refs/heads/main.
6767
### Resources
6868

6969
- The docs contain lots of resources to help you get started with Pyrogram: https://docs.pyrogram.org.
70-
- Seeking extra help? Come join and ask our community: https://t.me/pyrogrammodchat.
71-
- For other kind of inquiries, you can send a [message](https://t.me/haskell) or an [e-mail](mailto:dan@pyrogram.org).
70+
- Seeking extra help? Come join and ask our community: https://telegram.me/pyrogrammodchat.
71+
- For other kind of inquiries, you can send a [message](https://telegram.me/haskell) or an [e-mail](mailto:dan@pyrogram.org).
7272

7373
### Copyright & License
7474

@@ -78,16 +78,16 @@ pip3 install https://github.com/PyrogramMod/PyrogramMod/archive/refs/heads/main.
7878
### INFO
7979

8080
- 📕 Official Repo: https://github.com/pyrogram/pyrogram
81-
- 🗞 News: https://t.me/pyrogram
82-
- 💭 Support Group: https://t.me/pyrogramchat
81+
- 🗞 News: https://telegram.me/pyrogram
82+
- 💭 Support Group: https://telegram.me/pyrogramchat
8383
- 📚 Docs: https://docs.pyrogram.org
8484
------------------------------------------------------------
8585
- 📕 Un-Official Repo: https://github.com/PyrogramMod/PyrogramMod/
86-
- 🗞 News: https://t.me/PyroGramModNews
87-
- 💭 Support Group: https://t.me/pyrogramodchat
86+
- 🗞 News: https://telegram.me/PyroGramModNews
87+
- 💭 Support Group: https://telegram.me/pyrogramodchat
8888
- 📚 Docs: https://pyrogrammod.readthedocs.io/en/latest/
8989
------------------------------------------------------------
9090

9191
- Check out the docs at https://docs.pyrogram.org to learn more about Pyrogram, get started right
9292
away and discover more in-depth material for building your client applications.
93-
- Join the official channel at https://t.me/PyroGramModNews and stay tuned for news, updates and announcements.
93+
- Join the official channel at https://telegram.me/PyroGramModNews and stay tuned for news, updates and announcements.

compiler/api/compiler.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ def camel(s: str):
100100
return "".join([i[0].upper() + i[1:] for i in s.split("_")])
101101

102102

103+
# noinspection PyShadowingBuiltins, PyShadowingNames
104+
def get_return_type_hint(qualtype: str) -> str:
105+
"""Get return type hint for generic TLObject"""
106+
if qualtype.startswith("Vector"):
107+
# Extract inner type from Vector<Type>
108+
inner = qualtype.split("<")[1][:-1]
109+
ns, name = inner.split(".") if "." in inner else ("", inner)
110+
return f'"List[raw.base.{".".join([ns, name]).strip(".")}]"'
111+
else:
112+
ns, name = qualtype.split(".") if "." in qualtype else ("", qualtype)
113+
return f'"raw.base.{".".join([ns, name]).strip(".")}"'
114+
115+
103116
# noinspection PyShadowingBuiltins, PyShadowingNames
104117
def get_type_hint(type: str) -> str:
105118
is_flag = FLAGS_RE.match(type)
@@ -301,7 +314,7 @@ def start(format: bool = False):
301314
d[qualtype].append(c.qualname)
302315

303316
if c.section == "types":
304-
key = c.namespace
317+
key = c.typespace if len(c.namespace) == 0 else c.namespace
305318

306319
if key not in namespaces_to_types:
307320
namespaces_to_types[key] = []
@@ -548,6 +561,12 @@ def start(format: bool = False):
548561
slots = ", ".join([f'"{i[0]}"' for i in sorted_args])
549562
return_arguments = ", ".join([f"{i[0]}={i[0]}" for i in sorted_args])
550563

564+
# Generate generic type hint for functions
565+
if c.section == "functions":
566+
generic_type = f"[{get_return_type_hint(c.qualtype)}]"
567+
else:
568+
generic_type = ""
569+
551570
compiled_combinator = combinator_tmpl.format(
552571
notice=notice,
553572
warning=WARNING,
@@ -560,7 +579,8 @@ def start(format: bool = False):
560579
fields=fields,
561580
read_types=read_types,
562581
write_types=write_types,
563-
return_arguments=return_arguments
582+
return_arguments=return_arguments,
583+
generic_type=generic_type
564584
)
565585

566586
directory = "types" if c.section == "types" else c.section
@@ -585,6 +605,7 @@ def start(format: bool = False):
585605
d[c.namespace].append(c.name)
586606

587607
for namespace, types in namespaces_to_types.items():
608+
os.makedirs(DESTINATION_PATH / "base" / namespace, exist_ok=True)
588609
with open(DESTINATION_PATH / "base" / namespace / "__init__.py", "w") as f:
589610
f.write(f"{notice}\n\n")
590611
f.write(f"{WARNING}\n\n")

0 commit comments

Comments
 (0)