Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit bfab8d8

Browse files
Update Pyrogram to v2.0.59
1 parent a18b176 commit bfab8d8

264 files changed

Lines changed: 466 additions & 3900 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.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Development
2+
docs
23
*.session
34
config.ini
45
main.py
56
unknown_errors.txt
7+
.DS_Store
68

79
# Pyrogram generated code
810
pyrogram/errors/exceptions/

Makefile

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
11
VENV := venv
22
PYTHON := $(VENV)/bin/python
3+
HOST = $(shell ifconfig | grep "inet " | tail -1 | cut -d\ -f2)
34

45
RM := rm -rf
56

6-
.PHONY: venv build docs
7+
.PHONY: venv clean-build clean-api clean api build
78

89
venv:
910
$(RM) $(VENV)
1011
python3 -m venv $(VENV)
1112
$(PYTHON) -m pip install -U pip wheel setuptools
12-
$(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt -r docs/requirements.txt
13+
$(PYTHON) -m pip install -U -r requirements.txt -r dev-requirements.txt
1314
@echo "Created venv with $$($(PYTHON) --version)"
1415

1516
clean-build:
1617
$(RM) *.egg-info build dist
1718

18-
clean-docs:
19-
$(RM) docs/build
20-
$(RM) docs/source/api/bound-methods docs/source/api/methods docs/source/api/types docs/source/telegram
21-
2219
clean-api:
2320
$(RM) pyrogram/errors/exceptions pyrogram/raw/all.py pyrogram/raw/base pyrogram/raw/functions pyrogram/raw/types
2421

2522
clean:
2623
make clean-build
27-
make clean-docs
2824
make clean-api
2925

3026
api:
3127
cd compiler/api && ../../$(PYTHON) compiler.py
3228
cd compiler/errors && ../../$(PYTHON) compiler.py
3329

34-
docs-live:
35-
make clean-docs
36-
cd compiler/docs && ../../$(PYTHON) compiler.py
37-
$(RM) docs/source/telegram
38-
$(VENV)/bin/sphinx-autobuild \
39-
--host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \
40-
--watch pyrogram --watch docs/resources \
41-
-b html "docs/source" "docs/build/html" -j auto
42-
43-
docs:
44-
make clean-docs
45-
cd compiler/docs && ../../$(PYTHON) compiler.py
46-
$(VENV)/bin/sphinx-build \
47-
-b html "docs/source" "docs/build/html" -j auto
48-
4930
build:
50-
make clean-build
51-
make clean-api
31+
make clean
5232
$(PYTHON) setup.py sdist
5333
$(PYTHON) setup.py bdist_wheel

compiler/api/compiler.py

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
import json
1920
import os
2021
import re
2122
import shutil
@@ -59,6 +60,16 @@
5960
namespaces_to_constructors = {}
6061
namespaces_to_functions = {}
6162

63+
try:
64+
with open("docs.json") as f:
65+
docs = json.load(f)
66+
except FileNotFoundError:
67+
docs = {
68+
"type": {},
69+
"constructor": {},
70+
"method": {}
71+
}
72+
6273

6374
class Combinator(NamedTuple):
6475
section: str
@@ -149,7 +160,7 @@ def remove_whitespaces(source: str) -> str:
149160
return "\n".join(lines)
150161

151162

152-
def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool = False):
163+
def get_docstring_arg_type(t: str):
153164
if t in CORE_TYPES:
154165
if t == "long":
155166
return "``int`` ``64-bit``"
@@ -167,9 +178,9 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool
167178
elif t == "TLObject" or t == "X":
168179
return "Any object from :obj:`~pyrogram.raw.types`"
169180
elif t == "!X":
170-
return "Any method from :obj:`~pyrogram.raw.functions`"
181+
return "Any function from :obj:`~pyrogram.raw.functions`"
171182
elif t.lower().startswith("vector"):
172-
return "List of " + get_docstring_arg_type(t.split("<", 1)[1][:-1], True)
183+
return "List of " + get_docstring_arg_type(t.split("<", 1)[1][:-1])
173184
else:
174185
return f":obj:`{t} <pyrogram.raw.base.{t}>`"
175186

