From cfb509f350c3e4f74ed854e0aee20cea89aa135c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 31 Aug 2023 17:18:56 +0200 Subject: [PATCH 01/14] Fixes --- README.md | 1 + examples/simpleBot.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c5bcd989..04630fd89 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ The following open source projects were created using MadelineProto: you can dir * [magnaluna webradio](https://magna.madelineproto.xyz) - Multifeatured Telegram VoIP webradio * [TelegramApiServer](https://github.com/xtrime-ru/TelegramApiServer) - Fast, simple, async php telegram api server: an HTTP JSON API for MadelineProto! +* [`simpleBot.php`](https://github.com/danog/MadelineProto/blob/v8/examples/simpleBot.php) - Extremely basic example * [`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! diff --git a/examples/simpleBot.php b/examples/simpleBot.php index f0cc22f1f..09b31d069 100644 --- a/examples/simpleBot.php +++ b/examples/simpleBot.php @@ -12,7 +12,7 @@ use danog\MadelineProto\EventHandler\Message; use danog\MadelineProto\EventHandler\SimpleFilter\Incoming; use danog\MadelineProto\SimpleEventHandler; -// Load via composer +// Load via composer (RECOMMENDED, see https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-scratch) if (file_exists('vendor/autoload.php')) { require_once 'vendor/autoload.php'; } else { From 9bca88520f344abb94d1aebaade58e4d49e82d1d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 31 Aug 2023 17:21:27 +0200 Subject: [PATCH 02/14] Improve assertions --- src/MTProtoTools/FilesAbstraction.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/MTProtoTools/FilesAbstraction.php b/src/MTProtoTools/FilesAbstraction.php index 48561ae9c..e86943293 100644 --- a/src/MTProtoTools/FilesAbstraction.php +++ b/src/MTProtoTools/FilesAbstraction.php @@ -88,7 +88,10 @@ trait FilesAbstraction return new VideoSticker($this, $media, $attr, $has_video, $protected); } - \assert($has_document_photo !== null); + if ($has_document_photo === null) { + throw new AssertionError("has_document_photo === null: ".json_encode($media['document'])); + } + if ($attr['mask']) { return new MaskSticker($this, $media, $attr, $has_document_photo, $protected); } @@ -109,12 +112,16 @@ trait FilesAbstraction : new Audio($this, $media, $attr, $protected); } if ($t === 'documentAttributeCustomEmoji') { - \assert($has_document_photo !== null); + if ($has_document_photo === null) { + throw new AssertionError("has_document_photo === null: ".json_encode($media['document'])); + } return new CustomEmoji($this, $media, $attr, $has_document_photo, $protected); } } if ($has_animated) { - \assert($has_video !== null); + if ($has_video === null) { + throw new AssertionError("has_video === null: ".json_encode($media['document'])); + } return new Gif($this, $media, $has_video, $protected); } if ($has_video) { From 7cfa8613479fc1f09c492dcf4335550a4c900dff Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 31 Aug 2023 18:02:11 +0200 Subject: [PATCH 03/14] Psalm fixes --- README.md | 7 ++ psalm-baseline.xml | 90 ++++++++----------- src/EventHandler/AbstractMessage.php | 2 +- src/EventHandler/Media/Gif.php | 6 +- src/EventHandler/Message/ChannelMessage.php | 16 ++-- .../Message/Entities/MessageEntity.php | 11 ++- src/EventHandler/Message/GroupMessage.php | 11 ++- src/EventHandler/Message/PrivateMessage.php | 3 +- .../Service/AbstractDialogGroupCall.php | 3 + .../Message/Service/DialogChannelCreated.php | 2 +- .../Message/Service/DialogGameScore.php | 2 +- .../Message/Service/DialogPhoneCall.php | 2 +- .../Message/Service/DialogTopicEdited.php | 2 +- src/EventHandler/Participant.php | 5 +- src/EventHandler/Participant/Admin.php | 4 +- src/EventHandler/Participant/Banned.php | 7 +- src/EventHandler/Participant/Creator.php | 4 +- src/EventHandler/Participant/Left.php | 10 +-- src/EventHandler/Participant/Member.php | 4 +- src/EventHandler/Participant/MySelf.php | 4 +- src/EventHandler/Participant/Rights.php | 2 +- src/EventHandler/Participant/Rights/Admin.php | 8 +- .../Participant/Rights/Banned.php | 2 +- src/InternalDoc.php | 13 ++- src/MTProtoTools/FilesAbstraction.php | 6 +- src/MTProtoTools/UpdateHandler.php | 20 ++--- src/StrTools.php | 6 +- src/VoIP/DiscardReason.php | 5 +- tools/build_docs.php | 3 + 29 files changed, 134 insertions(+), 126 deletions(-) diff --git a/README.md b/README.md index 04630fd89..a05da8cc8 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,13 @@ Want to add your own open-source project to this list? [Click here!](https://doc * [danog\MadelineProto\Broadcast\Progress »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/Broadcast/Progress.html) * [Full property list »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/Broadcast/Progress.html#properties) * [Full bound method list »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/Broadcast/Progress.html#method-list) + * [danog\MadelineProto\EventHandler\Message\Service\DialogChannelMigrateFrom »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChannelMigrateFrom.html) - Indicates the channel was [migrated](https://core.telegram.org/api/channel) + * [danog\MadelineProto\EventHandler\Message\Service\DialogChatMigrateTo »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogChatMigrateTo.html) - Indicates the chat was [migrated](https://core.telegram.org/api/channel) + * [danog\MadelineProto\EventHandler\Message\Service\DialogPeerRequested »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPeerRequested.html) - Contains info about a peer that the user shared with the bot after clicking on a [keyboardButtonRequestPeer](https://docs.madelineproto.xyz/API_docs/constructors/keyboardButtonRequestPeer.html) + * [danog\MadelineProto\EventHandler\Message\Service\DialogSuggestProfilePhoto »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogSuggestProfilePhoto.html) - A new profile picture was suggested using [photos.uploadContactProfilePhoto](https://docs.madelineproto.xyz/API_docs/methods/photos.uploadContactProfilePhoto.html) + * [danog\MadelineProto\EventHandler\Message\Service\DialogTopicCreated »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTopicCreated.html) - A [forum topic](https://core.telegram.org/api/forum#forum-topics) + * [danog\MadelineProto\EventHandler\Message\Service\DialogTopicEdited »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogTopicEdited.html) - [Forum topic](https://core.telegram.org/api/forum#forum-topics) + * [danog\MadelineProto\EventHandler\Message\Service\DialogWebView »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogWebView.html) - Data from an opened [reply keyboard bot web app](https://core.telegram.org/api/bots/webapps) was relayed to the bot that owns it (user & bot side service message) * [danog\MadelineProto\VoIP »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/VoIP.html) * [Full property list »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/VoIP.html#properties) * [Full bound method list »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/VoIP.html#method-list) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f91102be5..1207ef69c 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -412,8 +412,15 @@ replyCache]]> replyCache]]> + + - $replyCache + $peerResolved + + + + + $peersResolved @@ -421,16 +428,6 @@ $adminIds - - - $peerResolved - - - - - $peersResolved - - $peerResolved @@ -440,13 +437,9 @@ $matches $matches + $matches - - - $peerResolved - - botApiFileId]]> @@ -560,10 +553,6 @@ - - entities]]> - entities]]> - getClient()->wrapMessage($this->getClient()->extractMessage($result))]]> @@ -576,7 +565,6 @@ $html $htmlTelegram - Message ChannelMessage ChannelMessage - ChannelMessage GroupMessage GroupMessage - GroupMessage + + getClient()->wrapMessage($this->getClient()->extractMessage($result))]]> + + + DialogScreenshotTaken + + + getClient()->wrapMessage($this->getClient()->extractMessage($result))]]> + PrivateMessage PrivateMessage - PrivateMessage - - - DialogCreated - + + + getIdInternal($rawParticipant['peer'])]]> + - - - DialogMemberLeft - - - - - DialogMembersJoined - - - - - DialogMessagePinned - - - - - DialogPhotoChanged - - - - - DialogTitleChanged - + + + getIdInternal($rawParticipant['peer'])]]> + @@ -1609,6 +1583,10 @@ '_' => 'messageMediaPhoto', 'photo' => $message['action']['photo'] ])]]> + wrapMedia([ + '_' => 'messageMediaPhoto', + 'photo' => $message['action']['photo'] + ])]]> nextSent]]> @@ -1620,6 +1598,11 @@ getUpdatesState loadUpdateState + + getIdInternal($message['action']['from_id'])]]> + getIdInternal($message['action']['peer'])]]> + getIdInternal($message['action']['to_id'])]]> + authorization['user']]]> authorization['user']]]> @@ -1801,6 +1784,9 @@ + + $entities + diff --git a/src/EventHandler/AbstractMessage.php b/src/EventHandler/AbstractMessage.php index 5e4e60519..62188f4f2 100644 --- a/src/EventHandler/AbstractMessage.php +++ b/src/EventHandler/AbstractMessage.php @@ -117,7 +117,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters return $this->replyToMsgId !== null; } - protected readonly ?self $replyCache; + protected ?self $replyCache = null; protected bool $replyCached = false; /** * Get replied-to message. diff --git a/src/EventHandler/Media/Gif.php b/src/EventHandler/Media/Gif.php index dab897aa1..db5b29efd 100644 --- a/src/EventHandler/Media/Gif.php +++ b/src/EventHandler/Media/Gif.php @@ -45,9 +45,8 @@ final class Gif extends AbstractVideo } /** - * Add GIF to saved gifs list + * Add GIF to saved gifs list. * - * @return bool */ public function save(): bool { @@ -61,9 +60,8 @@ final class Gif extends AbstractVideo } /** - * Remove GIF from saved gifs list + * Remove GIF from saved gifs list. * - * @return bool */ public function unsave(): bool { diff --git a/src/EventHandler/Message/ChannelMessage.php b/src/EventHandler/Message/ChannelMessage.php index 851688ff9..6e21fe76a 100644 --- a/src/EventHandler/Message/ChannelMessage.php +++ b/src/EventHandler/Message/ChannelMessage.php @@ -18,14 +18,14 @@ namespace danog\MadelineProto\EventHandler\Message; use AssertionError; use danog\MadelineProto\EventHandler\Message; -use danog\MadelineProto\MTProto; use danog\MadelineProto\EventHandler\Participant; -use danog\MadelineProto\EventHandler\Participant\Left; use danog\MadelineProto\EventHandler\Participant\Admin; -use danog\MadelineProto\EventHandler\Participant\Member; -use danog\MadelineProto\EventHandler\Participant\MySelf; use danog\MadelineProto\EventHandler\Participant\Banned; use danog\MadelineProto\EventHandler\Participant\Creator; +use danog\MadelineProto\EventHandler\Participant\Left; +use danog\MadelineProto\EventHandler\Participant\Member; +use danog\MadelineProto\EventHandler\Participant\MySelf; +use danog\MadelineProto\MTProto; /** * Represents an incoming or outgoing channel message. @@ -42,7 +42,7 @@ final class ChannelMessage extends Message } /** - * Disable message signatures in channels + * Disable message signatures in channels. */ public function disableSignatures(): void { @@ -56,7 +56,7 @@ final class ChannelMessage extends Message } /** - * Enable message signatures in channels + * Enable message signatures in channels. */ public function enableSignatures(): void { @@ -70,16 +70,14 @@ final class ChannelMessage extends Message } /** - * Get info about a [channel/supergroup](https://core.telegram.org/api/channel) participant + * Get info about a [channel/supergroup](https://core.telegram.org/api/channel) participant. * * @param string|integer $member Participant to get info about. - * @return Participant * @throws AssertionError */ public function getMember(string|int $member): Participant { $client = $this->getClient(); - $member = $client->getId($member); $result = $client->methodCallAsyncRead( 'channels.getParticipant', [ diff --git a/src/EventHandler/Message/Entities/MessageEntity.php b/src/EventHandler/Message/Entities/MessageEntity.php index 875e007eb..ada5721c7 100644 --- a/src/EventHandler/Message/Entities/MessageEntity.php +++ b/src/EventHandler/Message/Entities/MessageEntity.php @@ -23,9 +23,13 @@ abstract class MessageEntity implements JsonSerializable $this->length = $rawEntities['length']; } - public static function fromRawEntities(array $entities) + /** + * @param list $entities + * @return list + */ + public static function fromRawEntities(array $entities): array { - $create = static fn (array $entity): MessageEntity => match ($entity['_']) { + return \array_map(static fn (array $entity): MessageEntity => match ($entity['_']) { 'messageEntityMention' => new Mention($entity), 'messageEntityHashtag' => new Hashtag($entity), 'messageEntityBotCommand' => new BotCommand($entity), @@ -46,8 +50,7 @@ abstract class MessageEntity implements JsonSerializable 'messageEntitySpoiler' => new Spoiler($entity), 'messageEntityCustomEmoji' => new CustomEmoji($entity), default => new Unknown($entity) - }; - return \array_map(fn (array $entity) => $create($entity), $entities); + }, $entities); } /** @internal */ public function jsonSerialize(): mixed diff --git a/src/EventHandler/Message/GroupMessage.php b/src/EventHandler/Message/GroupMessage.php index e68ba9a9f..cbc9861d7 100644 --- a/src/EventHandler/Message/GroupMessage.php +++ b/src/EventHandler/Message/GroupMessage.php @@ -19,29 +19,28 @@ namespace danog\MadelineProto\EventHandler\Message; use AssertionError; use danog\MadelineProto\EventHandler\Message; use danog\MadelineProto\EventHandler\Participant; -use danog\MadelineProto\EventHandler\Participant\Left; use danog\MadelineProto\EventHandler\Participant\Admin; -use danog\MadelineProto\EventHandler\Participant\Member; -use danog\MadelineProto\EventHandler\Participant\MySelf; use danog\MadelineProto\EventHandler\Participant\Banned; use danog\MadelineProto\EventHandler\Participant\Creator; +use danog\MadelineProto\EventHandler\Participant\Left; +use danog\MadelineProto\EventHandler\Participant\Member; +use danog\MadelineProto\EventHandler\Participant\MySelf; + /** * Represents an incoming or outgoing group message. */ final class GroupMessage extends Message { /** - * Get info about a [channel/supergroup](https://core.telegram.org/api/channel) participant + * Get info about a [channel/supergroup](https://core.telegram.org/api/channel) participant. * * @param string|integer|null $member Participant to get info about; can be empty or null to get info about the sender of the message. - * @return Participant * @throws AssertionError */ public function getMember(string|int|null $member = null): Participant { $client = $this->getClient(); $member ??= $this->senderId; - $member = $client->getId($member); $result = $client->methodCallAsyncRead( 'channels.getParticipant', [ diff --git a/src/EventHandler/Message/PrivateMessage.php b/src/EventHandler/Message/PrivateMessage.php index 109e2be5c..ce2467c23 100644 --- a/src/EventHandler/Message/PrivateMessage.php +++ b/src/EventHandler/Message/PrivateMessage.php @@ -25,9 +25,8 @@ use danog\MadelineProto\EventHandler\Message\Service\DialogScreenshotTaken; final class PrivateMessage extends Message { /** - * Notify the other user in a private chat that a screenshot of the chat was taken + * Notify the other user in a private chat that a screenshot of the chat was taken. * - * @return DialogScreenshotTaken */ public function screenShot(): DialogScreenshotTaken { diff --git a/src/EventHandler/Message/Service/AbstractDialogGroupCall.php b/src/EventHandler/Message/Service/AbstractDialogGroupCall.php index 45dc74c3e..d005b30b6 100644 --- a/src/EventHandler/Message/Service/AbstractDialogGroupCall.php +++ b/src/EventHandler/Message/Service/AbstractDialogGroupCall.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto\EventHandler\Message\Service; use danog\MadelineProto\EventHandler\Message\ServiceMessage; use danog\MadelineProto\MTProto; +/** + * Represents a service message about a group call. + */ abstract class AbstractDialogGroupCall extends ServiceMessage { /** @internal */ diff --git a/src/EventHandler/Message/Service/DialogChannelCreated.php b/src/EventHandler/Message/Service/DialogChannelCreated.php index 55bff9553..94e5c2f6d 100644 --- a/src/EventHandler/Message/Service/DialogChannelCreated.php +++ b/src/EventHandler/Message/Service/DialogChannelCreated.php @@ -20,7 +20,7 @@ use danog\MadelineProto\EventHandler\Message\ServiceMessage; use danog\MadelineProto\MTProto; /** - * The channel was created + * The channel was created. */ final class DialogChannelCreated extends ServiceMessage { diff --git a/src/EventHandler/Message/Service/DialogGameScore.php b/src/EventHandler/Message/Service/DialogGameScore.php index 7a6d5a78f..3effeaf35 100644 --- a/src/EventHandler/Message/Service/DialogGameScore.php +++ b/src/EventHandler/Message/Service/DialogGameScore.php @@ -28,7 +28,7 @@ final class DialogGameScore extends ServiceMessage MTProto $API, array $rawMessage, array $info, - + /** Game ID */ public readonly int $gameId, /** Score */ diff --git a/src/EventHandler/Message/Service/DialogPhoneCall.php b/src/EventHandler/Message/Service/DialogPhoneCall.php index 40df302b9..e8133b99e 100644 --- a/src/EventHandler/Message/Service/DialogPhoneCall.php +++ b/src/EventHandler/Message/Service/DialogPhoneCall.php @@ -17,8 +17,8 @@ namespace danog\MadelineProto\EventHandler\Message\Service; use danog\MadelineProto\EventHandler\Message\ServiceMessage; -use danog\MadelineProto\VoIP\DiscardReason; use danog\MadelineProto\MTProto; +use danog\MadelineProto\VoIP\DiscardReason; /** * A phone call. diff --git a/src/EventHandler/Message/Service/DialogTopicEdited.php b/src/EventHandler/Message/Service/DialogTopicEdited.php index 322541921..d6152a5f7 100644 --- a/src/EventHandler/Message/Service/DialogTopicEdited.php +++ b/src/EventHandler/Message/Service/DialogTopicEdited.php @@ -28,7 +28,7 @@ final class DialogTopicEdited extends ServiceMessage MTProto $API, array $rawMessage, array $info, - + /** Topic name. */ public readonly string $title, /** ID of the [custom emoji](https://core.telegram.org/api/custom-emoji) used as topic icon. */ diff --git a/src/EventHandler/Participant.php b/src/EventHandler/Participant.php index aa974b40d..db643b870 100644 --- a/src/EventHandler/Participant.php +++ b/src/EventHandler/Participant.php @@ -16,13 +16,12 @@ namespace danog\MadelineProto\EventHandler; -use danog\MadelineProto\MTProto; use JsonSerializable; use ReflectionClass; use ReflectionProperty; /** - * Info about a channel participant + * Info about a channel participant. */ abstract class Participant implements JsonSerializable { @@ -36,4 +35,4 @@ abstract class Participant implements JsonSerializable } return $res; } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/Admin.php b/src/EventHandler/Participant/Admin.php index f701a5c2a..a46129f08 100644 --- a/src/EventHandler/Participant/Admin.php +++ b/src/EventHandler/Participant/Admin.php @@ -20,7 +20,7 @@ use danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant\Rights\Admin as AdminRights; /** - * Admin + * Admin. */ final class Admin extends Participant { @@ -61,4 +61,4 @@ final class Admin extends Participant $this->rank = $rawParticipant['rank'] ?? 'admin'; $this->adminRights = new AdminRights($rawParticipant['admin_rights']); } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/Banned.php b/src/EventHandler/Participant/Banned.php index 96db2cf87..1a1010904 100644 --- a/src/EventHandler/Participant/Banned.php +++ b/src/EventHandler/Participant/Banned.php @@ -18,10 +18,11 @@ namespace danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant\Rights\Banned as BannedRights; +use danog\MadelineProto\Ipc\Client; use danog\MadelineProto\MTProto; /** - * Banned/kicked user + * Banned/kicked user. */ final class Banned extends Participant { @@ -42,11 +43,11 @@ final class Banned extends Participant /** @internal */ public function __construct( - MTProto $API, + MTProto|Client $API, array $rawParticipant ) { $this->left = $rawParticipant['left']; - $this->peer = $API->getIdInternal ($rawParticipant['peer']); + $this->peer = $API->getIdInternal($rawParticipant['peer']); $this->kickedBy = $rawParticipant['kicked_by']; $this->date = $rawParticipant['date']; $this->bannedRights = new BannedRights($rawParticipant['banned_rights']); diff --git a/src/EventHandler/Participant/Creator.php b/src/EventHandler/Participant/Creator.php index cd599de51..cff69d21f 100644 --- a/src/EventHandler/Participant/Creator.php +++ b/src/EventHandler/Participant/Creator.php @@ -20,7 +20,7 @@ use danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant\Rights\Admin as AdminRights; /** - * Channel/supergroup creator + * Channel/supergroup creator. */ final class Creator extends Participant { @@ -41,4 +41,4 @@ final class Creator extends Participant $this->adminRights = new AdminRights($rawParticipant['adminRights']); $this->rank = $rawParticipant['rank'] ?? 'Owner'; } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/Left.php b/src/EventHandler/Participant/Left.php index 7cd6d5b25..df7253bf6 100644 --- a/src/EventHandler/Participant/Left.php +++ b/src/EventHandler/Participant/Left.php @@ -17,22 +17,22 @@ namespace danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant; +use danog\MadelineProto\Ipc\Client; use danog\MadelineProto\MTProto; /** - * A participant that left the channel/supergroup + * A participant that left the channel/supergroup. */ final class Left extends Participant { - /** The peer that left */ public readonly int $peer; /** @internal */ public function __construct( - MTProto $API, + MTProto|Client $API, array $rawParticipant ) { - $this->peer = $API->getIdInternal ($rawParticipant['peer']); + $this->peer = $API->getIdInternal($rawParticipant['peer']); } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/Member.php b/src/EventHandler/Participant/Member.php index 36eccca9b..1690c1e43 100644 --- a/src/EventHandler/Participant/Member.php +++ b/src/EventHandler/Participant/Member.php @@ -19,7 +19,7 @@ namespace danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant; /** - * Channel/supergroup participant + * Channel/supergroup participant. */ final class Member extends Participant { @@ -36,4 +36,4 @@ final class Member extends Participant $this->userId = $rawParticipant['user_id']; $this->date = $rawParticipant['date']; } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/MySelf.php b/src/EventHandler/Participant/MySelf.php index aaff1ed4a..328e5ab3c 100644 --- a/src/EventHandler/Participant/MySelf.php +++ b/src/EventHandler/Participant/MySelf.php @@ -19,7 +19,7 @@ namespace danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant; /** - * Myself + * Myself. */ final class MySelf extends Participant { @@ -44,4 +44,4 @@ final class MySelf extends Participant $this->inviterId = $rawParticipant['inviter_id'] ?? null; $this->date = $rawParticipant['date']; } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/Rights.php b/src/EventHandler/Participant/Rights.php index 4e78fa5e4..1d0aff928 100644 --- a/src/EventHandler/Participant/Rights.php +++ b/src/EventHandler/Participant/Rights.php @@ -32,4 +32,4 @@ abstract class Rights implements JsonSerializable } return $res; } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/Rights/Admin.php b/src/EventHandler/Participant/Rights/Admin.php index 2f6158dd0..81b931aee 100644 --- a/src/EventHandler/Participant/Rights/Admin.php +++ b/src/EventHandler/Participant/Rights/Admin.php @@ -28,7 +28,7 @@ final class Admin extends Rights /** If set, allows the admin to post messages in the [channel](https://core.telegram.org/api/channel) */ public readonly bool $postMessages; - + /** If set, allows the admin to also edit messages from other admins in the [channel](https://core.telegram.org/api/channel) */ public readonly bool $editMessages; @@ -53,10 +53,10 @@ final class Admin extends Rights /** If set, allows the admin to change group call/livestream settings */ public readonly bool $manageCall; - /** Set this flag if none of the other flags are set, + /** Set this flag if none of the other flags are set, * but you still want the user to be an admin: if this or any of the other flags are set, * the admin can get the chat [admin log](https://core.telegram.org/api/recent-actions), get [chat statistics](https://core.telegram.org/api/stats), get [message statistics in channels](https://core.telegram.org/api/stats), get channel members, - * see anonymous administrators in supergroups and ignore slow mode. + * see anonymous administrators in supergroups and ignore slow mode. */ public readonly bool $other; @@ -80,4 +80,4 @@ final class Admin extends Rights $this->other = $rawRights['other']; $this->manageTopics = $rawRights['manage_topics']; } -} \ No newline at end of file +} diff --git a/src/EventHandler/Participant/Rights/Banned.php b/src/EventHandler/Participant/Rights/Banned.php index becb73e04..ade9dcc85 100644 --- a/src/EventHandler/Participant/Rights/Banned.php +++ b/src/EventHandler/Participant/Rights/Banned.php @@ -108,4 +108,4 @@ final class Banned extends Rights $this->sendPlain = $rawRights['send_plain']; $this->untilDate = $rawRights['until_date']; } -} \ No newline at end of file +} diff --git a/src/InternalDoc.php b/src/InternalDoc.php index dbe5e72cb..9715a3924 100644 --- a/src/InternalDoc.php +++ b/src/InternalDoc.php @@ -26,6 +26,17 @@ use danog\MadelineProto\EventHandler\Media\Document; use danog\MadelineProto\EventHandler\Media\Photo; use danog\MadelineProto\EventHandler\Media\Video; use danog\MadelineProto\EventHandler\Message; +use danog\MadelineProto\EventHandler\Message\Entities\Code; +use danog\MadelineProto\EventHandler\Message\Entities\Email; +use danog\MadelineProto\EventHandler\Message\Entities\Mention; +use danog\MadelineProto\EventHandler\Message\Entities\MessageEntity; +use danog\MadelineProto\EventHandler\Message\Entities\Phone; +use danog\MadelineProto\EventHandler\Message\Entities\Pre; +use danog\MadelineProto\EventHandler\Message\Entities\Spoiler; +use danog\MadelineProto\EventHandler\Message\Entities\Url; +use danog\MadelineProto\EventHandler\Participant\Admin; +use danog\MadelineProto\EventHandler\Participant\Member; +use danog\MadelineProto\EventHandler\Participant\Rights\Admin; use danog\MadelineProto\EventHandler\Update; use danog\MadelineProto\Ipc\Client; use danog\MadelineProto\Ipc\EventHandlerProxy; @@ -501,7 +512,7 @@ abstract class InternalDoc /** * Convert a message and a set of entities to HTML. * - * @param list $entities + * @param list $entities * @param bool $allowTelegramTags Whether to allow telegram-specific tags like tg-spoiler, tg-emoji, mention links and so on... */ public static function entitiesToHtml(string $message, array $entities, bool $allowTelegramTags = false): string diff --git a/src/MTProtoTools/FilesAbstraction.php b/src/MTProtoTools/FilesAbstraction.php index e86943293..6878ce62f 100644 --- a/src/MTProtoTools/FilesAbstraction.php +++ b/src/MTProtoTools/FilesAbstraction.php @@ -89,7 +89,7 @@ trait FilesAbstraction } if ($has_document_photo === null) { - throw new AssertionError("has_document_photo === null: ".json_encode($media['document'])); + throw new AssertionError("has_document_photo === null: ".\json_encode($media['document'])); } if ($attr['mask']) { @@ -113,14 +113,14 @@ trait FilesAbstraction } if ($t === 'documentAttributeCustomEmoji') { if ($has_document_photo === null) { - throw new AssertionError("has_document_photo === null: ".json_encode($media['document'])); + throw new AssertionError("has_document_photo === null: ".\json_encode($media['document'])); } return new CustomEmoji($this, $media, $attr, $has_document_photo, $protected); } } if ($has_animated) { if ($has_video === null) { - throw new AssertionError("has_video === null: ".json_encode($media['document'])); + throw new AssertionError("has_video === null: ".\json_encode($media['document'])); } return new Gif($this, $media, $has_video, $protected); } diff --git a/src/MTProtoTools/UpdateHandler.php b/src/MTProtoTools/UpdateHandler.php index bdd6430d5..41355007e 100644 --- a/src/MTProtoTools/UpdateHandler.php +++ b/src/MTProtoTools/UpdateHandler.php @@ -32,11 +32,18 @@ use danog\MadelineProto\EventHandler\Message; use danog\MadelineProto\EventHandler\Message\ChannelMessage; use danog\MadelineProto\EventHandler\Message\GroupMessage; use danog\MadelineProto\EventHandler\Message\PrivateMessage; +use danog\MadelineProto\EventHandler\Message\Service\DialogChannelCreated; +use danog\MadelineProto\EventHandler\Message\Service\DialogChannelMigrateFrom; use danog\MadelineProto\EventHandler\Message\Service\DialogChatJoinedByLink; +use danog\MadelineProto\EventHandler\Message\Service\DialogChatMigrateTo; use danog\MadelineProto\EventHandler\Message\Service\DialogContactSignUp; use danog\MadelineProto\EventHandler\Message\Service\DialogCreated; use danog\MadelineProto\EventHandler\Message\Service\DialogGameScore; use danog\MadelineProto\EventHandler\Message\Service\DialogGeoProximityReached; +use danog\MadelineProto\EventHandler\Message\Service\DialogGiftPremium; +use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallEnded; +use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallInvited; +use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallScheduled; use danog\MadelineProto\EventHandler\Message\Service\DialogHistoryCleared; use danog\MadelineProto\EventHandler\Message\Service\DialogMemberJoinedByRequest; use danog\MadelineProto\EventHandler\Message\Service\DialogMemberLeft; @@ -44,22 +51,15 @@ use danog\MadelineProto\EventHandler\Message\Service\DialogMembersJoined; use danog\MadelineProto\EventHandler\Message\Service\DialogMessagePinned; use danog\MadelineProto\EventHandler\Message\Service\DialogPeerRequested; use danog\MadelineProto\EventHandler\Message\Service\DialogPhoneCall; -use danog\MadelineProto\EventHandler\Message\Service\DialogChannelCreated; -use danog\MadelineProto\EventHandler\Message\Service\DialogChannelMigrateFrom; -use danog\MadelineProto\EventHandler\Message\Service\DialogChatMigrateTo; use danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged; -use danog\MadelineProto\EventHandler\Message\Service\DialogTitleChanged; use danog\MadelineProto\EventHandler\Message\Service\DialogScreenshotTaken; use danog\MadelineProto\EventHandler\Message\Service\DialogSetChatTheme; use danog\MadelineProto\EventHandler\Message\Service\DialogSetTTL; use danog\MadelineProto\EventHandler\Message\Service\DialogSuggestProfilePhoto; +use danog\MadelineProto\EventHandler\Message\Service\DialogTitleChanged; use danog\MadelineProto\EventHandler\Message\Service\DialogTopicCreated; use danog\MadelineProto\EventHandler\Message\Service\DialogTopicEdited; use danog\MadelineProto\EventHandler\Message\Service\DialogWebView; -use danog\MadelineProto\EventHandler\Message\Service\DialogGiftPremium; -use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallEnded; -use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallInvited; -use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallScheduled; use danog\MadelineProto\EventHandler\Query\ChatButtonQuery; use danog\MadelineProto\EventHandler\Query\ChatGameQuery; use danog\MadelineProto\EventHandler\Query\InlineButtonQuery; @@ -440,13 +440,13 @@ trait UpdateHandler $this, $message, $info, - $message['action']['inviter_id'], + $message['action']['inviter_id'], ), 'messageActionChannelCreate' => new DialogChannelCreated( $this, $message, $info, - $message['action']['title'], + $message['action']['title'], ), 'messageActionChatMigrateTo' => new DialogChatMigrateTo( $this, diff --git a/src/StrTools.php b/src/StrTools.php index a207d693f..b647591ea 100644 --- a/src/StrTools.php +++ b/src/StrTools.php @@ -133,14 +133,16 @@ abstract class StrTools extends Extension /** * Convert a message and a set of entities to HTML. * - * @param list $entities + * @param list $entities * @param bool $allowTelegramTags Whether to allow telegram-specific tags like tg-spoiler, tg-emoji, mention links and so on... */ public static function entitiesToHtml(string $message, array $entities, bool $allowTelegramTags = false): string { $insertions = []; + if (isset($entities[0]) && \is_array($entities[0])) { + $entities = MessageEntity::fromRawEntities($entities); + } foreach ($entities as $entity) { - $entity = isset($entity) && \is_array($entity) ? MessageEntity::fromRawEntities([$entity])[0] : $entity; [$offset, $length] = [$entity->offset, $entity->length]; $insertions[$offset] ??= ''; $insertions[$offset] .= match (true) { diff --git a/src/VoIP/DiscardReason.php b/src/VoIP/DiscardReason.php index 2329b96bb..d1c7a6c43 100644 --- a/src/VoIP/DiscardReason.php +++ b/src/VoIP/DiscardReason.php @@ -39,14 +39,13 @@ enum DiscardReason implements JsonSerializable /** * @internal - * - * @param ?string * @throws AssertionError */ public static function fromString(?string $name): ?DiscardReason { - if ($name === null) + if ($name === null) { return null; + } $newName = \strtoupper(\substr($name, 22)); foreach (DiscardReason::cases() as $case) { if ($case->name === $newName) { diff --git a/tools/build_docs.php b/tools/build_docs.php index 0ac0ecbc4..9a0c969b7 100755 --- a/tools/build_docs.php +++ b/tools/build_docs.php @@ -146,6 +146,9 @@ function printTypes(array $types, string $type): string } $refl = new ReflectionClass($class); $link = "https://docs.madelineproto.xyz/PHP/".str_replace('\\', '/', $class).'.html'; + if (!$refl->getDocComment()) { + throw new AssertionError("No documentation for $class!"); + } $f = $b->create($refl->getDocComment())->getSummary(); if ($refl->hasMethod('__construct')) { $c = $refl->getMethod('__construct'); From e7fc3ccc5349601c05ed3521f4b897d28e444264 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 31 Aug 2023 18:50:48 +0200 Subject: [PATCH 04/14] Fix --- docs | 2 +- src/AnnotationsBuilder.php | 6 ++++++ src/DocsBuilder/Methods.php | 2 +- src/InternalDoc.php | 1 - 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs b/docs index f9479b5ed..4600ecd20 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit f9479b5ed73a5140b98bb70bb48f3c8b3e551a38 +Subproject commit 4600ecd205dfda11d056ccf772e4f5a3b92db8a3 diff --git a/src/AnnotationsBuilder.php b/src/AnnotationsBuilder.php index 8774da303..e5de70eab 100644 --- a/src/AnnotationsBuilder.php +++ b/src/AnnotationsBuilder.php @@ -535,7 +535,13 @@ final class Blacklist { \fwrite($handle, "use Amp\\Cancellation;\n"); \fwrite($handle, "use Amp\\Http\\Server\\Request as ServerRequest;\n"); \fwrite($handle, "use danog\\MadelineProto\\Broadcast\\Action;\n"); + $had = []; foreach (ClassFinder::getClassesInNamespace(\danog\MadelineProto\EventHandler::class, ClassFinder::RECURSIVE_MODE) as $class) { + $name = \basename(\str_replace('\\', '//', $class)); + if (isset($had[$name])) { + continue; + } + $had[$name] = true; \fwrite($handle, "use $class;\n"); } /** @psalm-suppress UndefinedClass */ diff --git a/src/DocsBuilder/Methods.php b/src/DocsBuilder/Methods.php index 259ad382c..47ff9e7a4 100644 --- a/src/DocsBuilder/Methods.php +++ b/src/DocsBuilder/Methods.php @@ -225,7 +225,7 @@ trait Methods $header .= "YOU CANNOT USE THIS METHOD IN MADELINEPROTO\n\n\n\n\n"; } if (\in_array($method, ['messages.getHistory', 'messages.getMessages', 'channels.getMessages'], true)) { - $header .= "# Warning: flood wait\n**Warning: this method is prone to rate limiting with flood waits, please use the [updates event handler, instead »](/docs/UPDATES.html#async-event-driven)**\n\n"; + $header .= "# Warning: flood wait\n**Warning: this method is prone to rate limiting with flood waits, **which can lead to !!! ACCOUNT BANS !!!**, please use the [updates event handler, instead (which is 100% safe) »](/docs/UPDATES.html#async-event-driven)**\n\n"; $header .= "# Warning: non-realtime results\n**Warning: this method is not suitable for receiving messages in real-time from chats and users, please use the [updates event handler, instead »](/docs/UPDATES.html#async-event-driven)**\n\n"; $header .= "# Warning: this is probably NOT what you need\nYou probably need to use the [updates event handler, instead »](/docs/UPDATES.html#async-event-driven) :)\n\n"; } diff --git a/src/InternalDoc.php b/src/InternalDoc.php index 9715a3924..3afb86b80 100644 --- a/src/InternalDoc.php +++ b/src/InternalDoc.php @@ -36,7 +36,6 @@ use danog\MadelineProto\EventHandler\Message\Entities\Spoiler; use danog\MadelineProto\EventHandler\Message\Entities\Url; use danog\MadelineProto\EventHandler\Participant\Admin; use danog\MadelineProto\EventHandler\Participant\Member; -use danog\MadelineProto\EventHandler\Participant\Rights\Admin; use danog\MadelineProto\EventHandler\Update; use danog\MadelineProto\Ipc\Client; use danog\MadelineProto\Ipc\EventHandlerProxy; From ee9db1ab3fc10edbe3f82801553d44ce332283b6 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 14:51:30 +0200 Subject: [PATCH 05/14] Add pull request workflow --- .woodpecker/.build.yml | 1 + .woodpecker/test.yml | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .woodpecker/test.yml diff --git a/.woodpecker/.build.yml b/.woodpecker/.build.yml index 0cb190d78..cc9ca6a37 100644 --- a/.woodpecker/.build.yml +++ b/.woodpecker/.build.yml @@ -63,3 +63,4 @@ services: depends_on: - build-docker + - test \ No newline at end of file diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml new file mode 100644 index 000000000..1426ab435 --- /dev/null +++ b/.woodpecker/test.yml @@ -0,0 +1,47 @@ +matrix: + php: + - "8.1" + platform: + - linux/arm64 + +platform: ${platform} + +clone: + git: + when: + event: + - tag + - push + - pull_request + image: woodpeckerci/plugin-git:v1.5.0 + settings: + depth: 1 + lfs: false + recursive: false + tags: true + +pipeline: + test: + group: test + image: danog/madelineproto:next + when: + event: + - tag + - push + - pull_request + secrets: + - GITHUB_TOKEN + - API_ID + - API_HASH + - BOT_TOKEN + - DEST + environment: + - PHP_VERSION=${php} + - PLATFORM=${platform} + - TAG=${CI_COMMIT_TAG} + commands: + - apk add bash + - /bin/bash -e tests/test.sh + +depends_on: + - build-docker From 442f0792259091ee3bf050b077d6f62d75e7885e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 14:52:26 +0200 Subject: [PATCH 06/14] Update syntax --- .woodpecker/.build-docker.yml | 2 +- .woodpecker/.build.yml | 2 +- .woodpecker/.deploy-docker.yml | 2 +- .woodpecker/test.yml | 8 +------- docs | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.woodpecker/.build-docker.yml b/.woodpecker/.build-docker.yml index e724ebfca..25e154aaf 100644 --- a/.woodpecker/.build-docker.yml +++ b/.woodpecker/.build-docker.yml @@ -13,7 +13,7 @@ clone: recursive: false tags: true -pipeline: +steps: variants: image: docker:cli secrets: [docker_username, docker_password] diff --git a/.woodpecker/.build.yml b/.woodpecker/.build.yml index cc9ca6a37..0bc8fcf86 100644 --- a/.woodpecker/.build.yml +++ b/.woodpecker/.build.yml @@ -19,7 +19,7 @@ clone: recursive: false tags: true -pipeline: +steps: build: group: build image: danog/madelineproto:next diff --git a/.woodpecker/.deploy-docker.yml b/.woodpecker/.deploy-docker.yml index 609349047..c0d68d0ff 100644 --- a/.woodpecker/.deploy-docker.yml +++ b/.woodpecker/.deploy-docker.yml @@ -12,7 +12,7 @@ clone: recursive: false tags: true -pipeline: +steps: variants: image: docker:cli secrets: [docker_username, docker_password] diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 1426ab435..934f9d7ec 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -20,7 +20,7 @@ clone: recursive: false tags: true -pipeline: +steps: test: group: test image: danog/madelineproto:next @@ -29,12 +29,6 @@ pipeline: - tag - push - pull_request - secrets: - - GITHUB_TOKEN - - API_ID - - API_HASH - - BOT_TOKEN - - DEST environment: - PHP_VERSION=${php} - PLATFORM=${platform} diff --git a/docs b/docs index 4600ecd20..1eb6e9dae 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 4600ecd205dfda11d056ccf772e4f5a3b92db8a3 +Subproject commit 1eb6e9dae8e6dc51142a0ac4c37bc4b64ab568c3 From 48fa46d30a8cadc8aa53ebb95efe60b40e7cff10 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 14:53:46 +0200 Subject: [PATCH 07/14] Update syntax --- .woodpecker/.build-docker.yml | 2 +- .woodpecker/.build.yml | 2 +- .woodpecker/.deploy-docker.yml | 2 +- .woodpecker/test.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.woodpecker/.build-docker.yml b/.woodpecker/.build-docker.yml index 25e154aaf..9d9911a24 100644 --- a/.woodpecker/.build-docker.yml +++ b/.woodpecker/.build-docker.yml @@ -6,7 +6,7 @@ clone: event: - tag - push - image: woodpeckerci/plugin-git:v1.5.0 + image: woodpeckerci/plugin-git settings: depth: 1 lfs: false diff --git a/.woodpecker/.build.yml b/.woodpecker/.build.yml index 0bc8fcf86..75b4934b1 100644 --- a/.woodpecker/.build.yml +++ b/.woodpecker/.build.yml @@ -12,7 +12,7 @@ clone: event: - tag - push - image: woodpeckerci/plugin-git:v1.5.0 + image: woodpeckerci/plugin-git settings: depth: 1 lfs: false diff --git a/.woodpecker/.deploy-docker.yml b/.woodpecker/.deploy-docker.yml index c0d68d0ff..48a171aff 100644 --- a/.woodpecker/.deploy-docker.yml +++ b/.woodpecker/.deploy-docker.yml @@ -5,7 +5,7 @@ clone: when: event: - tag - image: woodpeckerci/plugin-git:v1.5.0 + image: woodpeckerci/plugin-git settings: depth: 1 lfs: false diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 934f9d7ec..ddaf0b53b 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -13,7 +13,7 @@ clone: - tag - push - pull_request - image: woodpeckerci/plugin-git:v1.5.0 + image: woodpeckerci/plugin-git settings: depth: 1 lfs: false From 692bde41db3f6f2dc9dea1875b168bdbb3ca84e1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 14:55:19 +0200 Subject: [PATCH 08/14] Remove build_docker dependency for test --- .woodpecker/test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index ddaf0b53b..1cc425ab7 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -35,7 +35,4 @@ steps: - TAG=${CI_COMMIT_TAG} commands: - apk add bash - - /bin/bash -e tests/test.sh - -depends_on: - - build-docker + - /bin/bash -e tests/test.sh \ No newline at end of file From 4290c569fd3852ce2c6c173027d2d331e3846e79 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 14:56:43 +0200 Subject: [PATCH 09/14] Add test.sh --- tests/test.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 tests/test.sh diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 000000000..df716e989 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +php composer-setup.php +php -r "unlink('composer-setup.php');" +mv composer.phar /usr/local/bin/composer + +apk add procps git unzip github-cli openssh + +composer update +composer build + From 8379bd8fc438b9e47e85c51453157f56b2d6c08d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 15:04:04 +0200 Subject: [PATCH 10/14] Update --- .woodpecker/test.yml | 2 +- README.md | 2 +- composer.json | 1 - src/EventHandler/Media.php | 2 +- src/Stream/ConnectionContext.php | 1 - tests/test.sh | 3 ++- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 1cc425ab7..069a1a349 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -35,4 +35,4 @@ steps: - TAG=${CI_COMMIT_TAG} commands: - apk add bash - - /bin/bash -e tests/test.sh \ No newline at end of file + - tests/test.sh \ No newline at end of file diff --git a/README.md b/README.md index a05da8cc8..f6c474e4b 100644 --- a/README.md +++ b/README.md @@ -347,7 +347,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc * Convert MTProto parameters to bot API parameters: MTProtoToBotAPI * Convert TD parameters to tdcli: tdToTdcli * Convert TD to MTProto parameters: tdToMTProto - * Convert a message and a set of entities to HTML: entitiesToHtml + * Convert a message and a set of entities to HTML: entitiesToHtml * Convert a supergroup to a gigagroup, when requested by channel suggestions: channels.convertToGigagroup * Convert bot API channel ID to MTProto channel ID: fromSupergroup * Convert bot API parameters to MTProto parameters: botAPIToMTProto diff --git a/composer.json b/composer.json index 7e568e8cc..5af9811f0 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,6 @@ "bamarni/composer-bin-plugin": "1.8.2", "symfony/yaml": "^6.0", "amphp/http-server": "^3", - "leproxy/leproxy": "^0.2.2", "revolt/event-loop-adapter-react": "^1", "dg/bypass-finals": "dev-master" }, diff --git a/src/EventHandler/Media.php b/src/EventHandler/Media.php index eedddedda..3e73e01b8 100644 --- a/src/EventHandler/Media.php +++ b/src/EventHandler/Media.php @@ -112,7 +112,7 @@ abstract class Media extends IpcCapable implements JsonSerializable /** * Get a readable amp stream with the file contents. * - * @param ?(callable(float, float, float): void) $cb Progress callback + * @param (callable(float, float, float): void)|null $cb Progress callback */ public function getStream(?callable $cb = null, int $offset = 0, int $end = -1): ReadableStream { diff --git a/src/Stream/ConnectionContext.php b/src/Stream/ConnectionContext.php index f4aaba4c2..943936a93 100644 --- a/src/Stream/ConnectionContext.php +++ b/src/Stream/ConnectionContext.php @@ -298,7 +298,6 @@ final class ConnectionContext /** * Get the inputClientProxy proxy MTProto object. * - * @return array */ public function getInputClientProxy(): array|null { diff --git a/tests/test.sh b/tests/test.sh index df716e989..bb522674a 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -ex php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php @@ -10,3 +10,4 @@ apk add procps git unzip github-cli openssh composer update composer build +if [ "$(git diff)" != "" ]; then echo "Please run composer build!"; exit 1; fi \ No newline at end of file From 5a02ae17a771049f9e0924ff6ffe3a57038c8b29 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 15:08:11 +0200 Subject: [PATCH 11/14] Fixes --- .woodpecker/test.yml | 2 +- composer.json | 5 ----- docs | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 069a1a349..3a6d3ff4c 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -17,7 +17,7 @@ clone: settings: depth: 1 lfs: false - recursive: false + recursive: true tags: true steps: diff --git a/composer.json b/composer.json index 5af9811f0..bea33abf7 100644 --- a/composer.json +++ b/composer.json @@ -113,11 +113,6 @@ "@cs-fix", "@psalm" ], - "check": [ - "@test", - "@cs", - "@psalm" - ], "test-php7": "tests/test-conversion.sh 70", "test-php56": "tests/test-conversion.sh 5", "cs": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v --diff --dry-run", diff --git a/docs b/docs index 1eb6e9dae..fd37b4337 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 1eb6e9dae8e6dc51142a0ac4c37bc4b64ab568c3 +Subproject commit fd37b433741080d7df00d12e9c28e63bb999cd2a From a904be25a20a0321c4f8372a3a34ed40a542149e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 15:14:28 +0200 Subject: [PATCH 12/14] Speed up build --- .woodpecker/test.yml | 2 +- tests/test.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 3a6d3ff4c..069a1a349 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -17,7 +17,7 @@ clone: settings: depth: 1 lfs: false - recursive: true + recursive: false tags: true steps: diff --git a/tests/test.sh b/tests/test.sh index bb522674a..846f6ef4c 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -7,6 +7,10 @@ mv composer.phar /usr/local/bin/composer apk add procps git unzip github-cli openssh +rm -rf docs +curl -L https://github.com/danog/MadelineProtoDocs/archive/refs/heads/master.tar.gz | tar -xz +mv MadelineProtoDocs-master/ docs + composer update composer build From 07176701bb0b571406b0eed934e984149df5e2d5 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 15:16:47 +0200 Subject: [PATCH 13/14] Update schema submodule --- tests/test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test.sh b/tests/test.sh index 846f6ef4c..9753c046f 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -11,6 +11,9 @@ rm -rf docs curl -L https://github.com/danog/MadelineProtoDocs/archive/refs/heads/master.tar.gz | tar -xz mv MadelineProtoDocs-master/ docs +git submodule init schemas +git submodule update schemas + composer update composer build From 7a8f762aca23b3befe986bd2be2ba56d6e511824 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 1 Sep 2023 15:31:26 +0200 Subject: [PATCH 14/14] Add missing schema --- schemas | 2 +- tests/test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/schemas b/schemas index e0f1a275a..5ac5e7a01 160000 --- a/schemas +++ b/schemas @@ -1 +1 @@ -Subproject commit e0f1a275a4b610addd13a835c82ca31b98ffab35 +Subproject commit 5ac5e7a012be37cf4931c1edc0d516a72793ac16 diff --git a/tests/test.sh b/tests/test.sh index 9753c046f..09ee28969 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -7,7 +7,7 @@ mv composer.phar /usr/local/bin/composer apk add procps git unzip github-cli openssh -rm -rf docs +rmdir docs curl -L https://github.com/danog/MadelineProtoDocs/archive/refs/heads/master.tar.gz | tar -xz mv MadelineProtoDocs-master/ docs