mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 19:24:42 +01:00
Improve bot API conversion
This commit is contained in:
parent
89e1230b06
commit
6cdf32e5e1
@ -61,7 +61,7 @@ The following open source projects were created using MadelineProto: you can dir
|
||||
* [`tgstories_dl_bot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/tgstories_dl_bot.php) - Source code of [@tgstories_dl_bot](https://t.me/tgstories_dl_bot) - Bot to download any Telegram Story!
|
||||
* [`downloadRenameBot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/downloadRenameBot.php) - Download files by URL and rename Telegram files using this async parallelized bot!
|
||||
* [`secret_bot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/secret_bot.php) - Secret chat bot!
|
||||
* [`pipesbot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/pipesbot.php) - Creating inline bots and using other inline bots via a userbot!
|
||||
* [`pipesbot.php`](https://github.com/danog/pipesbot) - Creating inline bots and using other inline bots via a userbot!
|
||||
* [`bot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/bot.php) - Examples for sending normal messages, downloading any media!
|
||||
|
||||
Want to add your own open-source project to this list? [Click here!](https://docs.madelineproto.xyz/FOSS.html)
|
||||
@ -435,7 +435,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#callfork-generator-amp-future-callable-callable-mixed-args-amp-future-t" name="callFork">Fork a new green thread and execute the passed function in the background: callFork</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#broadcastforwardmessages-mixed-from_peer-list-int-message_ids-bool-drop_author-false-danog-madelineproto-broadcast-filter-filter-null-bool-pin-false-int" name="broadcastForwardMessages">Forwards a list of messages to all peers (users, chats, channels) of the bot: broadcastForwardMessages</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.forwardMessages.html" name="messages.forwardMessages">Forwards messages by their IDs: messages.forwardMessages</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#genvectorhash-array-ints-string" name="genVectorHash">Generate MTProto vector hash: genVectorHash</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#genvectorhash-array-longs-string" name="genVectorHash">Generate MTProto vector hash: genVectorHash</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/auth.exportLoginToken.html" name="auth.exportLoginToken">Generate a login token, for login via QR code. : auth.exportLoginToken</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/payments.exportInvoice.html" name="payments.exportInvoice">Generate an invoice deep link: payments.exportInvoice</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/contacts.exportContactToken.html" name="contacts.exportContactToken">Generates a temporary profile link for the currently logged-in user: contacts.exportContactToken</a>
|
||||
|
@ -29,6 +29,8 @@ use danog\MadelineProto\PeerNotInDbException;
|
||||
use danog\MadelineProto\PTSException;
|
||||
use danog\MadelineProto\RPCErrorException;
|
||||
|
||||
use function Amp\delay;
|
||||
|
||||
/**
|
||||
* Update loop.
|
||||
*
|
||||
@ -92,6 +94,10 @@ final class UpdateLoop extends Loop
|
||||
try {
|
||||
$difference = $this->API->methodCallAsyncRead('updates.getChannelDifference', ['channel' => $this->API->toSupergroup($this->channelId), 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['datacenter' => $this->API->datacenter->currentDatacenter, 'postpone' => $this->first, 'FloodWaitLimit' => 86400]);
|
||||
} catch (RPCErrorException $e) {
|
||||
if ($e->rpc === '-503') {
|
||||
delay(1.0);
|
||||
continue;
|
||||
}
|
||||
if (\in_array($e->rpc, ['CHANNEL_PRIVATE', 'CHAT_FORBIDDEN', 'CHANNEL_INVALID', 'USER_BANNED_IN_CHANNEL'], true)) {
|
||||
$this->feeder->stop();
|
||||
unset($this->API->updaters[$this->channelId], $this->API->feeders[$this->channelId]);
|
||||
@ -151,7 +157,16 @@ final class UpdateLoop extends Loop
|
||||
}
|
||||
} else {
|
||||
$this->logger->logger('Resumed and fetching normal difference...', Logger::ULTRA_VERBOSE);
|
||||
$difference = $this->API->methodCallAsyncRead('updates.getDifference', ['pts' => $state->pts(), 'date' => $state->date(), 'qts' => $state->qts()], ['datacenter' => $this->API->authorized_dc]);
|
||||
do {
|
||||
try {
|
||||
$difference = $this->API->methodCallAsyncRead('updates.getDifference', ['pts' => $state->pts(), 'date' => $state->date(), 'qts' => $state->qts()], ['datacenter' => $this->API->authorized_dc]);
|
||||
break;
|
||||
} catch (RPCErrorException $e) {
|
||||
if ($e->rpc !== '-503') {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
} while (true);
|
||||
$this->logger->logger('Got '.$difference['_'], Logger::ULTRA_VERBOSE);
|
||||
$timeout = self::DEFAULT_TIMEOUT;
|
||||
switch ($difference['_']) {
|
||||
|
@ -36,6 +36,7 @@ use danog\MadelineProto\SecretPeerNotInDbException;
|
||||
use danog\MadelineProto\Settings;
|
||||
use danog\MadelineProto\Tools;
|
||||
use InvalidArgumentException;
|
||||
use Throwable;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
use const danog\Decoder\PHOTOSIZE_SOURCE_DIALOGPHOTO_BIG;
|
||||
@ -983,7 +984,11 @@ trait PeerHandler
|
||||
*/
|
||||
public function getPwrChat(mixed $id, bool $fullfetch = true): array
|
||||
{
|
||||
$full = $fullfetch && $this->getSettings()->getDb()->getEnableFullPeerDb() ? $this->getFullInfo($id) : $this->getInfo($id);
|
||||
try {
|
||||
$full = $fullfetch && $this->getSettings()->getDb()->getEnableFullPeerDb() ? $this->getFullInfo($id) : $this->getInfo($id);
|
||||
} catch (Throwable) {
|
||||
$full = $this->getInfo($id);
|
||||
}
|
||||
$res = ['id' => $full['bot_api_id'], 'type' => $full['type']];
|
||||
switch ($full['type']) {
|
||||
case 'user':
|
||||
|
@ -187,9 +187,9 @@ trait BotAPI
|
||||
$newd['post'] = $data['post'];
|
||||
$newd['silent'] = $data['silent'];
|
||||
if (isset($data['from_id'])) {
|
||||
$newd['from'] = ($this->getPwrChat($data['from_id']));
|
||||
$newd['from'] = ($this->getPwrChat($data['from_id'], false));
|
||||
}
|
||||
$newd['chat'] = ($this->getPwrChat($data['peer_id']));
|
||||
$newd['chat'] = ($this->getPwrChat($data['peer_id'], false));
|
||||
if (isset($data['entities'])) {
|
||||
$newd['entities'] = ($this->MTProtoToBotAPI($data['entities']));
|
||||
}
|
||||
@ -200,14 +200,14 @@ trait BotAPI
|
||||
$newd['edit_date'] = $data['edit_date'];
|
||||
}
|
||||
if (isset($data['via_bot_id'])) {
|
||||
$newd['via_bot'] = ($this->getPwrChat($data['via_bot_id']));
|
||||
$newd['via_bot'] = ($this->getPwrChat($data['via_bot_id'], false));
|
||||
}
|
||||
if (isset($data['fwd_from']['from_id'])) {
|
||||
$newd['forward_from'] = ($this->getPwrChat($data['fwd_from']['from_id']));
|
||||
$newd['forward_from'] = ($this->getPwrChat($data['fwd_from']['from_id'], false));
|
||||
}
|
||||
if (isset($data['fwd_from']['channel_id'])) {
|
||||
try {
|
||||
$newd['forward_from_chat'] = $this->getPwrChat(MTProto::toSupergroup($data['fwd_from']['channel_id']));
|
||||
$newd['forward_from_chat'] = $this->getPwrChat(MTProto::toSupergroup($data['fwd_from']['channel_id']), false);
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
@ -285,7 +285,7 @@ trait BotAPI
|
||||
case 'messageEntityMentionName':
|
||||
unset($data['_']);
|
||||
$data['type'] = 'text_mention';
|
||||
$data['user'] = ($this->getPwrChat($data['user_id']));
|
||||
$data['user'] = ($this->getPwrChat($data['user_id'], false));
|
||||
unset($data['user_id']);
|
||||
return $data;
|
||||
case 'messageMediaPhoto':
|
||||
|
Loading…
Reference in New Issue
Block a user