@@ -183,10 +194,7 @@ def get_references(t: str, kind: str):
183194
raise ValueError("Invalid kind")
184195

185196
if t:
186-
return "\n ".join(
187-
f"- :obj:`{i} <pyrogram.raw.functions.{i}>`"
188-
for i in t
189-
), len(t)
197+
return "\n ".join(t), len(t)
190198

191199
return None, 0
192200

@@ -315,17 +323,33 @@ def start(format: bool = False):
315323

316324
constructors = sorted(types_to_constructors[qualtype])
317325
constr_count = len(constructors)
318-
items = "\n ".join([f"- :obj:`{c} <pyrogram.raw.types.{c}>`" for c in constructors])
326+
items = "\n ".join([f"{c}" for c in constructors])
327+
328+
type_docs = docs["type"].get(qualtype, None)
329+
330+
if type_docs:
331+
type_docs = type_docs["desc"]
332+
else:
333+
type_docs = "Telegram API base type."
319334

320-
docstring = f"This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n"
321-
docstring += f" Constructors:\n .. hlist::\n :columns: 2\n\n {items}"
335+
docstring = type_docs
336+
337+
docstring += f"\n\n Constructors:\n" \
338+
f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n" \
339+
f" .. currentmodule:: pyrogram.raw.types\n\n" \
340+
f" .. autosummary::\n" \
341+
f" :nosignatures:\n\n" \
342+
f" {items}"
322343

323344
references, ref_count = get_references(qualtype, "types")
324345

325346
if references:
326-
docstring += f"\n\n See Also:\n This object can be returned by " \
327-
f"{ref_count} method{'s' if ref_count > 1 else ''}:" \
328-
f"\n\n .. hlist::\n :columns: 2\n\n " + references
347+
docstring += f"\n\n Functions:\n This object can be returned by " \
348+
f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n" \
349+
f" .. currentmodule:: pyrogram.raw.functions\n\n" \
350+
f" .. autosummary::\n" \
351+
f" :nosignatures:\n\n" \
352+
f" " + references
329353

