Show invalid bot methods in the docs

This commit is contained in:
Lonami Exo 2018-06-06 17:35:06 +02:00
parent c7d7977951
commit 4bdc28a775
3 changed files with 20 additions and 3 deletions

View File

@ -11,6 +11,7 @@ Extra supported commands are:
""" """
import itertools import itertools
import json
import os import os
import re import re
import shutil import shutil
@ -43,6 +44,8 @@ ERRORS_IN_JSON = os.path.join(GENERATOR_DIR, 'data', 'errors.json')
ERRORS_IN_DESC = os.path.join(GENERATOR_DIR, 'data', 'error_descriptions') ERRORS_IN_DESC = os.path.join(GENERATOR_DIR, 'data', 'error_descriptions')
ERRORS_OUT = os.path.join(LIBRARY_DIR, 'errors', 'rpc_error_list.py') ERRORS_OUT = os.path.join(LIBRARY_DIR, 'errors', 'rpc_error_list.py')
INVALID_BM_IN = os.path.join(GENERATOR_DIR, 'data', 'invalid_bot_methods.json')
TLOBJECT_IN_CORE_TL = os.path.join(GENERATOR_DIR, 'data', 'mtproto_api.tl') TLOBJECT_IN_CORE_TL = os.path.join(GENERATOR_DIR, 'data', 'mtproto_api.tl')
TLOBJECT_IN_TL = os.path.join(GENERATOR_DIR, 'data', 'telegram_api.tl') TLOBJECT_IN_TL = os.path.join(GENERATOR_DIR, 'data', 'telegram_api.tl')
TLOBJECT_OUT = os.path.join(LIBRARY_DIR, 'tl') TLOBJECT_OUT = os.path.join(LIBRARY_DIR, 'tl')
@ -57,11 +60,14 @@ def generate(which):
from telethon_generator.generators import\ from telethon_generator.generators import\
generate_errors, generate_tlobjects, generate_docs, clean_tlobjects generate_errors, generate_tlobjects, generate_docs, clean_tlobjects
with open(INVALID_BM_IN) as f:
ib = set(json.load(f))
layer = find_layer(TLOBJECT_IN_TL) layer = find_layer(TLOBJECT_IN_TL)
errors = list(parse_errors(ERRORS_IN_JSON, ERRORS_IN_DESC)) errors = list(parse_errors(ERRORS_IN_JSON, ERRORS_IN_DESC))
tlobjects = list(itertools.chain( tlobjects = list(itertools.chain(
parse_tl(TLOBJECT_IN_CORE_TL, layer=layer), parse_tl(TLOBJECT_IN_CORE_TL, layer=layer, invalid_bot_methods=ib),
parse_tl(TLOBJECT_IN_TL, layer=layer))) parse_tl(TLOBJECT_IN_TL, layer=layer, invalid_bot_methods=ib)))
if not which: if not which:
which.extend(('tl', 'errors')) which.extend(('tl', 'errors'))

View File

@ -266,6 +266,10 @@ def _write_html_pages(tlobjects, errors, layer, input_res, output_dir):
# Create the page title # Create the page title
docs.write_title(tlobject.class_name) docs.write_title(tlobject.class_name)
if tlobject.is_function:
docs.write_text('Bots <strong>can{}</strong> use this method.'
.format("" if tlobject.bot_usable else "'t"))
# Write the code definition for this TLObject # Write the code definition for this TLObject
docs.write_code(tlobject) docs.write_code(tlobject)
docs.write_copy_button('Copy import to the clipboard', docs.write_copy_button('Copy import to the clipboard',

View File

@ -44,6 +44,7 @@ class TLObject:
self.args = args self.args = args
self.result = result self.result = result
self.is_function = is_function self.is_function = is_function
self.bot_usable = None
self.id = None self.id = None
if object_id is None: if object_id is None:
self.id = self.infer_id() self.id = self.infer_id()
@ -252,8 +253,11 @@ def _from_line(line, is_function, layer):
) )
def parse_tl(file_path, layer, ignore_core=False): def parse_tl(file_path, layer, ignore_core=False, invalid_bot_methods=None):
"""This method yields TLObjects from a given .tl file.""" """This method yields TLObjects from a given .tl file."""
if invalid_bot_methods is None:
invalid_bot_methods = set()
with open(file_path, encoding='utf-8') as file: with open(file_path, encoding='utf-8') as file:
is_function = False is_function = False
for line in file: for line in file:
@ -274,6 +278,9 @@ def parse_tl(file_path, layer, ignore_core=False):
try: try:
result = _from_line(line, is_function, layer=layer) result = _from_line(line, is_function, layer=layer)
if not ignore_core or result.id not in CORE_TYPES: if not ignore_core or result.id not in CORE_TYPES:
result.bot_usable =\
result.fullname not in invalid_bot_methods
yield result yield result
except ValueError as e: except ValueError as e:
if 'vector#1cb5c415' not in str(e): if 'vector#1cb5c415' not in str(e):