1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 12:31:15 +01:00

Update docs

This commit is contained in:
Daniil Gentili 2023-05-26 17:54:42 +02:00
parent d17dcca02a
commit 942d0ac4d3
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
9 changed files with 127 additions and 11 deletions

View File

@ -84,6 +84,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* [Simple](https://docs.madelineproto.xyz/docs/INSTALLATION.html#simple)
* [Composer from existing project](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project)
* [Composer from scratch](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-scratch)
* [Broadcasting messages to all users](https://docs.madelineproto.xyz/docs/BROADCAST.html)
* [Handling updates (new messages & other events)](https://docs.madelineproto.xyz/docs/UPDATES.html)
* [Async Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#async-event-driven)
* [Built-in database driver](https://docs.madelineproto.xyz/docs/UPDATES.html#built-in-database-driver)

View File

@ -61,7 +61,8 @@
"webmozart/assert": "^1.11"
},
"require-dev": {
"phpdocumentor/reflection-docblock": "^5.2",
"phpdocumentor/reflection-docblock": "dev-master",
"phpdocumentor/type-resolver": "1.x-dev@dev",
"ext-ctype": "*",
"danog/phpdoc": "^0.1.7",
"phpunit/phpunit": "^9",

2
docs

@ -1 +1 @@
Subproject commit f3e1bbfe1afc06f1d4579db1a11e8a30fe62d043
Subproject commit 727240ef2c3a46b91d3ef35afcaed6fc43d02f3d

View File

@ -23,7 +23,7 @@ namespace danog\MadelineProto\Broadcast\Action;
use Amp\Cancellation;
use danog\MadelineProto\Broadcast\Action;
use danog\MadelineProto\MTProto;
use LogicException;
use danog\MadelineProto\RPCErrorException;
/** @internal */
final class ActionSend implements Action
@ -33,6 +33,34 @@ final class ActionSend implements Action
}
public function act(int $broadcastId, int $peer, Cancellation $cancellation): void
{
throw new LogicException("todo")
try {
foreach ($this->messages as $message) {
if ($cancellation->isRequested()) {
return;
}
$this->API->methodCallAsyncRead(
'messages.sendMessage',
\array_merge($message, ['to_peer' => $peer]),
['FloodWaitLimit' => 2*86400]
);
}
} catch (RPCErrorException $e) {
if ($e->rpc === 'INPUT_USER_DEACTIVATED') {
return;
}
if ($e->rpc === 'USER_IS_BOT') {
return;
}
if ($e->rpc === 'CHAT_WRITE_FORBIDDEN') {
return;
}
if ($e->rpc === 'USER_IS_BLOCKED') {
return;
}
if ($e->rpc === 'PEER_ID_INVALID') {
return;
}
throw $e;
}
}
}

View File

@ -32,18 +32,62 @@ trait Broadcast
{
/** @var array<int, InternalState> */
private array $broadcasts = [];
/**
* Sends a list of messages to all peers (users, chats, channels) of the bot.
*
* A simplified version of this method is also available: broadcastForwardMessages can work with pre-prepared messages.
*
* Will return an integer ID that can be used to:
*
* - Get the current broadcast progress with getBroadcastProgress
* - Cancel the broadcast using cancelBroadcast
*
* Note that to avoid manually polling the progress,
* MadelineProto will also periodically emit updateBroadcastProgress updates,
* containing a Progress object for all broadcasts currently in-progress.
*
* @param array $messages The messages to send: an array of arrays, containing parameters to pass to messages.sendMessage.
*/
public function broadcastMessages(array $messages): int
{
return $this->broadcastCustom(new ActionSend($this, $messages));
}
/**
* @param list<int> $ids
* Forwards a list of messages to all peers (users, chats, channels) of the bot.
*
* Will return an integer ID that can be used to:
*
* - Get the current broadcast progress with getBroadcastProgress
* - Cancel the broadcast using cancelBroadcast
*
* Note that to avoid manually polling the progress,
* MadelineProto will also periodically emit updateBroadcastProgress updates,
* containing a Progress object for all broadcasts currently in-progress.
*
* @param mixed $from_peer Bot API ID or Update, from where to forward the messages.
* @param list<int> $ids IDs of the messages to forward.
* @param bool $drop_author If true, will forward messages without quoting the original author.
*/
public function broadcastForwardMessages(mixed $from_peer, array $ids, bool $drop_author = false): int
{
return $this->broadcastCustom(new ActionForward($this, $this->getID($from_peer), $ids, $drop_author));
}
/**
* Executes a custom broadcast action with all peers (users, chats, channels) of the bot.
*
* Will return an integer ID that can be used to:
*
* - Get the current broadcast progress with getBroadcastProgress
* - Cancel the broadcast using cancelBroadcast
*
* Note that to avoid manually polling the progress,
* MadelineProto will also periodically emit updateBroadcastProgress updates,
* containing a Progress object for all broadcasts currently in-progress.
*
* @param Action $action A custom, serializable Action class that will be called once for every peer.
*/
public function broadcastCustom(Action $action): int
{
$id = \count($this->broadcasts);

View File

@ -21,7 +21,7 @@ interface DbArray extends DbType, ArrayAccess, Countable
/**
* Get Array copy.
*
* @return array<TKey, TValue>
* @psalm-return array<TKey, TValue>
*/
public function getArrayCopy(): array;
/**

View File

@ -229,19 +229,60 @@ abstract class InternalDoc
{
return $this->wrapper->getAPI()->botLogin($token);
}
/**
* Executes a custom broadcast action with all peers (users, chats, channels) of the bot.
*
* Will return an integer ID that can be used to:
*
* - Get the current broadcast progress with getBroadcastProgress
* - Cancel the broadcast using cancelBroadcast
*
* Note that to avoid manually polling the progress,
* MadelineProto will also periodically emit updateBroadcastProgress updates,
* containing a Progress object for all broadcasts currently in-progress.
*
* @param Action $action A custom, serializable Action class that will be called once for every peer.
*/
public function broadcastCustom(\danog\MadelineProto\Broadcast\Action $action): int
{
return $this->wrapper->getAPI()->broadcastCustom($action);
}
/**
* @param list<int> $ids
* Forwards a list of messages to all peers (users, chats, channels) of the bot.
*
* Will return an integer ID that can be used to:
*
* - Get the current broadcast progress with getBroadcastProgress
* - Cancel the broadcast using cancelBroadcast
*
* Note that to avoid manually polling the progress,
* MadelineProto will also periodically emit updateBroadcastProgress updates,
* containing a Progress object for all broadcasts currently in-progress.
*
* @param mixed $from_peer Bot API ID or Update, from where to forward the messages.
* @param list<int> $ids IDs of the messages to forward.
* @param bool $drop_author If true, will forward messages without quoting the original author.
*/
public function broadcastForwardMessages(mixed $from_peer, array $ids, bool $drop_author = false): int
{
return $this->wrapper->getAPI()->broadcastForwardMessages($from_peer, $ids, $drop_author);
}
/**
* Sends a list of messages to all peers (users, chats, channels) of the bot.
*
* A simplified version of this method is also available: broadcastForwardMessages can work with pre-prepared messages.
*
* Will return an integer ID that can be used to:
*
* - Get the current broadcast progress with getBroadcastProgress
* - Cancel the broadcast using cancelBroadcast
*
* Note that to avoid manually polling the progress,
* MadelineProto will also periodically emit updateBroadcastProgress updates,
* containing a Progress object for all broadcasts currently in-progress.
*
* @param array $messages The messages to send: an array of arrays, containing parameters to pass to messages.sendMessage.
*/
public function broadcastMessages(array $messages): int
{
return $this->wrapper->getAPI()->broadcastMessages($messages);

View File

@ -60,7 +60,7 @@ final class Redis extends DriverDatabaseAbstract
*
* @param string $uri Database URI.
*/
public function setUri(string $uri): self
public function setUri(string $uri): static
{
$this->uri = $uri;

View File

@ -78,6 +78,7 @@ $order = [
'FEATURES',
'REQUIREMENTS',
'INSTALLATION',
'BROADCAST',
'UPDATES',
'DATABASE',
'SETTINGS',
@ -208,4 +209,4 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
---
'.$readme);
#include 'phpdoc.php';
include 'phpdoc.php';