330354
with open(dir_path / f"{snake(module)}.py", "w") as f:
331355
f.write(
@@ -359,41 +383,67 @@ def start(format: bool = False):
359383
docstring = ""
360384
docstring_args = []
361385

386+
if c.section == "functions":
387+
combinator_docs = docs["method"]
388+
else:
389+
combinator_docs = docs["constructor"]
390+
362391
for i, arg in enumerate(sorted_args):
363392
arg_name, arg_type = arg
364393
is_optional = FLAGS_RE.match(arg_type)
365394
flag_number = is_optional.group(1) if is_optional else -1
366395
arg_type = arg_type.split("?")[-1]
367396

397+
arg_docs = combinator_docs.get(c.qualname, None)
398+
399+
if arg_docs:
400+
arg_docs = arg_docs["params"].get(arg_name, "N/A")
401+
else:
402+
arg_docs = "N/A"
403+
368404
docstring_args.append(
369-
"{}{}: {}".format(
405+
"{} ({}{}):\n {}\n".format(
370406
arg_name,
371-
" (optional)".format(flag_number) if is_optional else "",
372-
get_docstring_arg_type(arg_type, is_pyrogram_type=c.namespace == "pyrogram")
407+
get_docstring_arg_type(arg_type),
408+
", *optional*".format(flag_number) if is_optional else "",
409+
arg_docs
373410
)
374411
)
375412

376413
if c.section == "types":
377-
docstring += f"This object is a constructor of the base type :obj:`~pyrogram.raw.base.{c.qualtype}`.\n\n"
378-
else:
379-
docstring += f"Telegram API method.\n\n"
414+
constructor_docs = docs["constructor"].get(c.qualname, None)
380415

381-
docstring += f" Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n"
416+
if constructor_docs:
417+
constructor_docs = constructor_docs["desc"]
418+
else:
419+
constructor_docs = "Telegram API type."
382420

383-
if docstring_args:
384-
docstring += " Parameters:\n " + "\n ".join(docstring_args)
421+
docstring += constructor_docs + "\n"
422+
docstring += f"\n Constructor of :obj:`~pyrogram.raw.base.{c.qualtype}`."
385423
else:
386-
docstring += " **No parameters required.**"
424+
function_docs = docs["method"].get(c.qualname, None)
425+
426+
if function_docs:
427+
docstring += function_docs["desc"] + "\n"
428+
else:
429+
docstring += f"Telegram API function."
430+
431+
docstring += f"\n\n Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n"
432+
docstring += f" Parameters:\n " + \
433+
(f"\n ".join(docstring_args) if docstring_args else "No parameters required.\n")
387434

388435
if c.section == "functions":
389-
docstring += "\n\n Returns:\n " + get_docstring_arg_type(c.qualtype)
436+
docstring += "\n Returns:\n " + get_docstring_arg_type(c.qualtype)
390437
else:
391438
references, count = get_references(c.qualname, "constructors")
392439

393440
if references:
394-
docstring += f"\n\n See Also:\n This object can be returned by " \
395-
f"{count} method{'s' if count > 1 else ''}:" \
396-
f"\n\n .. hlist::\n :columns: 2\n\n " + references
441+
docstring += f"\n Functions:\n This object can be returned by " \
442+
f"{count} function{'s' if count > 1 else ''}.\n\n" \
443+
f" .. currentmodule:: pyrogram.raw.functions\n\n" \
444+
f" .. autosummary::\n" \
445+
f" :nosignatures:\n\n" \
446+
f" " + references
397447

398448
write_types = read_types = "" if c.has_flags else "# No flags\n "
399449

compiler/api/source/main_api.tl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ inputMediaVenue#c13d1c11 geo_point:InputGeoPoint title:string address:string pro
4646
inputMediaPhotoExternal#e5bbfe1a flags:# url:string ttl_seconds:flags.0?int = InputMedia;
4747
inputMediaDocumentExternal#fb52dc99 flags:# url:string ttl_seconds:flags.0?int = InputMedia;
4848
inputMediaGame#d33f43f3 id:InputGame = InputMedia;
49-
inputMediaInvoice#d9799874 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:flags.1?string = InputMedia;
49+
inputMediaInvoice#8eb5a6d5 flags:# title:string description:string photo:flags.0?InputWebDocument invoice:Invoice payload:bytes provider:string provider_data:DataJSON start_param:flags.1?string extended_media:flags.2?InputMedia = InputMedia;
5050
inputMediaGeoLive#971fa843 flags:# stopped:flags.0?true geo_point:InputGeoPoint heading:flags.2?int period:flags.1?int proximity_notification_radius:flags.3?int = InputMedia;
5151
inputMediaPoll#f94e5f1 flags:# poll:Poll correct_answers:flags.0?Vector<bytes> solution:flags.1?string solution_entities:flags.1?Vector<MessageEntity> = InputMedia;
5252
inputMediaDice#e66fbf7b emoticon:string = InputMedia;
@@ -132,7 +132,7 @@ messageMediaDocument#9cb070d7 flags:# nopremium:flags.3?true document:flags.0?Do
132132
messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia;
133133
messageMediaVenue#2ec0533f geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string = MessageMedia;
134134
messageMediaGame#fdb19008 game:Game = MessageMedia;
135-
messageMediaInvoice#84551347 flags:# shipping_address_requested:flags.1?true test:flags.3?true title:string description:string photo:flags.0?WebDocument receipt_msg_id:flags.2?int currency:string total_amount:long start_param:string = MessageMedia;
135+
messageMediaInvoice#f6a548d3 flags:# shipping_address_requested:flags.1?true test:flags.3?true title:string description:string photo:flags.0?WebDocument receipt_msg_id:flags.2?int currency:string total_amount:long start_param:string extended_media:flags.4?MessageExtendedMedia = MessageMedia;
136136
messageMediaGeoLive#b940c666 flags:# geo:GeoPoint heading:flags.0?int period:int proximity_notification_radius:flags.1?int = MessageMedia;
137137
messageMediaPoll#4bd6e798 poll:Poll results:PollResults = MessageMedia;
138138
messageMediaDice#3f7ee58b value:int emoticon:string = MessageMedia;
@@ -375,6 +375,7 @@ updateUserEmojiStatus#28373599 user_id:long emoji_status:EmojiStatus = Update;
375375
updateRecentEmojiStatuses#30f443db = Update;
376376
updateRecentReactions#6f7863f4 = Update;
377377
updateMoveStickerSetToTop#86fccf85 flags:# masks:flags.0?true emojis:flags.1?true stickerset:long = Update;
378+
updateMessageExtendedMedia#5a73a98c peer:Peer msg_id:int extended_media:MessageExtendedMedia = Update;
378379

379380
updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State;
380381

@@ -1422,6 +1423,9 @@ premiumSubscriptionOption#b6f11ebe flags:# current:flags.1?true can_purchase_upg
14221423

14231424
sendAsPeer#b81c7034 flags:# premium_required:flags.0?true peer:Peer = SendAsPeer;
14241425

1426+
messageExtendedMediaPreview#ad628cc8 flags:# w:flags.0?int h:flags.0?int thumb:flags.1?PhotoSize video_duration:flags.2?int = MessageExtendedMedia;
1427+
messageExtendedMedia#ee479c64 media:MessageMedia = MessageExtendedMedia;
1428+
14251429
---functions---
14261430

14271431
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@@ -1735,6 +1739,7 @@ messages.reportReaction#3f64c076 peer:InputPeer id:int reaction_peer:InputPeer =
17351739
messages.getTopReactions#bb8125ba limit:int hash:long = messages.Reactions;
17361740
messages.getRecentReactions#39461db2 limit:int hash:long = messages.Reactions;
17371741
messages.clearRecentReactions#9dfeefb4 = Bool;
1742+
messages.getExtendedMedia#84f80814 peer:InputPeer id:Vector<int> = Updates;
17381743

17391744
updates.getState#edd4882a = updates.State;
17401745
updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;
@@ -1897,4 +1902,4 @@ stats.getMegagroupStats#dcdf8607 flags:# dark:flags.0?true channel:InputChannel
18971902
stats.getMessagePublicForwards#5630281b channel:InputChannel msg_id:int offset_rate:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages;
18981903
stats.getMessageStats#b6e0a3f5 flags:# dark:flags.0?true channel:InputChannel msg_id:int = stats.MessageStats;
18991904

1900-
// LAYER 145
1905+
// LAYER 146

compiler/docs/template/bound-methods.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ some of the required arguments.
1919
2020
app.run()
2121
22-
.. contents:: Contents
23-
:backlinks: none
24-
:local:
25-
2622
-----
2723

2824
.. currentmodule:: pyrogram.types

compiler/docs/template/methods.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ the main package directly.
1414
with app:
1515
app.send_message("me", "hi")
1616
17-
.. contents:: Contents
18-
:backlinks: none
19-
:local:
20-
2117
-----
2218

2319
.. currentmodule:: pyrogram.Client

compiler/docs/template/toctree.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
.. module:: {module}
55

66
.. toctree::
7+
:titlesonly:
8+
79
{entities}

compiler/docs/template/types.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ are only returned by other methods. You also don't need to import them, unless y
1717

1818
To tell whether a field is set or not, do a simple boolean check: ``if message.photo: ...``.
1919

20-
.. contents:: Contents
21-
:backlinks: none
22-
:local:
23-
2420
-----
2521

2622
.. currentmodule:: pyrogram.types

docs/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/source/api/client.rst

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)