Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 5, 2023
1 parent b532604 commit a85c6cf
Show file tree
Hide file tree
Showing 28 changed files with 545 additions and 523 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* [Manual (bot)](https://docs.madelineproto.xyz/docs/LOGIN.html#manual-bot)
* [QR code login (user)](https://docs.madelineproto.xyz/docs/LOGIN.html#qr-code-user)
* [Features](https://docs.madelineproto.xyz/docs/FEATURES.html) - MadelineProto can do everything official clients can do, and more!
* [Requirements](https://docs.madelineproto.xyz/docs/REQUIREMENTS.html) - MadelineProto requires the mbstring, xml, json, fileinfo, gmp, openssl, iconv extensions to function properly.
* [Requirements](https://docs.madelineproto.xyz/docs/REQUIREMENTS.html) - MadelineProto requires the mbstring, xml, json, fileinfo, gmp, openssl, iconv, gd extensions to function properly.
* [MadelineProto on Docker](https://docs.madelineproto.xyz/docs/DOCKER.html) - MadelineProto offers an official MadelineProto docker image for the linux/amd64, linux/arm64 and linux/riscv64 platforms @ hub.madelineproto.xyz/danog/madelineproto.
* [Getting started](https://docs.madelineproto.xyz/docs/DOCKER.html#getting-started)
* [CLI bot (recommended)](https://docs.madelineproto.xyz/docs/DOCKER.html#cli-bot-recommended)
Expand Down
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 43 files
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/AbstractMessage.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/AbstractPrivateMessage.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/ChannelMessage.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/GroupMessage.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/PrivateMessage.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/SecretMessage.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogBotAllowed.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChannelCreated.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChannelMigrateFrom.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChatJoinedByLink.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChatMigrateTo.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogContactSignUp.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogCreated.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogDeleteMessages.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGameScore.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGeoProximityReached.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGiftPremium.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall/GroupCall.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall/GroupCallInvited.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogGroupCall/GroupCallScheduled.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogHistoryCleared.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMemberJoinedByRequest.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMemberLeft.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMembersJoined.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMessagePinned.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPeerRequested.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPhoneCall.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPhotoChanged.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogReadMessages.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogScreenshotTaken.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSetChatTheme.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSetChatWallPaper.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSetTTL.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSuggestProfilePhoto.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTitleChanged.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTopicCreated.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTopicEdited.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogWebView.md
+4 −2 docs/PHP/danog/MadelineProto/EventHandler/Message/ServiceMessage.md
+2 −2 docs/docs/REQUIREMENTS.md
+1 −1 docs/index.md
2 changes: 1 addition & 1 deletion src/AnnotationsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private function prepareTLParams(array $data): array
}
$contents .= " * @param ?int \$floodWaitLimit Can be used to specify a custom flood wait limit: if a FLOOD_WAIT_ rate limiting error is received with a waiting period bigger than this integer, an RPCErrorException will be thrown; otherwise, MadelineProto will simply wait for the specified amount of time. Defaults to the value specified in the settings: https://docs.madelineproto.xyz/PHP/danog/MadelineProto/Settings/RPC.html#setfloodtimeout-int-floodtimeout-self\n";
$signature []= "?int \$floodWaitLimit = null";
$contents .= " * @param bool \$postpone If true, will postpone execution of this method until the first method call with \$postpone = false, bundling all queued in a single container for higher efficiency. Will not return until the method is queued and a response is received, so this should be used in combination with \\Amp\\async.\n";
$contents .= " * @param bool \$postpone If true, will postpone execution of this method until the first method call with \$postpone = false to the same DC or a call to flush() is made, bundling all queued in a single container for higher efficiency. Will not return until the method is queued and a response is received, so this should be used in combination with \\Amp\\async.\n";
$signature []= "bool \$postpone = false";
$contents .= " * @param ?string \$queueId Usually, concurrent method calls are executed in arbitrary order: with this option, strict ordering for requests **to the same chat/datacenter** can be enforced by specifying the same queue ID for all methods that require strictly ordered execution.\n";
$signature []= "?string \$queueId = null";
Expand Down
5 changes: 4 additions & 1 deletion src/EventHandler/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace danog\MadelineProto\EventHandler;

use Amp\Cancellation;
use AssertionError;
use danog\MadelineProto\EventHandler\Action\Typing;
use danog\MadelineProto\EventHandler\Message\Service\DialogSetTTL;
Expand Down Expand Up @@ -222,6 +223,7 @@ public function reply(
bool $background = false,
bool $clearDraft = false,
bool $updateStickersetsOrder = false,
?Cancellation $cancellation = null
): Message {
return $this->getClient()->sendMessage(
peer: $this->chatId,
Expand All @@ -237,7 +239,8 @@ public function reply(
background: $background,
clearDraft: $clearDraft,
noWebpage: $noWebpage,
updateStickersetsOrder: $updateStickersetsOrder
updateStickersetsOrder: $updateStickersetsOrder,
cancellation: $cancellation
);
}

Expand Down
16 changes: 12 additions & 4 deletions src/InternalDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,13 @@ public static function flock(string $file, int $operation, float $polling = 0.1,
{
return \danog\MadelineProto\AsyncTools::flock($file, $operation, $polling, $token, $failureCb);
}
/**
* Flush all postponed messages.
*/
public function flush(): void
{
$this->wrapper->getAPI()->flush();
}
/**
* When was full info for this chat last cached.
*
Expand Down Expand Up @@ -1668,10 +1675,11 @@ public function sendDocument(string|int $peer, \danog\MadelineProto\EventHandler
* @param boolean $clearDraft Clears the draft field
* @param boolean $noWebpage Set this flag to disable generation of the webpage preview
* @param boolean $updateStickersetsOrder Whether to move used stickersets to top
* @param ?Cancellation $cancellation Cancellation
*/
public function sendMessage(string|int $peer, string $message, \danog\MadelineProto\ParseMode $parseMode = \danog\MadelineProto\ParseMode::TEXT, ?int $replyToMsgId = null, ?int $topMsgId = null, ?array $replyMarkup = null, string|int|null $sendAs = null, ?int $scheduleDate = null, bool $silent = false, bool $noForwards = false, bool $background = false, bool $clearDraft = false, bool $noWebpage = false, bool $updateStickersetsOrder = false): \danog\MadelineProto\EventHandler\Message
public function sendMessage(string|int $peer, string $message, \danog\MadelineProto\ParseMode $parseMode = \danog\MadelineProto\ParseMode::TEXT, ?int $replyToMsgId = null, ?int $topMsgId = null, ?array $replyMarkup = null, string|int|null $sendAs = null, ?int $scheduleDate = null, bool $silent = false, bool $noForwards = false, bool $background = false, bool $clearDraft = false, bool $noWebpage = false, bool $updateStickersetsOrder = false, ?\Amp\Cancellation $cancellation = null): \danog\MadelineProto\EventHandler\Message
{
return $this->wrapper->getAPI()->sendMessage($peer, $message, $parseMode, $replyToMsgId, $topMsgId, $replyMarkup, $sendAs, $scheduleDate, $silent, $noForwards, $background, $clearDraft, $noWebpage, $updateStickersetsOrder);
return $this->wrapper->getAPI()->sendMessage($peer, $message, $parseMode, $replyToMsgId, $topMsgId, $replyMarkup, $sendAs, $scheduleDate, $silent, $noForwards, $background, $clearDraft, $noWebpage, $updateStickersetsOrder, $cancellation);
}
/**
* Sends a message to all report peers (admins of the bot).
Expand All @@ -1687,9 +1695,9 @@ public function sendMessage(string|int $peer, string $message, \danog\MadelinePr
*
* @return list<\danog\MadelineProto\EventHandler\Message>
*/
public function sendMessageToAdmins(string $message, \danog\MadelineProto\ParseMode $parseMode = \danog\MadelineProto\ParseMode::TEXT, ?array $replyMarkup = null, ?int $scheduleDate = null, bool $silent = false, bool $noForwards = false, bool $background = false, bool $clearDraft = false, bool $noWebpage = false): array
public function sendMessageToAdmins(string $message, \danog\MadelineProto\ParseMode $parseMode = \danog\MadelineProto\ParseMode::TEXT, ?array $replyMarkup = null, ?int $scheduleDate = null, bool $silent = false, bool $noForwards = false, bool $background = false, bool $clearDraft = false, bool $noWebpage = false, ?\Amp\Cancellation $cancellation = null): array
{
return $this->wrapper->getAPI()->sendMessageToAdmins($message, $parseMode, $replyMarkup, $scheduleDate, $silent, $noForwards, $background, $clearDraft, $noWebpage);
return $this->wrapper->getAPI()->sendMessageToAdmins($message, $parseMode, $replyMarkup, $scheduleDate, $silent, $noForwards, $background, $clearDraft, $noWebpage, $cancellation);
}
/**
* Sends a photo.
Expand Down
8 changes: 6 additions & 2 deletions src/Loop/Connection/WriteLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use danog\MadelineProto\MTProtoTools\Crypt;
use danog\MadelineProto\Tools;
use Revolt\EventLoop;
use Webmozart\Assert\Assert;

use function strlen;

Expand Down Expand Up @@ -248,7 +247,12 @@ public function encryptedWriteLoop(): bool
&& !$prev->hasReply()
) {
$prevId = $prev->getMsgId();
Assert::notNull($prevId);
if (!$prevId) {
$prev->getResultPromise()->finally(fn () => $this->resume(true));
$this->API->logger("Skipping $message due pending local queue in DC $this->datacenter");
$skipped = true;
continue;
}
$MTmessage['body'] = $this->API->getTL()->serializeMethod(
'invokeAfterMsg',
[
Expand Down
14 changes: 13 additions & 1 deletion src/MTProto.php
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,16 @@ public function setReportPeers(int|string|array $userOrId): void
$this->reportDest = $this->sanitizeReportPeers($userOrId);
$this->admins = array_values(array_filter($this->reportDest, fn (int $v) => $v > 0));
}
/**
* Flush all postponed messages.
*/
public function flush(): void
{
$this->waitForInit();
foreach ($this->datacenter->getDataCenterConnections() as $conn) {
$conn->flush();
}
}
private ?LocalMutex $reportMutex = null;
/**
* Sends a message to all report peers (admins of the bot).
Expand All @@ -1599,6 +1609,7 @@ public function sendMessageToAdmins(
bool $background = false,
bool $clearDraft = false,
bool $noWebpage = false,
?Cancellation $cancellation = null
): array {
$result = [];
foreach ($this->admins as $report) {
Expand All @@ -1612,7 +1623,8 @@ public function sendMessageToAdmins(
noForwards: $noForwards,
background: $background,
clearDraft: $clearDraft,
noWebpage: $noWebpage
noWebpage: $noWebpage,
cancellation: $cancellation
);
}
return $result;
Expand Down
11 changes: 0 additions & 11 deletions src/MTProtoSession/CallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use danog\MadelineProto\TL\Exception;
use danog\MadelineProto\WrappedFuture;
use Revolt\EventLoop;
use Throwable;

use function Amp\async;
use function Amp\Future\await;
Expand Down Expand Up @@ -152,16 +151,6 @@ public function methodCallAsyncWrite(string $method, array $args): WrappedFuture
if (isset($this->callQueue[$queueId])
&& !($prev = $this->callQueue[$queueId])->hasReply()
) {
/** @var MTProtoOutgoingMessage $prev */
if (!$prev->hasMsgId() && $prev->wasSent()) {
// Use client-side queue due to MSG_WAIT_* error, wait...
try {
$prev->getResultPromise()->await($cancellation);
} catch (Throwable) {
}
// Got response, resume order is equal to suspension order
$cancellation?->throwIfRequested();
}
$this->API->logger("$method to queue with ID $queueId", Logger::ULTRA_VERBOSE);
} else {
$prev = null;
Expand Down
6 changes: 4 additions & 2 deletions src/MTProtoTools/FilesAbstraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ public function sendMedia(
$params = [
'peer' => $peer,
'message' => $message,
'file' => $file
'file' => $file,
'cancellation' => $cancellation,
];
} else {
$method = 'messages.sendMedia';
Expand Down Expand Up @@ -441,7 +442,8 @@ public function sendMedia(
'parse_mode' => $parseMode,
'schedule_date' => $scheduleDate,
'send_as' => $sendAs,
'media' => $media
'media' => $media,
'cancellation' => $cancellation,
];
}

Expand Down
6 changes: 5 additions & 1 deletion src/MTProtoTools/UpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace danog\MadelineProto\MTProtoTools;

use Amp\Cancellation;
use Amp\CancelledException;
use Amp\DeferredFuture;
use Amp\Http\Client\Request;
Expand Down Expand Up @@ -712,6 +713,7 @@ public function wrapMessage(array $message): ?AbstractMessage
* @param boolean $clearDraft Clears the draft field
* @param boolean $noWebpage Set this flag to disable generation of the webpage preview
* @param boolean $updateStickersetsOrder Whether to move used stickersets to top
* @param ?Cancellation $cancellation Cancellation
*/
public function sendMessage(
int|string $peer,
Expand All @@ -728,6 +730,7 @@ public function sendMessage(
bool $clearDraft = false,
bool $noWebpage = false,
bool $updateStickersetsOrder = false,
?Cancellation $cancellation = null
): Message {
$result = $this->methodCallAsyncRead(
'messages.sendMessage',
Expand All @@ -745,7 +748,8 @@ public function sendMessage(
'background' => $background,
'clear_draft' => $clearDraft,
'no_webpage' => $noWebpage,
'update_stickersets_order' => $updateStickersetsOrder
'update_stickersets_order' => $updateStickersetsOrder,
'cancellation' => $cancellation
]
);
if (isset($result['_'])) {
Expand Down
Loading

0 comments on commit a85c6cf

Please sign in to comment.