1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-12-11 17:00:00 +01:00
MadelineProto/tools/layerdiff.php

123 lines
4.2 KiB
PHP
Raw Normal View History

2022-12-29 20:40:06 +01:00
<?php declare(strict_types=1);
2019-06-04 14:55:58 +02:00
2019-05-31 13:17:29 +02:00
use danog\MadelineProto\Logger;
2021-12-09 13:25:14 +01:00
use danog\MadelineProto\Settings\Logger as SettingsLogger;
use danog\MadelineProto\Settings\TLSchema;
2019-05-31 13:17:29 +02:00
use danog\MadelineProto\TL\TL;
use danog\MadelineProto\Tools;
2019-05-31 13:17:29 +02:00
/*
2020-02-17 14:13:46 +01:00
Copyright 2016-2020 Daniil Gentili
2019-05-31 13:17:29 +02:00
(https://daniil.it)
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/>.
*/
require 'vendor/autoload.php';
2021-12-09 13:25:14 +01:00
$logger = new Logger(new SettingsLogger);
2019-05-31 13:17:29 +02:00
2022-12-08 20:16:40 +01:00
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
2019-05-31 13:17:29 +02:00
if ($argc !== 3) {
die("Usage: {$argv[0]} layernumberold layernumbernew\n");
}
/**
2019-06-04 14:55:58 +02:00
* Get TL info of layer.
2019-05-31 13:17:29 +02:00
*
* @param int $layer Layer number
2019-06-04 14:55:58 +02:00
*
2023-08-13 15:47:21 +02:00
* @internal
*
2019-05-31 13:17:29 +02:00
* @return void
*/
function getTL($layer)
{
2023-02-07 16:38:36 +01:00
$layerFile = __DIR__."/../schemas/TL_telegram_v$layer.tl";
$layer = new TL();
$layer->init((new TLSchema)->setAPISchema($layerFile)->setSecretSchema(''));
2019-06-04 14:55:58 +02:00
2021-12-09 13:25:14 +01:00
return ['methods' => $layer->getMethods(), 'constructors' => $layer->getConstructors()];
2019-05-31 13:17:29 +02:00
}
2023-08-13 15:47:21 +02:00
/** @internal */
2019-05-31 13:17:29 +02:00
function getUrl($constructor, $type)
{
2023-07-20 22:14:25 +02:00
$orig = $constructor;
$constructor = Tools::markdownEscape($constructor);
2019-06-04 14:55:58 +02:00
2023-07-20 22:14:25 +02:00
return "[$constructor](https://docs.madelineproto.xyz/API_docs/$type/$orig.html)";
2019-05-31 13:17:29 +02:00
}
$old = getTL($argv[1]);
$new = getTL($argv[2]);
$res = '';
foreach (['methods', 'constructors'] as $type) {
$finder = $type === 'methods' ? 'findByMethod' : 'findByPredicate';
2019-05-31 13:17:29 +02:00
$key = $type === 'methods' ? 'method' : 'predicate';
// New constructors
2022-12-29 21:33:26 +01:00
$res .= "\n\nNew ".ucfirst($type).":\n";
2019-05-31 13:17:29 +02:00
foreach ($new[$type]->by_id as $constructor) {
$name = $constructor[$key];
if (!$old[$type]->$finder($name)) {
$name = getUrl($name, $type);
2022-10-08 14:10:04 +02:00
$res .= "- $name\n";
2019-05-31 13:17:29 +02:00
}
}
// Changed constructors
2022-12-29 21:33:26 +01:00
$res .= "\n\nChanged ".ucfirst($type).":\n";
2019-05-31 13:17:29 +02:00
foreach ($new[$type]->by_id as $constructor) {
$name = $constructor[$key];
if ($old[$type]->$finder($name)) {
2019-05-31 13:17:29 +02:00
$new_args = $constructor['params'];
$old_args = $old[$type]->$finder($name)['params'];
$final_new_args = [];
$final_old_args = [];
foreach ($new_args as $arg) {
$final_new_args[$arg['name']] = $arg['type'];
}
foreach ($old_args as $arg) {
$final_old_args[$arg['name']] = $arg['type'];
}
$url = getUrl($name, $type);
foreach ($final_new_args as $name => $ttype) {
2022-05-01 19:59:07 +02:00
if (!isset($final_old_args[$name]) && $name !== 'flags' && $name !== 'flags2') {
$name = Tools::markdownEscape($name);
2023-12-28 14:35:47 +01:00
$res .= "- Added $name param to $url\n";
2019-05-31 13:17:29 +02:00
}
}
foreach ($final_old_args as $name => $ttype) {
2022-05-01 19:59:07 +02:00
if (!isset($final_new_args[$name]) && $name !== 'flags' && $name !== 'flags2') {
$name = Tools::markdownEscape($name);
2023-12-28 14:35:47 +01:00
$res .= "- Removed $name param from $url\n";
2019-05-31 13:17:29 +02:00
}
}
}
}
// Deleted constructors
2022-12-29 21:33:26 +01:00
$res .= "\n\nDeleted ".ucfirst($type).":\n";
2019-05-31 13:17:29 +02:00
foreach ($old[$type]->by_id as $constructor) {
$name = $constructor[$key];
if (!$new[$type]->$finder($name)) {
$name = Tools::markdownEscape($name);
2022-10-08 14:10:04 +02:00
$res .= "- $name\n";
2019-05-31 13:17:29 +02:00
}
}
}
2023-07-20 22:14:25 +02:00
$bot = new \danog\MadelineProto\API('testing.madeline');
2021-12-09 13:25:14 +01:00
$bot->start();
2022-12-08 20:16:40 +01:00
foreach (explode("\n\n", $res) as $chunk) {
2022-12-29 21:33:26 +01:00
if (!$chunk || !trim(explode(':', $chunk)[1])) {
2021-12-09 13:25:14 +01:00
continue;
}
$bot->messages->sendMessage(['peer' => 'danogentili', 'message' => $chunk, 'parse_mode' => 'markdown']);
}