Skip to content

Commit e81ecc8

Browse files
committed
Start cleaning up repo
1 parent 579dfe3 commit e81ecc8

20 files changed

Lines changed: 156 additions & 547 deletions

‎.gitmodules‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "docs"]
22
path = docs
33
url = https://github.com/danog/MadelineProtoDocs
4+
[submodule "userbots/magnaluna"]
5+
path = userbots/magnaluna
6+
url = https://github.com/danog/magnaluna

‎.php_cs.dist‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $config->getFinder()
55
->in(__DIR__ . '/src')
66
->in(__DIR__ . '/tests')
77
->in(__DIR__ . '/userbots')
8-
->name(__DIR__ . '/*.php');
8+
->in(__DIR__);
99

1010
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
1111

‎asyncify.php‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@
22

33
$not_subbing = [];
44

5-
foreach (explode("\n", shell_exec("find src -type f -name '*.php'")) as $file) {
5+
foreach (\explode("\n", \shell_exec("find src -type f -name '*.php'")) as $file) {
66
if (!$file) {
77
continue;
88
}
9-
if (in_array(basename($file, '.php'), ['APIFactory', 'API', 'Connection', 'Coroutine', 'ReferenceDatabase', 'ProxySocketPool'])) {
9+
if (\in_array(\basename($file, '.php'), ['APIFactory', 'API', 'Connection', 'Coroutine', 'ReferenceDatabase', 'ProxySocketPool'])) {
1010
continue;
1111
}
12-
if (strpos($file, 'Loop/')) {
12+
if (\strpos($file, 'Loop/')) {
1313
continue;
1414
}
15-
if (strpos($file, 'Stream/')) {
15+
if (\strpos($file, 'Stream/')) {
1616
continue;
1717
}
18-
if (strpos($file, 'Server/')) {
18+
if (\strpos($file, 'Server/')) {
1919
continue;
2020
}
21-
if (strpos($file, 'Async/')) {
21+
if (\strpos($file, 'Async/')) {
2222
continue;
2323
}
2424
$to_sub = [];
2525
$last_match = null;
26-
foreach (explode("\n", $filec = file_get_contents($file)) as $number => $line) {
27-
if (preg_match("/public function (\w*)[(]/", $line, $matches)) {
28-
$last_match = stripos($matches[1], 'async') === false ? $matches[1] : null;
26+
foreach (\explode("\n", $filec = \file_get_contents($file)) as $number => $line) {
27+
if (\preg_match("/public function (\w*)[(]/", $line, $matches)) {
28+
$last_match = \stripos($matches[1], 'async') === false ? $matches[1] : null;
2929
}
30-
if (preg_match('/function [(]/', $line) && stripos($line, 'public function') === false) {
30+
if (\preg_match('/function [(]/', $line) && \stripos($line, 'public function') === false) {
3131
$last_match = 0;
3232
}
33-
if (strpos($line, 'yield') !== false) {
33+
if (\strpos($line, 'yield') !== false) {
3434
if ($last_match) {
3535
echo "subbing $last_match for $line at $number in $file".PHP_EOL;
3636
$to_sub[] = $last_match;
@@ -47,7 +47,7 @@
4747
$output[] = "public function $func".'_async(';
4848
}
4949
if ($input) {
50-
file_put_contents($file, str_replace($input, $output, $filec));
50+
\file_put_contents($file, \str_replace($input, $output, $filec));
5151
}
5252
}
53-
var_dump(array_values($not_subbing));
53+
\var_dump(\array_values($not_subbing));

‎bot.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
If not, see <http://www.gnu.org/licenses/>.
1414
*/
1515

16-
use danog\MadelineProto\Stream\Proxy\SocksProxy;
1716

1817
\set_include_path(\get_include_path().':'.\realpath(\dirname(__FILE__).'/MadelineProto/'));
1918

‎build_docs.php‎

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
\danog\MadelineProto\Logger::constructor($param);
1616
$logger = \danog\MadelineProto\Logger::$default;
1717

18-
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
18+
\set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
1919

2020
\danog\MadelineProto\Logger::log('Copying readme...', \danog\MadelineProto\Logger::NOTICE);
2121

22-
file_put_contents('docs/docs/index.md', '---
22+
\file_put_contents('docs/docs/index.md', '---
2323
title: MadelineProto documentation
2424
description: PHP client/server for the telegram MTProto protocol (a better tg-cli)
2525
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
2626
---
27-
'.str_replace('<img', '<amp-img', file_get_contents('README.md')));
27+
'.\str_replace('<img', '<amp-img', \file_get_contents('README.md')));
2828

2929
$docs = [
3030
/* [
@@ -52,8 +52,8 @@
5252
];
5353

5454
$layer_list = '';
55-
foreach (array_slice(glob(__DIR__.'/src/danog/MadelineProto/TL_telegram_*'), 0, -1) as $file) {
56-
$layer = preg_replace(['/.*telegram_/', '/\..+/'], '', $file);
55+
foreach (\array_slice(\glob(__DIR__.'/src/danog/MadelineProto/TL_telegram_*'), 0, -1) as $file) {
56+
$layer = \preg_replace(['/.*telegram_/', '/\..+/'], '', $file);
5757
$docs[] = [
5858
'tl_schema' => ['telegram' => $file],
5959
'title' => 'MadelineProto API documentation (layer '.$layer.')',
@@ -65,7 +65,7 @@
6565
';
6666
}
6767

68-
file_put_contents('docs/old_docs/README.md', '---
68+
\file_put_contents('docs/old_docs/README.md', '---
6969
title: Documentations of old mtproto layers
7070
description: Documentation of old mtproto layers
7171
---
@@ -81,7 +81,7 @@
8181
$doc->mk_docs();
8282
}
8383

84-
chdir(__DIR__);
84+
\chdir(__DIR__);
8585

8686
$orderedfiles = [];
8787
$order = [
@@ -110,76 +110,78 @@
110110
'TEMPLATES',
111111
];
112112
$index = '';
113-
$files = glob('docs/docs/docs/*md');
113+
$files = \glob('docs/docs/docs/*md');
114114
foreach ($files as $file) {
115-
$base = basename($file, '.md');
116-
if ($base === 'UPDATES_INTERNAL') continue;
117-
$key = array_search($base, $order);
115+
$base = \basename($file, '.md');
116+
if ($base === 'UPDATES_INTERNAL') {
117+
continue;
118+
}
119+
$key = \array_search($base, $order);
118120
if ($key !== false) {
119121
$orderedfiles[$key] = $file;
120122
}
121123
}
122-
ksort($orderedfiles);
124+
\ksort($orderedfiles);
123125
foreach ($orderedfiles as $key => $filename) {
124-
$lines = explode("\n", file_get_contents($filename));
125-
while (end($lines) === '' || strpos(end($lines), 'Next')) {
126-
unset($lines[count($lines) - 1]);
126+
$lines = \explode("\n", \file_get_contents($filename));
127+
while (\end($lines) === '' || \strpos(\end($lines), 'Next')) {
128+
unset($lines[\count($lines) - 1]);
127129
}
128130
if ($lines[0] === '---') {
129-
array_shift($lines);
131+
\array_shift($lines);
130132
while ($lines[0] !== '---') {
131-
array_shift($lines);
133+
\array_shift($lines);
132134
}
133-
array_shift($lines);
135+
\array_shift($lines);
134136
}
135-
preg_match('|^# (.*)|', $lines[0], $matches);
137+
\preg_match('|^# (.*)|', $lines[0], $matches);
136138
$title = $matches[1];
137139
$description = $lines[2];
138140

139-
array_unshift($lines, '---', 'title: '.$title, 'description: '.$description, 'image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png', '---');
141+
\array_unshift($lines, '---', 'title: '.$title, 'description: '.$description, 'image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png', '---');
140142

141143
if (isset($orderedfiles[$key + 1])) {
142-
$nextfile = 'https://docs.madelineproto.xyz/docs/'.basename($orderedfiles[$key + 1], '.md').'.html';
143-
$prevfile = $key === 0 ? 'https://docs.madelineproto.xyz' : 'https://docs.madelineproto.xyz/docs/'.basename($orderedfiles[$key - 1], '.md').'.html';
144-
$lines[count($lines)] = "\n<a href=\"$nextfile\">Next section</a>";
144+
$nextfile = 'https://docs.madelineproto.xyz/docs/'.\basename($orderedfiles[$key + 1], '.md').'.html';
145+
$prevfile = $key === 0 ? 'https://docs.madelineproto.xyz' : 'https://docs.madelineproto.xyz/docs/'.\basename($orderedfiles[$key - 1], '.md').'.html';
146+
$lines[\count($lines)] = "\n<a href=\"$nextfile\">Next section</a>";
145147
} else {
146-
$lines[count($lines)] = "\n<a href=\"https://docs.madelineproto.xyz/#very-complex-and-complete-examples\">Next section</a>";
148+
$lines[\count($lines)] = "\n<a href=\"https://docs.madelineproto.xyz/#very-complex-and-complete-examples\">Next section</a>";
147149
}
148-
file_put_contents($filename, implode("\n", $lines));
150+
\file_put_contents($filename, \implode("\n", $lines));
149151

150-
$file = file_get_contents($filename);
152+
$file = \file_get_contents($filename);
151153

152-
preg_match_all('|( *)\* \[(.*)\]\((.*)\)|', $file, $matches);
153-
$file = 'https://docs.madelineproto.xyz/docs/'.basename($filename, '.md').'.html';
154+
\preg_match_all('|( *)\* \[(.*)\]\((.*)\)|', $file, $matches);
155+
$file = 'https://docs.madelineproto.xyz/docs/'.\basename($filename, '.md').'.html';
154156
$index .= "* [$title]($file)\n";
155-
if (basename($filename) !== 'FEATURES.md') {
157+
if (\basename($filename) !== 'FEATURES.md') {
156158
foreach ($matches[1] as $key => $match) {
157159
$spaces = " $match";
158160
$name = $matches[2][$key];
159161
$url = $matches[3][$key][0] === '#' ? $file.$matches[3][$key] : $matches[3][$key];
160162
$index .= "$spaces* [$name]($url)\n";
161163
if ($name === 'FULL API Documentation with descriptions') {
162164
$spaces .= ' ';
163-
preg_match_all('|\* (.*)|', file_get_contents('docs/docs/API_docs/methods/index.md'), $smatches);
165+
\preg_match_all('|\* (.*)|', \file_get_contents('docs/docs/API_docs/methods/index.md'), $smatches);
164166
foreach ($smatches[1] as $key => $match) {
165-
$match = str_replace('href="', 'href="https://docs.madelineproto.xyz/API_docs/methods/', $match);
167+
$match = \str_replace('href="', 'href="https://docs.madelineproto.xyz/API_docs/methods/', $match);
166168
$index .= "$spaces* ".$match."\n";
167169
}
168170
}
169171
}
170172
}
171173
}
172174

173-
$readme = explode('## ', file_get_contents('README.md'));
175+
$readme = \explode('## ', \file_get_contents('README.md'));
174176
foreach ($readme as &$section) {
175-
if (explode("\n", $section)[0] === 'Documentation') {
177+
if (\explode("\n", $section)[0] === 'Documentation') {
176178
$section = "Documentation\n\n".$index."\n";
177179
}
178180
}
179-
$readme = implode('## ', $readme);
181+
$readme = \implode('## ', $readme);
180182

181-
file_put_contents('README.md', $readme);
182-
file_put_contents('docs/docs/index.md', '---
183+
\file_put_contents('README.md', $readme);
184+
\file_put_contents('docs/docs/index.md', '---
183185
title: MadelineProto documentation
184186
description: PHP client/server for the telegram MTProto protocol (a better tg-cli)
185187
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png

‎combined_bot.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
You should have received a copy of the GNU General Public License along with MadelineProto.
1111
If not, see <http://www.gnu.org/licenses/>.
1212
*/
13-
set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/'));
13+
\set_include_path(\get_include_path().':'.\realpath(\dirname(__FILE__).'/MadelineProto/'));
1414

1515
/*
1616
* Various ways to load MadelineProto
1717
*/
18-
if (!file_exists(__DIR__.'/vendor/autoload.php')) {
18+
if (!\file_exists(__DIR__.'/vendor/autoload.php')) {
1919
echo 'You did not run composer update, using madeline.php'.PHP_EOL;
20-
if (!file_exists('madeline.php')) {
21-
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
20+
if (!\file_exists('madeline.php')) {
21+
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
2222
}
2323
include 'madeline.php';
2424
} else {
@@ -38,9 +38,9 @@ public function onAny($update, $path)
3838
yield $MadelineProto->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]);
3939
}
4040

41-
$res = json_encode($update, JSON_PRETTY_PRINT);
41+
$res = \json_encode($update, JSON_PRETTY_PRINT);
4242
if ($res == '') {
43-
$res = var_export($update, true);
43+
$res = \var_export($update, true);
4444
}
4545
yield $MadelineProto->sleep(3);
4646

‎input.raw‎

-15 MB
Binary file not shown.

‎layerdiff.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
\danog\MadelineProto\Logger::constructor($param);
2020
$logger = \danog\MadelineProto\Logger::$default;
2121

22-
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
22+
\set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
2323

2424
if ($argc !== 3) {
2525
die("Usage: {$argv[0]} layernumberold layernumbernew\n");
@@ -48,7 +48,7 @@ public function __construct($layer)
4848
}
4949
function getUrl($constructor, $type)
5050
{
51-
$changed = str_replace('.', '_', $constructor);
51+
$changed = \str_replace('.', '_', $constructor);
5252

5353
//return "[$constructor](https://github.com/danog/MadelineProtoDocs/blob/geochats/docs/API_docs/$type/$changed.md)";
5454
return "[$constructor](https://docs.madelineproto.xyz/API_docs/$type/$changed.html)";
@@ -62,7 +62,7 @@ function getUrl($constructor, $type)
6262
$key = $type === 'methods' ? 'method' : 'predicate';
6363

6464
// New constructors
65-
$res .= "\n\nNew ".ucfirst($type)."\n";
65+
$res .= "\n\nNew ".\ucfirst($type)."\n";
6666
foreach ($new[$type]->by_id as $constructor) {
6767
$name = $constructor[$key];
6868
if (!$old[$type]->$finder($name)) {
@@ -72,7 +72,7 @@ function getUrl($constructor, $type)
7272
}
7373

7474
// Changed constructors
75-
$res .= "\n\nChanged ".ucfirst($type)."\n";
75+
$res .= "\n\nChanged ".\ucfirst($type)."\n";
7676
foreach ($new[$type]->by_id as $constructor) {
7777
$name = $constructor[$key];
7878
$constructor['id'] = $new[$type]->$finder($name)['id'];
@@ -103,7 +103,7 @@ function getUrl($constructor, $type)
103103
}
104104

105105
// Deleted constructors
106-
$res .= "\n\nDeleted ".ucfirst($type)."\n";
106+
$res .= "\n\nDeleted ".\ucfirst($type)."\n";
107107
foreach ($old[$type]->by_id as $constructor) {
108108
$name = $constructor[$key];
109109
if (!$new[$type]->$finder($name)) {

‎lua/madeline.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,35 @@
1919
$Lua = \danog\MadelineProto\Serialization::deserialize('bot.madeline');
2020
} catch (\danog\MadelineProto\Exception $e) {
2121
}
22-
if (!is_object($Lua)) {
22+
if (!\is_object($Lua)) {
2323
$MadelineProto = new \danog\MadelineProto\API($settings);
24-
while (!in_array(($res = readline('Do you want to login as a user or as a bot (u/b)? ')), ['u', 'b'])) {
24+
while (!\in_array(($res = \readline('Do you want to login as a user or as a bot (u/b)? ')), ['u', 'b'])) {
2525
echo 'Please write either u or b'.PHP_EOL;
2626
}
2727
switch ($res) {
2828
case 'u':
29-
$sentCode = $MadelineProto->phone_login(readline('Enter your phone number: '));
29+
$sentCode = $MadelineProto->phone_login(\readline('Enter your phone number: '));
3030
\danog\MadelineProto\Logger::log($sentCode, \danog\MadelineProto\Logger::NOTICE);
3131
echo 'Enter the code you received: ';
32-
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);
32+
$code = \fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);
3333
$authorization = $MadelineProto->complete_phone_login($code);
3434
\danog\MadelineProto\Logger::log($authorization, \danog\MadelineProto\Logger::NOTICE);
3535
if ($authorization['_'] === 'account.noPassword') {
3636
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
3737
}
3838
if ($authorization['_'] === 'account.password') {
3939
\danog\MadelineProto\Logger::log('2FA is enabled', \danog\MadelineProto\Logger::NOTICE);
40-
$authorization = $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
40+
$authorization = $MadelineProto->complete_2fa_login(\readline('Please enter your password (hint '.$authorization['hint'].'): '));
4141
}
4242
if ($authorization['_'] === 'account.needSignup') {
4343
\danog\MadelineProto\Logger::log('Registering new user', \danog\MadelineProto\Logger::NOTICE);
44-
$authorization = $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
44+
$authorization = $MadelineProto->complete_signup(\readline('Please enter your first name: '), \readline('Please enter your last name (can be empty): '));
4545
}
4646
\danog\MadelineProto\Logger::log($authorization, \danog\MadelineProto\Logger::NOTICE);
4747
$Lua = new \danog\MadelineProto\Lua('madeline.lua', $MadelineProto);
4848
break;
4949
case 'b':
50-
$authorization = $MadelineProto->bot_login(readline('Please enter a bot token: '));
50+
$authorization = $MadelineProto->bot_login(\readline('Please enter a bot token: '));
5151
\danog\MadelineProto\Logger::log($authorization, \danog\MadelineProto\Logger::NOTICE);
5252
$Lua = new \danog\MadelineProto\Lua('madeline.lua', $MadelineProto);
5353
break;

0 commit comments

Comments
 (0)