Skip to content

Commit 09225da

Browse files
committed
Layer 150
1 parent 37fdcd5 commit 09225da

File tree

222 files changed

+1237
-2172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

222 files changed

+1237
-2172
lines changed

‎.php-cs-fixer.dist.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<?php
22

3-
$config = new Amp\CodeStyle\Config();
3+
$config = new class extends Amp\CodeStyle\Config {
4+
public function getRules(): array
5+
{
6+
return array_merge(parent::getRules(), [
7+
'void_return' => true,
8+
]);
9+
}
10+
};
11+
412
$config->getFinder()
513
->in(__DIR__ . '/src')
614
->in(__DIR__ . '/tests')

‎README.md

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# MadelineProto, a PHP MTProto telegram client
22

3-
[![phabel.io - PHP transpiler](https://phabel.io/badge)](https://phabel.io)
4-
53
Created by <a href="https://daniil.it" target="_blank" rel="noopener">Daniil Gentili</a>
64

75
`#StandWithUkraine 🇺🇦`
@@ -374,7 +372,6 @@ Want to add your own open-source project to this list? [Click here!](https://doc
374372
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getGameHighScores.html" name="messages.getGameHighScores">Get highscores of a game: messages.getGameHighScores</a>
375373
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getInactiveChannels.html" name="channels.getInactiveChannels">Get inactive channels and supergroups: channels.getInactiveChannels</a>
376374
* <a href="https://docs.madelineproto.xyz/API_docs/methods/phone.getGroupCallStreamChannels.html" name="phone.getGroupCallStreamChannels">Get info about RTMP streams in a group call or livestream. : phone.getGroupCallStreamChannels</a>
377-
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getChannels.html" name="channels.getChannels">Get info about channels/supergroups: channels.getChannels</a>
378375
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getParticipant.html" name="channels.getParticipant">Get info about a channel/supergroup participant: channels.getParticipant</a>
379376
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getWallPaper.html" name="account.getWallPaper">Get info about a certain wallpaper: account.getWallPaper</a>
380377
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getExportedChatInvite.html" name="messages.getExportedChatInvite">Get info about a chat invite: messages.getExportedChatInvite</a>
@@ -532,7 +529,6 @@ Want to add your own open-source project to this list? [Click here!](https://doc
532529
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getWallPapers.html" name="account.getWallPapers">Returns a list of available wallpapers: account.getWallPapers</a>
533530
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getEmojiURL.html" name="messages.getEmojiURL">Returns an HTTP URL which can be used to automatically log in into translation platform and suggest new emoji replacements. The URL will be valid for 30 seconds after generation: messages.getEmojiURL</a>
534531
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getAttachMenuBot.html" name="messages.getAttachMenuBot">Returns attachment menu entry for a bot web app that can be launched from the attachment menu »: messages.getAttachMenuBot</a>
535-
* <a href="https://docs.madelineproto.xyz/API_docs/methods/users.getUsers.html" name="users.getUsers">Returns basic user info according to their identifiers: users.getUsers</a>
536532
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.getChats.html" name="messages.getChats">Returns chat basic info on their IDs: messages.getChats</a>
537533
* <a href="https://docs.madelineproto.xyz/API_docs/methods/upload.getWebFile.html" name="upload.getWebFile">Returns content of a web file, by proxying the request through telegram, see the webfile docs for more info: upload.getWebFile</a>
538534
* <a href="https://docs.madelineproto.xyz/API_docs/methods/help.getConfig.html" name="help.getConfig">Returns current configuration, including data center configuration: help.getConfig</a>

‎examples/bot.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
/*
3131
* Various ways to load MadelineProto
3232
*/
33-
if (\file_exists('vendor/autoload.php')) {
33+
if (file_exists('vendor/autoload.php')) {
3434
include 'vendor/autoload.php';
3535
} else {
36-
if (!\file_exists('madeline.php')) {
37-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
36+
if (!file_exists('madeline.php')) {
37+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
3838
}
3939
/**
4040
* @psalm-suppress MissingFile
@@ -55,7 +55,6 @@ class MyEventHandler extends EventHandler
5555
/**
5656
* List of properties automatically stored in database (MySQL, Postgres, redis or memory).
5757
* @see https://docs.madelineproto.xyz/docs/DATABASE.html
58-
* @var array
5958
*/
6059
protected static array $dbProperties = [
6160
'dataStoredOnDb' => 'array'
@@ -81,7 +80,7 @@ public function getReportPeers()
8180
public function onStart()
8281
{
8382
$this->logger("The bot was started!");
84-
\var_dump(yield $this->getFullInfo('madelineproto'));
83+
var_dump(yield $this->getFullInfo('madelineproto'));
8584
}
8685
/**
8786
* Handle updates from supergroups and channels.
@@ -100,7 +99,6 @@ public function onUpdateNewChannelMessage(array $update): \Generator
10099
*
101100
* @param array $update Update
102101
*
103-
* @return \Generator
104102
*/
105103
public function onUpdateNewMessage(array $update): \Generator
106104
{
@@ -119,7 +117,6 @@ public function onUpdateNewMessage(array $update): \Generator
119117
}
120118
*/
121119

122-
123120
// You can also use the built-in MadelineProto MySQL async driver!
124121

125122
// Can be anything serializable, an array, an int, an object

‎examples/botAllMessages.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
/*
2323
* Various ways to load MadelineProto
2424
*/
25-
if (\file_exists('vendor/autoload.php')) {
25+
if (file_exists('vendor/autoload.php')) {
2626
include 'vendor/autoload.php';
2727
} else {
28-
if (!\file_exists('madeline.php')) {
29-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
28+
if (!file_exists('madeline.php')) {
29+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
3030
}
3131
/**
3232
* @psalm-suppress MissingFile
@@ -44,11 +44,11 @@
4444
$threads = 5;
4545
$step = 20;
4646
$totalMessages = 0;
47-
$start = \microtime(true);
47+
$start = microtime(true);
4848
while (true) {
4949
$promises = [];
5050
for ($i = 0; $i < $threads; $i++) {
51-
$promises[] = $MadelineProto->messages->getMessages(['id' => \range($lastMessageId+1, $lastMessageId+$step)]);
51+
$promises[] = $MadelineProto->messages->getMessages(['id' => range($lastMessageId+1, $lastMessageId+$step)]);
5252
$lastMessageId +=$step;
5353
}
5454
$results = yield \Amp\Promise\all($promises);
@@ -62,6 +62,6 @@
6262
}
6363
}
6464
};
65-
$time = \microtime(true)-$start;
65+
$time = microtime(true)-$start;
6666
yield $MadelineProto->echo("\nTime: {$time}\n");
6767
});

‎examples/combinedBot.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
/*
2727
* Various ways to load MadelineProto
2828
*/
29-
if (\file_exists('vendor/autoload.php')) {
29+
if (file_exists('vendor/autoload.php')) {
3030
include 'vendor/autoload.php';
3131
} else {
32-
if (!\file_exists('madeline.php')) {
33-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
32+
if (!file_exists('madeline.php')) {
33+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
3434
}
3535
include 'madeline.php';
3636
}
@@ -58,7 +58,6 @@ public function getReportPeers()
5858
*
5959
* @param array $update Update
6060
*
61-
* @return \Generator
6261
*/
6362
public function onUpdateNewChannelMessage(array $update): \Generator
6463
{
@@ -69,14 +68,13 @@ public function onUpdateNewChannelMessage(array $update): \Generator
6968
*
7069
* @param array $update Update
7170
*
72-
* @return \Generator
7371
*/
7472
public function onUpdateNewMessage(array $update): \Generator
7573
{
7674
if ($update['message']['_'] === 'messageEmpty' || $update['message']['out'] ?? false) {
7775
return;
7876
}
79-
$res = \json_encode($update, JSON_PRETTY_PRINT);
77+
$res = json_encode($update, JSON_PRETTY_PRINT);
8078

8179
yield $this->messages->sendMessage(['peer' => $update, 'message' => "<code>$res</code>", 'reply_to_msg_id' => isset($update['message']['id']) ? $update['message']['id'] : null, 'parse_mode' => 'HTML']);
8280
if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') {

‎examples/database-config-examples/memory.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* load MadelineProto in Your Project
77
*/
88

9-
10-
if (\file_exists('vendor/autoload.php')) {
9+
if (file_exists('vendor/autoload.php')) {
1110
include 'vendor/autoload.php';
1211
} else {
13-
if (!\file_exists('madeline.php')) {
14-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
12+
if (!file_exists('madeline.php')) {
13+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
1514
}
1615
include 'madeline.php';
1716
}
@@ -41,7 +40,6 @@
4140

4241
$settings->setDb($database);
4342

44-
4543
/*
4644
create madeline proto session
4745
*/

‎examples/database-config-examples/mysql.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* load MadelineProto in Your Project
77
*/
88

9-
10-
if (\file_exists('vendor/autoload.php')) {
9+
if (file_exists('vendor/autoload.php')) {
1110
include 'vendor/autoload.php';
1211
} else {
13-
if (!\file_exists('madeline.php')) {
14-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
12+
if (!file_exists('madeline.php')) {
13+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
1514
}
1615
include 'madeline.php';
1716
}
@@ -42,7 +41,6 @@
4241

4342
$settings->setDb($database);
4443

45-
4644
/*
4745
create madeline proto session
4846
*/

‎examples/database-config-examples/postgres.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* load MadelineProto in Your Project
77
*/
88

9-
10-
if (\file_exists('vendor/autoload.php')) {
9+
if (file_exists('vendor/autoload.php')) {
1110
include 'vendor/autoload.php';
1211
} else {
13-
if (!\file_exists('madeline.php')) {
14-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
12+
if (!file_exists('madeline.php')) {
13+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
1514
}
1615
include 'madeline.php';
1716
}
@@ -42,7 +41,6 @@
4241

4342
$settings->setDb($database);
4443

45-
4644
/*
4745
create madeline proto session
4846
*/

‎examples/database-config-examples/redis.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* load MadelineProto in Your Project
77
*/
88

9-
10-
if (\file_exists('vendor/autoload.php')) {
9+
if (file_exists('vendor/autoload.php')) {
1110
include 'vendor/autoload.php';
1211
} else {
13-
if (!\file_exists('madeline.php')) {
14-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
12+
if (!file_exists('madeline.php')) {
13+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
1514
}
1615
include 'madeline.php';
1716
}
@@ -41,7 +40,6 @@
4140

4241
$settings->setDb($database);
4342

44-
4543
/*
4644
create madeline proto session
4745
*/

‎examples/downloadRenameBot.php

+19-21
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
* @link https://docs.madelineproto.xyz MadelineProto documentation
2020
*/
2121

22-
23-
if (\function_exists('memprof_enable')) {
24-
\memprof_enable();
22+
if (function_exists('memprof_enable')) {
23+
memprof_enable();
2524
}
2625

2726
use Amp\Http\Server\HttpServer;
@@ -36,11 +35,11 @@
3635
/*
3736
* Various ways to load MadelineProto
3837
*/
39-
if (\file_exists('vendor/autoload.php')) {
38+
if (file_exists('vendor/autoload.php')) {
4039
include 'vendor/autoload.php';
4140
} else {
42-
if (!\file_exists('madeline.php')) {
43-
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
41+
if (!file_exists('madeline.php')) {
42+
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
4443
}
4544
include 'madeline.php';
4645
}
@@ -89,7 +88,7 @@ public function getReportPeers()
8988
*/
9089
public function __construct(?APIWrapper $API)
9190
{
92-
$this->UPLOAD = \class_exists(HttpServer::class);
91+
$this->UPLOAD = class_exists(HttpServer::class);
9392
parent::__construct($API);
9493
}
9594
public function onStart()
@@ -112,7 +111,6 @@ public function onUpdateNewChannelMessage(array $update)
112111
*
113112
* @param array $update Update
114113
*
115-
* @return \Generator
116114
*/
117115
public function onUpdateNewMessage(array $update): \Generator
118116
{
@@ -137,18 +135,18 @@ public function onUpdateNewMessage(array $update): \Generator
137135
return $this->messages->sendMessage(['peer' => $peerId, 'message' => self::START, 'parse_mode' => 'Markdown', 'reply_to_msg_id' => $messageId]);
138136
}
139137
if ($update['message']['message'] === '/report' && $peerId === $this->adminId) {
140-
\memprof_dump_callgrind($stm = \fopen("php://memory", "w"));
141-
\fseek($stm, 0);
138+
memprof_dump_callgrind($stm = fopen("php://memory", "w"));
139+
fseek($stm, 0);
142140
yield $this->messages->sendMedia(['peer' => $peerId, 'media' => ['_' => 'inputMediaUploadedDocument', 'file' => $stm, 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'callgrind.out']]]]);
143-
\fclose($stm);
141+
fclose($stm);
144142
return;
145143
}
146144
if (isset($update['message']['media']['_']) && $update['message']['media']['_'] !== 'messageMediaWebPage') {
147145
if ($this->UPLOAD && ($this->states[$peerId] ?? false) === $this->UPLOAD) {
148146
unset($this->states[$peerId]);
149147
$update = Files::extractBotAPIFile(yield $this->MTProtoToBotAPI($update));
150148
$file = [$update['file_size'], $update['mime_type']];
151-
\var_dump($update['file_id'].'.'.Tools::base64urlEncode(\json_encode($file))."/".$update['file_name']);
149+
var_dump($update['file_id'].'.'.Tools::base64urlEncode(json_encode($file))."/".$update['file_name']);
152150
return;
153151
}
154152
yield $this->messages->sendMessage(['peer' => $peerId, 'message' => 'Give me a new name for this file: ', 'reply_to_msg_id' => $messageId]);
@@ -161,19 +159,19 @@ public function onUpdateNewMessage(array $update): \Generator
161159
$url = $this->states[$peerId];
162160
unset($this->states[$peerId]);
163161
} else {
164-
$url = \explode(' ', $update['message']['message'], 2);
165-
$name = \trim($url[1] ?? \basename($update['message']['message']));
166-
$url = \trim($url[0]);
162+
$url = explode(' ', $update['message']['message'], 2);
163+
$name = trim($url[1] ?? basename($update['message']['message']));
164+
$url = trim($url[0]);
167165
if (!$url) {
168166
return;
169167
}
170-
if (\stripos($url, 'http') !== 0) {
168+
if (stripos($url, 'http') !== 0) {
171169
$url = "http://$url";
172170
}
173171
}
174172
$id = yield $this->messages->sendMessage(['peer' => $peerId, 'message' => 'Preparing...', 'reply_to_msg_id' => $messageId]);
175173
if (!isset($id['id'])) {
176-
$this->report(\json_encode($id));
174+
$this->report(json_encode($id));
177175
foreach ($id['updates'] as $updat) {
178176
if (isset($updat['id'])) {
179177
$id = $updat['id'];
@@ -190,7 +188,7 @@ function ($progress, $speed, $time) use ($peerId, $id) {
190188
$this->logger("Upload progress: $progress%");
191189

192190
static $prev = 0;
193-
$now = \time();
191+
$now = time();
194192
if ($now - $prev < 10 && $progress < 100) {
195193
return;
196194
}
@@ -217,18 +215,18 @@ function ($progress, $speed, $time) use ($peerId, $id) {
217215
]
218216
);
219217

220-
if (\in_array($peer['type'], ['channel', 'supergroup'])) {
218+
if (in_array($peer['type'], ['channel', 'supergroup'])) {
221219
yield $this->channels->deleteMessages(['channel' => $peerId, 'id' => [$id]]);
222220
} else {
223221
yield $this->messages->deleteMessages(['revoke' => true, 'id' => [$id]]);
224222
}
225223
} catch (\Throwable $e) {
226-
if (\strpos($e->getMessage(), 'Could not connect to URI') === false && !($e instanceof UriException) && \strpos($e->getMessage(), 'URI') === false) {
224+
if (strpos($e->getMessage(), 'Could not connect to URI') === false && !($e instanceof UriException) && strpos($e->getMessage(), 'URI') === false) {
227225
$this->report((string) $e);
228226
$this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
229227
}
230228
if ($e instanceof RPCErrorException && $e->rpc === 'FILE_PARTS_INVALID') {
231-
$this->report(\json_encode($url));
229+
$this->report(json_encode($url));
232230
}
233231
try {
234232
yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => 'Error: '.$e->getMessage()]);

0 commit comments

Comments
 (0)