1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 10:19:00 +01:00
MadelineProto/tools/DocsBuilder/Methods.php

316 lines
18 KiB
PHP
Raw Normal View History

2022-12-30 21:54:44 +01:00
<?php
declare(strict_types=1);
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
/**
* Methods module.
*
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <daniil@daniil.it>
2023-01-04 12:43:01 +01:00
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
2019-10-31 15:07:35 +01:00
* @link https://docs.madelineproto.xyz MadelineProto documentation
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
*/
2018-02-24 17:54:39 +01:00
2017-08-18 18:10:30 +02:00
namespace danog\MadelineProto\DocsBuilder;
2023-06-13 21:30:02 +02:00
use AssertionError;
use danog\MadelineProto\API;
2022-12-30 19:21:36 +01:00
use danog\MadelineProto\Lang;
use danog\MadelineProto\Logger;
2020-06-16 17:52:55 +02:00
use danog\MadelineProto\StrTools;
2019-10-31 15:06:25 +01:00
use danog\MadelineProto\Tools;
2023-06-13 21:30:02 +02:00
use danog\PhpDoc\PhpDoc;
use danog\PhpDoc\PhpDoc\MethodDoc;
use ReflectionClass;
use ReflectionMethod;
2019-10-31 15:06:25 +01:00
2022-12-30 19:21:36 +01:00
use const PHP_EOL;
2023-02-16 18:38:47 +01:00
/**
2023-07-21 17:46:36 +02:00
* @internal This garbage code needs to be thrown away completely and rewritten from scratch.
2023-02-16 18:38:47 +01:00
*/
2017-08-18 18:10:30 +02:00
trait Methods
{
2023-01-15 11:21:57 +01:00
private array $docs_methods;
private array $human_docs_methods;
2020-10-01 21:03:25 +02:00
public function mkMethods(): void
2017-08-18 18:11:04 +02:00
{
2019-06-29 14:54:12 +02:00
static $bots;
2019-09-02 17:08:36 +02:00
if (!$bots) {
2023-10-01 20:05:04 +02:00
$bots = json_decode(file_get_contents('https://raw.githubusercontent.com/danog/rpc-db/master/bot.json'), true)['result'];
2019-09-02 17:08:36 +02:00
}
2019-06-29 14:54:12 +02:00
static $errors;
2019-09-02 17:08:36 +02:00
if (!$errors) {
2023-10-01 20:05:04 +02:00
$errors = json_decode(file_get_contents('https://rpc.madelineproto.xyz/v4.json'), true);
2019-09-02 17:08:36 +02:00
}
2019-06-29 14:54:12 +02:00
$new = ['result' => []];
foreach ($errors['result'] as $code => $suberrors) {
foreach ($suberrors as $method => $suberrors) {
2022-05-01 20:17:16 +02:00
if (!isset($new[$method])) {
$new[$method] = [];
2019-06-29 14:54:12 +02:00
}
foreach ($suberrors as $error) {
$new['result'][$method][] = [$error, $code];
}
}
}
2023-10-01 20:05:04 +02:00
foreach (glob('methods/'.$this->any) as $unlink) {
unlink($unlink);
2017-08-18 18:10:30 +02:00
}
2023-10-01 20:05:04 +02:00
if (file_exists('methods')) {
rmdir('methods');
2017-08-18 18:10:30 +02:00
}
2023-10-01 20:05:04 +02:00
mkdir('methods');
2017-08-18 18:10:30 +02:00
$this->docs_methods = [];
2018-03-23 17:44:33 +01:00
$this->human_docs_methods = [];
2022-12-30 19:21:36 +01:00
$this->logger->logger('Generating methods documentation...', Logger::NOTICE);
2023-08-05 20:53:57 +02:00
foreach ($this->TL->getMethods()->by_id as $id => $data) {
2023-09-28 15:55:32 +02:00
if ($data['type'] === 'Vector t') {
$data['type'] = "Vector<{$data['subtype']}>";
}
$method = $data['method'];
2020-06-16 17:52:55 +02:00
$phpMethod = StrTools::methodEscape($method);
2023-10-01 20:05:04 +02:00
$type = str_replace(['<', '>'], ['_of_', ''], $data['type']);
$php_type = preg_replace('/.*_of_/', '', $type);
2017-08-18 18:10:30 +02:00
if (!isset($this->types[$php_type])) {
$this->types[$php_type] = ['methods' => [], 'constructors' => []];
}
2023-06-28 15:50:38 +02:00
if (!\in_array($data, $this->types[$php_type]['methods'], true)) {
2017-08-18 18:10:30 +02:00
$this->types[$php_type]['methods'][] = $data;
}
$params = '';
foreach ($data['params'] as $param) {
2023-06-28 15:50:38 +02:00
if (\in_array($param['name'], ['flags', 'flags2', 'random_id', 'random_bytes'], true)) {
2017-08-18 18:10:30 +02:00
continue;
}
2017-09-28 19:38:43 +02:00
if ($param['name'] === 'data' && $type === 'messages_SentEncryptedMessage' && !isset($this->settings['td'])) {
2017-08-18 18:10:30 +02:00
$param['name'] = 'message';
$param['type'] = 'DecryptedMessage';
}
2020-06-16 17:52:55 +02:00
if ($param['name'] === 'chat_id' && $method !== 'messages.discardEncryption' && !isset($this->settings['td'])) {
2017-08-18 18:10:30 +02:00
$param['type'] = 'InputPeer';
}
$type_or_subtype = isset($param['subtype']) ? 'subtype' : 'type';
2023-10-01 20:05:04 +02:00
$type_or_bare_type = ctype_upper(Tools::end(explode('.', $param[$type_or_subtype]))[0]) || \in_array($param[$type_or_subtype], ['!X', 'X', 'bytes', 'true', 'false', 'double', 'string', 'Bool', 'int', 'long', 'int128', 'int256', 'int512', 'int53'], true) ? 'types' : 'constructors';
$param[$type_or_subtype] = str_replace(['true', 'false'], ['Bool', 'Bool'], $param[$type_or_subtype]);
2023-07-16 13:43:55 +02:00
$param[$type_or_subtype] = '['.self::markdownEscape($param[$type_or_subtype]).'](/API_docs/'.$type_or_bare_type.'/'.$param[$type_or_subtype].'.md)';
2023-06-24 18:25:26 +02:00
$param[$type_or_subtype] = '$'.$param[$type_or_subtype];
2023-01-04 15:13:55 +01:00
$params .= $param['name'].': '.(isset($param['subtype']) ? '\\['.$param[$type_or_subtype].'\\]' : $param[$type_or_subtype]).', ';
2017-08-18 18:10:30 +02:00
}
2020-10-03 15:36:03 +02:00
if (!isset($this->tdDescriptions['methods'][$method])) {
2020-06-16 17:52:55 +02:00
$this->addToLang('method_'.$method);
2022-12-30 19:21:36 +01:00
if (Lang::$lang['en']['method_'.$method] !== '') {
$this->tdDescriptions['methods'][$method]['description'] = Lang::$lang['en']['method_'.$method];
}
}
2022-05-01 20:17:16 +02:00
$md_method = '['.$phpMethod.'](/API_docs/methods/'.$method.'.md)';
2023-07-16 13:43:55 +02:00
$this->docs_methods[$method] = '$MadelineProto->'.$md_method.'(\\['.$params.'\\]) === [$'.self::markdownEscape($type).'](/API_docs/types/'.$php_type.'.md)<a name="'.$method.'"></a>
2018-03-23 17:44:33 +01:00
2017-08-18 18:10:30 +02:00
';
2023-10-01 20:05:04 +02:00
$desc = StrTools::toString(trim(explode("\n", $this->tdDescriptions['methods'][$method]['description'] ?? '')[0], '.'));
2023-07-21 19:21:34 +02:00
if ($desc !== '') {
$desc .= ': ';
}
$this->human_docs_methods[$desc.$method] = '* <a href="'.$method.'.html" name="'.$method.'">'.$desc.$method.'</a>
2019-09-04 18:33:27 +02:00
';
2017-08-18 18:10:30 +02:00
$params = '';
$lua_params = '';
$pwr_params = '';
$json_params = '';
$table = empty($data['params']) ? '' : '### Parameters:
| Name | Type | Required |
2017-08-20 11:05:56 +02:00
|----------|---------------|----------|
2017-08-18 18:10:30 +02:00
';
2020-10-03 15:36:03 +02:00
if (isset($this->tdDescriptions['methods'][$method]) && !empty($data['params'])) {
$table = '### Parameters:
2017-08-18 18:10:30 +02:00
2018-08-29 11:25:49 +02:00
| Name | Type | Description | Required |
|----------|---------------|-------------|----------|
2017-08-18 18:10:30 +02:00
';
}
$hasentities = false;
$hasreplymarkup = false;
$hasmessage = false;
foreach ($data['params'] as $param) {
2023-06-28 15:50:38 +02:00
if (\in_array($param['name'], ['flags', 'flags2', 'random_id', 'random_bytes'], true)) {
2017-08-18 18:10:30 +02:00
continue;
}
2017-09-28 19:38:43 +02:00
if ($param['name'] === 'data' && $type === 'messages_SentEncryptedMessage' && !isset($this->settings['td'])) {
2017-08-18 18:10:30 +02:00
$param['name'] = 'message';
$param['type'] = 'DecryptedMessage';
}
2020-06-16 17:52:55 +02:00
if ($param['name'] === 'chat_id' && $method !== 'messages.discardEncryption' && !isset($this->settings['td'])) {
2017-08-18 18:10:30 +02:00
$param['type'] = 'InputPeer';
}
if (!isset($this->tdDescriptions['methods'][$method]['params'][$param['name']])) {
if (isset($this->tdDescriptions['methods'][$method]['description'])) {
2022-12-30 19:21:36 +01:00
$this->tdDescriptions['methods'][$method]['params'][$param['name']] = Lang::$lang['en']['method_'.$method.'_param_'.$param['name'].'_type_'.$param['type']] ?? '';
}
}
if ($param['name'] === 'hash' && ($param['type'] === 'long' || $param['type'] === 'int')) {
2018-08-29 17:16:38 +02:00
$param['pow'] = 'hi';
$param['type'] = 'Vector t';
$param['subtype'] = 'long';
2018-08-29 17:16:38 +02:00
}
$ptype = $param[$type_or_subtype = isset($param['subtype']) ? 'subtype' : 'type'];
2017-08-18 18:10:30 +02:00
switch ($ptype) {
case 'true':
case 'false':
$ptype = 'Bool';
}
2018-03-27 14:41:50 +02:00
$human_ptype = $ptype;
if (\in_array($ptype, ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputPeer'], true) && !isset($this->settings['td'])) {
2020-04-05 22:22:47 +02:00
$human_ptype = 'Username, chat ID, Update, Message or '.$ptype;
}
2023-06-28 15:50:38 +02:00
if (\in_array($ptype, ['InputMedia', 'InputPhoto', 'InputDocument'], true) && !isset($this->settings['td'])) {
2020-04-05 22:22:47 +02:00
$human_ptype = 'MessageMedia, Update, Message or '.$ptype;
}
2023-06-28 15:50:38 +02:00
if (\in_array($ptype, ['InputMessage'], true) && !isset($this->settings['td'])) {
2020-04-05 22:22:47 +02:00
$human_ptype = 'Message ID or '.$ptype;
}
2023-06-28 15:50:38 +02:00
if (\in_array($ptype, ['InputEncryptedChat'], true) && !isset($this->settings['td'])) {
2020-04-05 22:22:47 +02:00
$human_ptype = 'Secret chat ID, Update, EncryptedMessage or '.$ptype;
}
2023-06-28 15:50:38 +02:00
if (\in_array($ptype, ['InputFile'], true) && !isset($this->settings['td'])) {
2020-04-05 22:22:47 +02:00
$human_ptype = 'File path or '.$ptype;
}
2023-06-28 15:50:38 +02:00
if (\in_array($ptype, ['InputEncryptedFile'], true) && !isset($this->settings['td'])) {
2020-04-05 22:22:47 +02:00
$human_ptype = 'File path or '.$ptype;
}
2023-10-01 20:05:04 +02:00
$type_or_bare_type = ctype_upper(Tools::end(explode('.', $param[$type_or_subtype]))[0]) || \in_array($param[$type_or_subtype], ['!X', 'X', 'bytes', 'true', 'false', 'double', 'string', 'Bool', 'int', 'long', 'int128', 'int256', 'int512', 'int53'], true) ? 'types' : 'constructors';
2020-10-03 15:36:03 +02:00
if (isset($this->tdDescriptions['methods'][$method])) {
2023-12-18 20:29:32 +01:00
$table .= '|'.self::markdownEscape($param['name']).'|'.(isset($param['subtype']) ? 'Array of ' : '').'['.self::markdownEscape($human_ptype).'](/API_docs/'.$type_or_bare_type.'/'.$ptype.'.md) | '.$this->tdDescriptions['methods'][$method]['params'][$param['name']].' | '.(isset($param['pow']) || $param['type'] === 'int' || $param['type'] === 'string' || $param['type'] === 'double' || ($id = $this->TL->getConstructors()->findByPredicate(lcfirst($param['type']).'Empty')) && $id['type'] === $param['type'] || ($id = $this->TL->getConstructors()->findByPredicate('input'.$param['type'].'Empty')) && $id['type'] === $param['type'] ? 'Optional' : 'Yes').'|';
2018-08-29 11:25:49 +02:00
} else {
2023-12-18 20:29:32 +01:00
$table .= '|'.self::markdownEscape($param['name']).'|'.(isset($param['subtype']) ? 'Array of ' : '').'['.self::markdownEscape($human_ptype).'](/API_docs/'.$type_or_bare_type.'/'.$ptype.'.md) | '.(isset($param['pow']) || $param['type'] === 'int' || $param['type'] === 'string' || ($param['type'] === 'long' && $param['name'] === 'hash')|| ($id = $this->TL->getConstructors()->findByPredicate(lcfirst($param['type']).'Empty')) && $id['type'] === $param['type'] || ($id = $this->TL->getConstructors()->findByPredicate('input'.$param['type'].'Empty')) && $id['type'] === $param['type'] ? 'Optional' : 'Yes').'|';
2017-08-18 18:10:30 +02:00
}
$table .= PHP_EOL;
2023-06-28 15:50:38 +02:00
$pptype = \in_array($ptype, ['string', 'bytes'], true) ? "'".$ptype."'" : '$'.$ptype;
$ppptype = \in_array($ptype, ['string'], true) ? '"'.$ptype.'"' : $ptype;
$ppptype = \in_array($ptype, ['bytes'], true) ? '{"_": "bytes", "bytes":"base64 encoded '.$ptype.'"}' : $ppptype;
2023-01-04 15:13:55 +01:00
$params .= $param['name'].': ';
2020-04-05 22:22:47 +02:00
$params .= (isset($param['subtype']) ? '['.$pptype.', '.$pptype.']' : $pptype).', ';
$json_params .= '"'.$param['name'].'": '.(isset($param['subtype']) ? '['.$ppptype.']' : $ppptype).', ';
$pwr_params .= $param['name'].' - Json encoded '.(isset($param['subtype']) ? ' array of '.$ptype : $ptype)."\n\n";
$lua_params .= $param['name'].'=';
$lua_params .= (isset($param['subtype']) ? '{'.$pptype.'}' : $pptype).', ';
2017-08-18 18:10:30 +02:00
if ($param['name'] === 'reply_markup') {
$hasreplymarkup = true;
}
if ($param['name'] === 'message') {
$hasmessage = true;
}
if ($param['name'] === 'entities') {
$hasentities = true;
2022-05-01 20:17:16 +02:00
$table .= '|parse\\_mode| [string](/API_docs/types/string.md) | Whether to parse HTML or Markdown markup in the message| Optional |
2017-08-18 18:10:30 +02:00
';
2022-05-11 20:35:26 +02:00
$params .= "parse_mode: 'string', ";
$lua_params .= "parseMode='string', ";
$json_params .= '"parseMode": "string"';
$pwr_params = "parseMode - string\n";
2017-08-18 18:10:30 +02:00
}
}
2020-10-03 15:36:03 +02:00
$description = isset($this->tdDescriptions['methods'][$method]) ? $this->tdDescriptions['methods'][$method]['description'] : $method.' parameters, return type and example';
2023-10-01 20:05:04 +02:00
$symFile = str_replace('.', '_', $method);
2020-01-31 19:29:43 +01:00
$redir = $symFile !== $method ? "\nredirect_from: /API_docs/methods/{$symFile}.html" : '';
2023-10-01 20:05:04 +02:00
$description = str_replace('"', "'", rtrim(explode("\n", $description)[0], ':'));
2023-07-16 13:43:55 +02:00
$header = $this->template('Method', $method, $description, $redir, self::markdownEscape($method));
2017-08-18 18:10:30 +02:00
if ($this->td) {
2020-06-16 17:52:55 +02:00
$header .= "YOU CANNOT USE THIS METHOD IN MADELINEPROTO\n\n\n\n\n";
2017-08-18 18:10:30 +02:00
}
2023-06-28 15:50:38 +02:00
if (\in_array($method, ['messages.getHistory', 'messages.getMessages', 'channels.getMessages'], true)) {
2023-08-31 18:50:48 +02:00
$header .= "# Warning: flood wait\n**Warning: this method is prone to rate limiting with flood waits, **which can lead to !!! ACCOUNT BANS !!!**, please use the [updates event handler, instead (which is 100% safe) &raquo;](/docs/UPDATES.html#async-event-driven)**\n\n";
2022-10-31 18:49:17 +01:00
$header .= "# Warning: non-realtime results\n**Warning: this method is not suitable for receiving messages in real-time from chats and users, please use the [updates event handler, instead &raquo;](/docs/UPDATES.html#async-event-driven)**\n\n";
$header .= "# Warning: this is probably NOT what you need\nYou probably need to use the [updates event handler, instead &raquo;](/docs/UPDATES.html#async-event-driven) :)\n\n";
2022-08-25 18:21:33 +02:00
}
if (\in_array($method, ['updates.getDifference', 'updates.getState', 'updates.getChannelDifference'], true)) {
$header .= "# Warning: this is a low-level, complex method that **must never** be used directly.\nThe [event handler](https://docs.madelineproto.xyz/docs/UPDATES.html) provides a high-level abstraction that **must** be used instead of this method to fetch updates.\nIf you want to fetch all users of a bot using a bot token, use [getDialogIds](https://docs.madelineproto.xyz/docs/DIALOGS.html) or the high-level [broadcast API](https://docs.madelineproto.xyz/docs/BROADCAST.html), instead.\n\n";
}
2020-10-03 15:36:03 +02:00
$header .= isset($this->tdDescriptions['methods'][$method]) ? $this->tdDescriptions['methods'][$method]['description'].PHP_EOL.PHP_EOL : '';
2017-08-18 18:10:30 +02:00
$table .= '
';
2023-07-16 13:43:55 +02:00
$return = '### Return type: ['.self::markdownEscape($type).'](/API_docs/types/'.$php_type.'.md)
2017-08-18 18:10:30 +02:00
';
2023-06-28 15:50:38 +02:00
$bot = !\in_array($method, $bots, true);
2017-08-25 14:43:29 +02:00
$example = '';
if (!isset($this->settings['td'])) {
2020-04-05 22:22:47 +02:00
$example .= '### Can bots use this method: **'.($bot ? 'YES' : 'NO')."**\n\n\n";
2023-10-01 20:05:04 +02:00
$example .= str_replace('[]', '', $this->template('method-example', str_replace('.', '_', $type), $phpMethod, $params, $method, $lua_params));
2017-08-25 14:43:50 +02:00
if ($hasreplymarkup) {
2020-06-16 17:52:55 +02:00
$example .= $this->template('reply_markup');
2017-08-25 14:43:50 +02:00
}
if ($hasmessage) {
2023-07-16 13:43:55 +02:00
$example .= $this->template('chunks', self::markdownEscape($type), $php_type);
2017-08-25 14:43:50 +02:00
}
if ($hasentities) {
2020-06-16 17:52:55 +02:00
$example .= $this->template('parse_mode');
2017-08-25 14:43:50 +02:00
}
2020-06-16 17:52:55 +02:00
if (isset($new['result'][$method])) {
2019-06-29 14:54:12 +02:00
$example .= '### Errors
2018-03-27 14:41:50 +02:00
2019-06-29 14:54:12 +02:00
| Code | Type | Description |
|------|----------|---------------|
2018-03-27 14:41:50 +02:00
';
2020-06-16 17:52:55 +02:00
foreach ($new['result'][$method] as $error) {
2019-06-29 14:54:12 +02:00
[$error, $code] = $error;
2020-04-05 22:22:47 +02:00
$example .= "|{$code}|{$error}|".$errors['human_result'][$error][0].'|'."\n";
2018-03-27 14:41:50 +02:00
}
$example .= "\n\n";
}
2017-08-25 14:43:50 +02:00
}
2023-10-01 20:05:04 +02:00
file_put_contents('methods/'.$method.'.md', $header.$table.$return.$example);
2017-08-18 18:10:30 +02:00
}
2022-12-30 19:21:36 +01:00
$this->logger->logger('Generating methods index...', Logger::NOTICE);
2023-06-13 21:30:02 +02:00
$reflection = new ReflectionClass(API::class);
2023-08-05 20:53:57 +02:00
/** @psalm-suppress UndefinedClass */
2023-06-13 21:30:02 +02:00
$phpdoc = PhpDoc::fromNamespace(\danog\MadelineProto::class);
$phpdoc->resolveAliases();
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
$name = $method->getName();
2023-10-01 20:05:04 +02:00
if (\in_array(strtolower($name), ['update2fa', 'getdialogids', 'getdialogs', 'getfulldialogs', 'getpwrchat', 'getfullinfo', 'getinfo', 'getid', 'getself', '__magic_construct', '__construct', '__destruct', '__sleep', '__wakeup'], true)) {
2023-06-13 21:30:02 +02:00
continue;
}
$doc = $method->getDocComment();
2023-10-01 20:05:04 +02:00
if (str_contains($doc, '@internal') || str_contains($doc, '@deprecated')) {
2023-06-13 21:30:02 +02:00
continue;
}
if ($doc) {
2024-04-06 19:21:12 +02:00
$doc = getSummary($doc);
2023-06-13 21:30:02 +02:00
}
if (!$doc) {
throw new AssertionError($name);
}
2023-10-01 20:05:04 +02:00
$doc = trim($doc, '.');
2023-06-13 21:30:02 +02:00
$method = new MethodDoc($phpdoc, $method);
$anchor = $method->getSignatureAnchor();
$this->human_docs_methods["$doc: $name"] = '* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#'.$anchor.'" name="'.$name.'">'.$doc.': '.$name.'</a>
';
}
2023-10-01 20:05:04 +02:00
ksort($this->docs_methods);
ksort($this->human_docs_methods);
2017-08-18 18:10:30 +02:00
$last_namespace = '';
foreach ($this->docs_methods as $method => &$value) {
2023-10-01 20:05:04 +02:00
$new_namespace = preg_replace('/_.*/', '', $method);
2017-08-18 18:10:30 +02:00
$br = $new_namespace != $last_namespace ? '***
2018-03-23 17:59:56 +01:00
<br><br>
' : '';
2020-04-05 22:22:47 +02:00
$value = $br.$value;
2018-03-23 17:44:33 +01:00
$last_namespace = $new_namespace;
}
2023-10-01 20:05:04 +02:00
file_put_contents('methods/api_'.$this->index, $this->template('methods-api-index', $this->index, implode('', $this->docs_methods)));
file_put_contents('methods/'.$this->index, $this->template('methods-index', $this->index, implode('', $this->human_docs_methods)));
2017-08-18 18:10:30 +02:00
}
2018-02-24 17:54:39 +01:00
}