From 08a502cb2f175f875de603d5af86fa8c8daa6aaa Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 5 Jun 2019 15:38:32 +0200 Subject: [PATCH] Add async readline --- CHANGELOG.md | 2 + README.md | 3 + build_docs.php | 2 +- src/danog/MadelineProto/APIFactory.php | 36 + src/danog/MadelineProto/InternalDoc.php | 2245 ++++++++++++++++- .../Loop/Connection/WriteLoop.php | 2 +- src/danog/MadelineProto/MTProto.php | 6 +- src/danog/MadelineProto/Tools.php | 21 + src/danog/MadelineProto/Wrappers/ApiStart.php | 41 +- src/danog/MadelineProto/Wrappers/Start.php | 27 +- tests/testing.php | 6 - 11 files changed, 2212 insertions(+), 179 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d6283c1..fa6e99103 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ And now, on to the **API changes**: * First of all, we've got several bucketloads of telegram API changes, that can be viewed in the first posts. * Dropped support for PHP 5 and PHP 7.0: these versions of PHP have [officially reached their EOL](http://php.net/eol.php), so MadelineProto will not support them anymore. You can use MadelineProto with PHP 7.3 (or PHP 7.2, PHP 7.1 is supported but not recommended). +* **Dropped support for get_updates**: it won't work properly on async, and I really recommend you stop using it * You can now use the `@support` username in sendMessage and other methods to send messages to the support user! * Now MadelineProto will automatically try to get the access hash of users not present in the internal peer database (this should reduce errors)! * If any file cannot be downloaded to due issues with the tg media server that is hosting it, it will be automatically sent to the `@support` user ([settings](https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsdownloadreport_broken_media)). @@ -169,4 +170,5 @@ group calls native calls dnssec mytelegramorg docs +web files telegram passport \ No newline at end of file diff --git a/README.md b/README.md index a3f35af6c..2cfade658 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [MadelineProto and AMPHP async APIs](https://docs.madelineproto.xyz/docs/ASYNC.html#madelineproto-and-amphp-async-apis) * [Helper methods](https://docs.madelineproto.xyz/docs/ASYNC.html#helper-methods) * [Async sleep](https://docs.madelineproto.xyz/docs/ASYNC.html#async-sleep-does-not-block-the-main-thread) + * [Async readline](https://docs.madelineproto.xyz/docs/ASYNC.html#async-readline-does-not-block-the-main-thread) * [MadelineProto artax HTTP client](https://docs.madelineproto.xyz/docs/ASYNC.html#madelineproto-artax-http-client) * [Async forking](https://docs.madelineproto.xyz/docs/ASYNC.html#async-forking-does-single-thread-forking) * [Combining async operations](https://docs.madelineproto.xyz/docs/ASYNC.html#combining-async-operations) @@ -76,8 +77,10 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro * [GenericLoop](https://docs.madelineproto.xyz/docs/ASYNC.html#genericloop) * [Creating a client](https://docs.madelineproto.xyz/docs/CREATING_A_CLIENT.html) * [Logging in](https://docs.madelineproto.xyz/docs/LOGIN.html) + * [Getting permission to use the telegram API](https://docs.madelineproto.xyz/docs/LOGIN.html#getting-permission-to-use-the-telegram-api) * [Automatic](https://docs.madelineproto.xyz/docs/LOGIN.html#automatic-now-fully-async) * [Manual (user)](https://docs.madelineproto.xyz/docs/LOGIN.html#manual-user) + * [API ID](https://docs.madelineproto.xyz/docs/LOGIN.html#api-id) * [Manual (bot)](https://docs.madelineproto.xyz/docs/LOGIN.html#manual-bot) * [Logout](https://docs.madelineproto.xyz/docs/LOGIN.html#logout) * [Changing 2FA password](https://docs.madelineproto.xyz/docs/LOGIN.html#changing-2fa-password) diff --git a/build_docs.php b/build_docs.php index bdad2ea01..69006eff0 100755 --- a/build_docs.php +++ b/build_docs.php @@ -73,7 +73,7 @@ description: Documentation of old mtproto layers '.$layer_list); -$doc = new \danog\MadelineProto\AnnotationsBuilder($logger, $docs[2]); +$doc = new \danog\MadelineProto\AnnotationsBuilder($logger, $docs[1]); $doc->mk_annotations(); foreach ($docs as $settings) { diff --git a/src/danog/MadelineProto/APIFactory.php b/src/danog/MadelineProto/APIFactory.php index 08565961c..e1238963f 100644 --- a/src/danog/MadelineProto/APIFactory.php +++ b/src/danog/MadelineProto/APIFactory.php @@ -23,6 +23,42 @@ use danog\MadelineProto\Async\AsyncConstruct; class APIFactory extends AsyncConstruct { + /** + * @internal this is a internal property generated by build_docs.php, don't change manually + * + * @var langpack + */ + public $langpack; + /** + * @internal this is a internal property generated by build_docs.php, don't change manually + * + * @var phone + */ + public $phone; + /** + * @internal this is a internal property generated by build_docs.php, don't change manually + * + * @var stickers + */ + public $stickers; + /** + * @internal this is a internal property generated by build_docs.php, don't change manually + * + * @var payments + */ + public $payments; + /** + * @internal this is a internal property generated by build_docs.php, don't change manually + * + * @var bots + */ + public $bots; + /** + * @internal this is a internal property generated by build_docs.php, don't change manually + * + * @var channels + */ + public $channels; /** * @internal this is a internal property generated by build_docs.php, don't change manually * diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index 924169ffa..e1fb8073c 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -12,35 +12,15 @@ interface auth /** * @param array params [ * string phone_number, - * ] - * - * @return auth_CheckedPhone - */ - public function checkPhone(array $params); - - /** - * @param array params [ - * string phone_number, - * int sms_type, * int api_id, * string api_hash, - * string lang_code, + * CodeSettings settings, * ] * * @return auth_SentCode */ public function sendCode(array $params); - /** - * @param array params [ - * string phone_number, - * string phone_code_hash, - * ] - * - * @return bool - */ - public function sendCall(array $params); - /** * @param array params [ * string phone_number, @@ -75,16 +55,6 @@ interface auth */ public function resetAuthorizations(); - /** - * @param array params [ - * string phone_numbers, - * string message, - * ] - * - * @return bool - */ - public function sendInvites(array $params); - /** * @param array params [ * int dc_id, @@ -116,6 +86,50 @@ interface auth */ public function bindTempAuthKey(array $params); + /** + * @param array params [ + * int api_id, + * string api_hash, + * string bot_auth_token, + * ] + * + * @return auth_Authorization + */ + public function importBotAuthorization(array $params); + + /** + * @param array params [ + * InputCheckPasswordSRP password, + * ] + * + * @return auth_Authorization + */ + public function checkPassword(array $params); + + /** + * @return auth_PasswordRecovery + */ + public function requestPasswordRecovery(); + + /** + * @param array params [ + * string code, + * ] + * + * @return auth_Authorization + */ + public function recoverPassword(array $params); + + /** + * @param array params [ + * string phone_number, + * string phone_code_hash, + * ] + * + * @return auth_SentCode + */ + public function resendCode(array $params); + /** * @param array params [ * string phone_number, @@ -124,7 +138,16 @@ interface auth * * @return bool */ - public function sendSms(array $params); + public function cancelCode(array $params); + + /** + * @param array params [ + * long except_auth_keys, + * ] + * + * @return bool + */ + public function dropTempAuthKeys(array $params); } interface account @@ -133,11 +156,9 @@ interface account * @param array params [ * int token_type, * string token, - * string device_model, - * string system_version, - * string app_version, * Bool app_sandbox, - * string lang_code, + * bytes secret, + * int other_uids, * ] * * @return bool @@ -148,6 +169,7 @@ interface account * @param array params [ * int token_type, * string token, + * int other_uids, * ] * * @return bool @@ -182,6 +204,7 @@ interface account * @param array params [ * string first_name, * string last_name, + * string about, * ] * * @return User @@ -198,9 +221,23 @@ interface account public function updateStatus(array $params); /** - * @return Vector_of_WallPaper + * @param array params [ + * int hash, + * ] + * + * @return account_WallPapers */ - public function getWallPapers(); + public function getWallPapers(array $params); + + /** + * @param array params [ + * InputPeer peer, + * ReportReason reason, + * ] + * + * @return bool + */ + public function reportPeer(array $params); /** * @param array params [ @@ -219,6 +256,391 @@ interface account * @return User */ public function updateUsername(array $params); + + /** + * @param array params [ + * InputPrivacyKey key, + * ] + * + * @return account_PrivacyRules + */ + public function getPrivacy(array $params); + + /** + * @param array params [ + * InputPrivacyKey key, + * InputPrivacyRule rules, + * ] + * + * @return account_PrivacyRules + */ + public function setPrivacy(array $params); + + /** + * @param array params [ + * string reason, + * ] + * + * @return bool + */ + public function deleteAccount(array $params); + + /** + * @return AccountDaysTTL + */ + public function getAccountTTL(); + + /** + * @param array params [ + * AccountDaysTTL ttl, + * ] + * + * @return bool + */ + public function setAccountTTL(array $params); + + /** + * @param array params [ + * string phone_number, + * CodeSettings settings, + * ] + * + * @return auth_SentCode + */ + public function sendChangePhoneCode(array $params); + + /** + * @param array params [ + * string phone_number, + * string phone_code_hash, + * string phone_code, + * ] + * + * @return User + */ + public function changePhone(array $params); + + /** + * @param array params [ + * int period, + * ] + * + * @return bool + */ + public function updateDeviceLocked(array $params); + + /** + * @return account_Authorizations + */ + public function getAuthorizations(); + + /** + * @param array params [ + * long hash, + * ] + * + * @return bool + */ + public function resetAuthorization(array $params); + + /** + * @return account_Password + */ + public function getPassword(); + + /** + * @param array params [ + * InputCheckPasswordSRP password, + * ] + * + * @return account_PasswordSettings + */ + public function getPasswordSettings(array $params); + + /** + * @param array params [ + * InputCheckPasswordSRP password, + * account_PasswordInputSettings new_settings, + * ] + * + * @return bool + */ + public function updatePasswordSettings(array $params); + + /** + * @param array params [ + * string hash, + * CodeSettings settings, + * ] + * + * @return auth_SentCode + */ + public function sendConfirmPhoneCode(array $params); + + /** + * @param array params [ + * string phone_code_hash, + * string phone_code, + * ] + * + * @return bool + */ + public function confirmPhone(array $params); + + /** + * @param array params [ + * InputCheckPasswordSRP password, + * int period, + * ] + * + * @return account_TmpPassword + */ + public function getTmpPassword(array $params); + + /** + * @return account_WebAuthorizations + */ + public function getWebAuthorizations(); + + /** + * @param array params [ + * long hash, + * ] + * + * @return bool + */ + public function resetWebAuthorization(array $params); + + /** + * @return bool + */ + public function resetWebAuthorizations(); + + /** + * @return Vector_of_SecureValue + */ + public function getAllSecureValues(); + + /** + * @param array params [ + * SecureValueType types, + * ] + * + * @return Vector_of_SecureValue + */ + public function getSecureValue(array $params); + + /** + * @param array params [ + * InputSecureValue value, + * long secure_secret_id, + * ] + * + * @return SecureValue + */ + public function saveSecureValue(array $params); + + /** + * @param array params [ + * SecureValueType types, + * ] + * + * @return bool + */ + public function deleteSecureValue(array $params); + + /** + * @param array params [ + * int bot_id, + * string scope, + * string public_key, + * ] + * + * @return account_AuthorizationForm + */ + public function getAuthorizationForm(array $params); + + /** + * @param array params [ + * int bot_id, + * string scope, + * string public_key, + * SecureValueHash value_hashes, + * SecureCredentialsEncrypted credentials, + * ] + * + * @return bool + */ + public function acceptAuthorization(array $params); + + /** + * @param array params [ + * string phone_number, + * CodeSettings settings, + * ] + * + * @return auth_SentCode + */ + public function sendVerifyPhoneCode(array $params); + + /** + * @param array params [ + * string phone_number, + * string phone_code_hash, + * string phone_code, + * ] + * + * @return bool + */ + public function verifyPhone(array $params); + + /** + * @param array params [ + * string email, + * ] + * + * @return account_SentEmailCode + */ + public function sendVerifyEmailCode(array $params); + + /** + * @param array params [ + * string email, + * string code, + * ] + * + * @return bool + */ + public function verifyEmail(array $params); + + /** + * @param array params [ + * boolean contacts, + * boolean message_users, + * boolean message_chats, + * boolean message_megagroups, + * boolean message_channels, + * boolean files, + * int file_max_size, + * ] + * + * @return account_Takeout + */ + public function initTakeoutSession(array $params); + + /** + * @param array params [ + * boolean success, + * ] + * + * @return bool + */ + public function finishTakeoutSession(array $params); + + /** + * @param array params [ + * string code, + * ] + * + * @return bool + */ + public function confirmPasswordEmail(array $params); + + /** + * @return bool + */ + public function resendPasswordEmail(); + + /** + * @return bool + */ + public function cancelPasswordEmail(); + + /** + * @return bool + */ + public function getContactSignUpNotification(); + + /** + * @param array params [ + * Bool silent, + * ] + * + * @return bool + */ + public function setContactSignUpNotification(array $params); + + /** + * @param array params [ + * boolean compare_sound, + * InputNotifyPeer peer, + * ] + * + * @return Updates + */ + public function getNotifyExceptions(array $params); + + /** + * @param array params [ + * InputWallPaper wallpaper, + * ] + * + * @return WallPaper + */ + public function getWallPaper(array $params); + + /** + * @param array params [ + * InputFile file, + * string mime_type, + * WallPaperSettings settings, + * ] + * + * @return WallPaper + */ + public function uploadWallPaper(array $params); + + /** + * @param array params [ + * InputWallPaper wallpaper, + * Bool unsave, + * WallPaperSettings settings, + * ] + * + * @return bool + */ + public function saveWallPaper(array $params); + + /** + * @param array params [ + * InputWallPaper wallpaper, + * WallPaperSettings settings, + * ] + * + * @return bool + */ + public function installWallPaper(array $params); + + /** + * @return bool + */ + public function resetWallPapers(); + + /** + * @return account_AutoDownloadSettings + */ + public function getAutoDownloadSettings(); + + /** + * @param array params [ + * boolean low, + * boolean high, + * AutoDownloadSettings settings, + * ] + * + * @return bool + */ + public function saveAutoDownloadSettings(array $params); } interface users @@ -240,10 +662,29 @@ interface users * @return UserFull */ public function getFullUser(array $params); + + /** + * @param array params [ + * InputUser id, + * SecureValueError errors, + * ] + * + * @return bool + */ + public function setSecureValueErrors(array $params); } interface contacts { + /** + * @param array params [ + * int hash, + * ] + * + * @return Vector_of_int + */ + public function getContactIDs(array $params); + /** * @return Vector_of_ContactStatus */ @@ -251,7 +692,7 @@ interface contacts /** * @param array params [ - * string hash, + * int hash, * ] * * @return contacts_Contacts @@ -261,22 +702,12 @@ interface contacts /** * @param array params [ * InputContact contacts, - * Bool replace, * ] * * @return contacts_ImportedContacts */ public function importContacts(array $params); - /** - * @param array params [ - * int limit, - * ] - * - * @return contacts_Suggested - */ - public function getSuggested(array $params); - /** * @param array params [ * InputUser id, @@ -295,6 +726,15 @@ interface contacts */ public function deleteContacts(array $params); + /** + * @param array params [ + * string phones, + * ] + * + * @return bool + */ + public function deleteByPhones(array $params); + /** * @param array params [ * InputUser id, @@ -323,20 +763,6 @@ interface contacts */ public function getBlocked(array $params); - /** - * @return Vector_of_int - */ - public function exportCard(); - - /** - * @param array params [ - * int export_card, - * ] - * - * @return User - */ - public function importCard(array $params); - /** * @param array params [ * string q, @@ -346,13 +772,68 @@ interface contacts * @return contacts_Found */ public function search(array $params); + + /** + * @param array params [ + * string username, + * ] + * + * @return contacts_ResolvedPeer + */ + public function resolveUsername(array $params); + + /** + * @param array params [ + * boolean correspondents, + * boolean bots_pm, + * boolean bots_inline, + * boolean phone_calls, + * boolean groups, + * boolean channels, + * int offset, + * int limit, + * int hash, + * ] + * + * @return contacts_TopPeers + */ + public function getTopPeers(array $params); + + /** + * @param array params [ + * TopPeerCategory category, + * InputPeer peer, + * ] + * + * @return bool + */ + public function resetTopPeerRating(array $params); + + /** + * @return bool + */ + public function resetSaved(); + + /** + * @return Vector_of_SavedContact + */ + public function getSaved(); + + /** + * @param array params [ + * Bool enabled, + * ] + * + * @return bool + */ + public function toggleTopPeers(array $params); } interface messages { /** * @param array params [ - * int id, + * InputMessage id, * ] * * @return messages_Messages @@ -361,9 +842,12 @@ interface messages /** * @param array params [ - * int offset, - * int max_id, + * boolean exclude_pinned, + * int offset_date, + * int offset_id, + * InputPeer offset_peer, * int limit, + * int hash, * ] * * @return messages_Dialogs @@ -373,9 +857,13 @@ interface messages /** * @param array params [ * InputPeer peer, - * int offset, - * int max_id, + * int offset_id, + * int offset_date, + * int add_offset, * int limit, + * int max_id, + * int min_id, + * int hash, * ] * * @return messages_Messages @@ -386,12 +874,16 @@ interface messages * @param array params [ * InputPeer peer, * string q, + * InputUser from_id, * MessagesFilter filter, * int min_date, * int max_date, - * int offset, - * int max_id, + * int offset_id, + * int add_offset, * int limit, + * int max_id, + * int min_id, + * int hash, * ] * * @return messages_Messages @@ -402,18 +894,18 @@ interface messages * @param array params [ * InputPeer peer, * int max_id, - * int offset, - * Bool read_contents, * ] * - * @return messages_AffectedHistory + * @return messages_AffectedMessages */ public function readHistory(array $params); /** * @param array params [ + * boolean just_clear, + * boolean revoke, * InputPeer peer, - * int offset, + * int max_id, * ] * * @return messages_AffectedHistory @@ -422,10 +914,11 @@ interface messages /** * @param array params [ + * boolean revoke, * int id, * ] * - * @return Vector_of_int + * @return messages_AffectedMessages */ public function deleteMessages(array $params); @@ -434,7 +927,7 @@ interface messages * int max_id, * ] * - * @return Vector_of_int + * @return Vector_of_ReceivedNotifyMessage */ public function receivedMessages(array $params); @@ -450,31 +943,50 @@ interface messages /** * @param array params [ + * boolean no_webpage, + * boolean silent, + * boolean background, + * boolean clear_draft, * InputPeer peer, + * int reply_to_msg_id, * string message, + * ReplyMarkup reply_markup, + * MessageEntity entities, * ] * - * @return messages_SentMessage + * @return Updates */ public function sendMessage(array $params); /** * @param array params [ + * boolean silent, + * boolean background, + * boolean clear_draft, * InputPeer peer, + * int reply_to_msg_id, * InputMedia media, + * string message, + * ReplyMarkup reply_markup, + * MessageEntity entities, * ] * - * @return messages_StatedMessage + * @return Updates */ public function sendMedia(array $params); /** * @param array params [ - * InputPeer peer, + * boolean silent, + * boolean background, + * boolean with_my_score, + * boolean grouped, + * InputPeer from_peer, * int id, + * InputPeer to_peer, * ] * - * @return messages_StatedMessages + * @return Updates */ public function forwardMessages(array $params); @@ -487,6 +999,35 @@ interface messages */ public function reportSpam(array $params); + /** + * @param array params [ + * InputPeer peer, + * ] + * + * @return bool + */ + public function hideReportSpam(array $params); + + /** + * @param array params [ + * InputPeer peer, + * ] + * + * @return PeerSettings + */ + public function getPeerSettings(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int id, + * ReportReason reason, + * ] + * + * @return bool + */ + public function report(array $params); + /** * @param array params [ * int id, @@ -511,7 +1052,7 @@ interface messages * string title, * ] * - * @return messages_StatedMessage + * @return Updates */ public function editChatTitle(array $params); @@ -521,7 +1062,7 @@ interface messages * InputChatPhoto photo, * ] * - * @return messages_StatedMessage + * @return Updates */ public function editChatPhoto(array $params); @@ -532,7 +1073,7 @@ interface messages * int fwd_limit, * ] * - * @return messages_StatedMessage + * @return Updates */ public function addChatUser(array $params); @@ -542,7 +1083,7 @@ interface messages * InputUser user_id, * ] * - * @return messages_StatedMessage + * @return Updates */ public function deleteChatUser(array $params); @@ -552,31 +1093,10 @@ interface messages * string title, * ] * - * @return messages_StatedMessage + * @return Updates */ public function createChat(array $params); - /** - * @param array params [ - * InputPeer peer, - * int id, - * ] - * - * @return messages_StatedMessage - */ - public function forwardMessage(array $params); - - /** - * @param array params [ - * InputUser contacts, - * string message, - * InputMedia media, - * ] - * - * @return messages_StatedMessages - */ - public function sendBroadcast(array $params); - /** * @param array params [ * int version, @@ -677,14 +1197,782 @@ interface messages */ public function receivedQueue(array $params); + /** + * @param array params [ + * InputEncryptedChat peer, + * ] + * + * @return bool + */ + public function reportEncryptedSpam(array $params); + /** * @param array params [ * int id, * ] * + * @return messages_AffectedMessages + */ + public function readMessageContents(array $params); + + /** + * @param array params [ + * string emoticon, + * int hash, + * ] + * + * @return messages_Stickers + */ + public function getStickers(array $params); + + /** + * @param array params [ + * int hash, + * ] + * + * @return messages_AllStickers + */ + public function getAllStickers(array $params); + + /** + * @param array params [ + * string message, + * MessageEntity entities, + * ] + * + * @return MessageMedia + */ + public function getWebPagePreview(array $params); + + /** + * @param array params [ + * InputPeer peer, + * ] + * + * @return ExportedChatInvite + */ + public function exportChatInvite(array $params); + + /** + * @param array params [ + * string hash, + * ] + * + * @return ChatInvite + */ + public function checkChatInvite(array $params); + + /** + * @param array params [ + * string hash, + * ] + * + * @return Updates + */ + public function importChatInvite(array $params); + + /** + * @param array params [ + * InputStickerSet stickerset, + * ] + * + * @return messages_StickerSet + */ + public function getStickerSet(array $params); + + /** + * @param array params [ + * InputStickerSet stickerset, + * Bool archived, + * ] + * + * @return messages_StickerSetInstallResult + */ + public function installStickerSet(array $params); + + /** + * @param array params [ + * InputStickerSet stickerset, + * ] + * + * @return bool + */ + public function uninstallStickerSet(array $params); + + /** + * @param array params [ + * InputUser bot, + * InputPeer peer, + * string start_param, + * ] + * + * @return Updates + */ + public function startBot(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int id, + * Bool increment, + * ] + * * @return Vector_of_int */ - public function readMessageContents(array $params); + public function getMessagesViews(array $params); + + /** + * @param array params [ + * int chat_id, + * InputUser user_id, + * Bool is_admin, + * ] + * + * @return bool + */ + public function editChatAdmin(array $params); + + /** + * @param array params [ + * int chat_id, + * ] + * + * @return Updates + */ + public function migrateChat(array $params); + + /** + * @param array params [ + * string q, + * int offset_date, + * InputPeer offset_peer, + * int offset_id, + * int limit, + * ] + * + * @return messages_Messages + */ + public function searchGlobal(array $params); + + /** + * @param array params [ + * boolean masks, + * long order, + * ] + * + * @return bool + */ + public function reorderStickerSets(array $params); + + /** + * @param array params [ + * bytes sha256, + * int size, + * string mime_type, + * ] + * + * @return Document + */ + public function getDocumentByHash(array $params); + + /** + * @param array params [ + * string q, + * int offset, + * ] + * + * @return messages_FoundGifs + */ + public function searchGifs(array $params); + + /** + * @param array params [ + * int hash, + * ] + * + * @return messages_SavedGifs + */ + public function getSavedGifs(array $params); + + /** + * @param array params [ + * InputDocument id, + * Bool unsave, + * ] + * + * @return bool + */ + public function saveGif(array $params); + + /** + * @param array params [ + * InputUser bot, + * InputPeer peer, + * InputGeoPoint geo_point, + * string query, + * string offset, + * ] + * + * @return messages_BotResults + */ + public function getInlineBotResults(array $params); + + /** + * @param array params [ + * boolean gallery, + * boolean private, + * long query_id, + * InputBotInlineResult results, + * int cache_time, + * string next_offset, + * InlineBotSwitchPM switch_pm, + * ] + * + * @return bool + */ + public function setInlineBotResults(array $params); + + /** + * @param array params [ + * boolean silent, + * boolean background, + * boolean clear_draft, + * boolean hide_via, + * InputPeer peer, + * int reply_to_msg_id, + * long query_id, + * string id, + * ] + * + * @return Updates + */ + public function sendInlineBotResult(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int id, + * ] + * + * @return messages_MessageEditData + */ + public function getMessageEditData(array $params); + + /** + * @param array params [ + * boolean no_webpage, + * InputPeer peer, + * int id, + * string message, + * InputMedia media, + * ReplyMarkup reply_markup, + * MessageEntity entities, + * ] + * + * @return Updates + */ + public function editMessage(array $params); + + /** + * @param array params [ + * boolean no_webpage, + * InputBotInlineMessageID id, + * string message, + * InputMedia media, + * ReplyMarkup reply_markup, + * MessageEntity entities, + * ] + * + * @return bool + */ + public function editInlineBotMessage(array $params); + + /** + * @param array params [ + * boolean game, + * InputPeer peer, + * int msg_id, + * bytes data, + * ] + * + * @return messages_BotCallbackAnswer + */ + public function getBotCallbackAnswer(array $params); + + /** + * @param array params [ + * boolean alert, + * long query_id, + * string message, + * string url, + * int cache_time, + * ] + * + * @return bool + */ + public function setBotCallbackAnswer(array $params); + + /** + * @param array params [ + * InputDialogPeer peers, + * ] + * + * @return messages_PeerDialogs + */ + public function getPeerDialogs(array $params); + + /** + * @param array params [ + * boolean no_webpage, + * int reply_to_msg_id, + * InputPeer peer, + * string message, + * MessageEntity entities, + * ] + * + * @return bool + */ + public function saveDraft(array $params); + + /** + * @return Updates + */ + public function getAllDrafts(); + + /** + * @param array params [ + * int hash, + * ] + * + * @return messages_FeaturedStickers + */ + public function getFeaturedStickers(array $params); + + /** + * @param array params [ + * long id, + * ] + * + * @return bool + */ + public function readFeaturedStickers(array $params); + + /** + * @param array params [ + * boolean attached, + * int hash, + * ] + * + * @return messages_RecentStickers + */ + public function getRecentStickers(array $params); + + /** + * @param array params [ + * boolean attached, + * InputDocument id, + * Bool unsave, + * ] + * + * @return bool + */ + public function saveRecentSticker(array $params); + + /** + * @param array params [ + * boolean attached, + * ] + * + * @return bool + */ + public function clearRecentStickers(array $params); + + /** + * @param array params [ + * boolean masks, + * long offset_id, + * int limit, + * ] + * + * @return messages_ArchivedStickers + */ + public function getArchivedStickers(array $params); + + /** + * @param array params [ + * int hash, + * ] + * + * @return messages_AllStickers + */ + public function getMaskStickers(array $params); + + /** + * @param array params [ + * InputStickeredMedia media, + * ] + * + * @return Vector_of_StickerSetCovered + */ + public function getAttachedStickers(array $params); + + /** + * @param array params [ + * boolean edit_message, + * boolean force, + * InputPeer peer, + * int id, + * InputUser user_id, + * int score, + * ] + * + * @return Updates + */ + public function setGameScore(array $params); + + /** + * @param array params [ + * boolean edit_message, + * boolean force, + * InputBotInlineMessageID id, + * InputUser user_id, + * int score, + * ] + * + * @return bool + */ + public function setInlineGameScore(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int id, + * InputUser user_id, + * ] + * + * @return messages_HighScores + */ + public function getGameHighScores(array $params); + + /** + * @param array params [ + * InputBotInlineMessageID id, + * InputUser user_id, + * ] + * + * @return messages_HighScores + */ + public function getInlineGameHighScores(array $params); + + /** + * @param array params [ + * InputUser user_id, + * int max_id, + * int limit, + * ] + * + * @return messages_Chats + */ + public function getCommonChats(array $params); + + /** + * @param array params [ + * int except_ids, + * ] + * + * @return messages_Chats + */ + public function getAllChats(array $params); + + /** + * @param array params [ + * string url, + * int hash, + * ] + * + * @return WebPage + */ + public function getWebPage(array $params); + + /** + * @param array params [ + * boolean pinned, + * InputDialogPeer peer, + * ] + * + * @return bool + */ + public function toggleDialogPin(array $params); + + /** + * @param array params [ + * boolean force, + * InputDialogPeer order, + * ] + * + * @return bool + */ + public function reorderPinnedDialogs(array $params); + + /** + * @return messages_PeerDialogs + */ + public function getPinnedDialogs(); + + /** + * @param array params [ + * long query_id, + * string error, + * ShippingOption shipping_options, + * ] + * + * @return bool + */ + public function setBotShippingResults(array $params); + + /** + * @param array params [ + * boolean success, + * long query_id, + * string error, + * ] + * + * @return bool + */ + public function setBotPrecheckoutResults(array $params); + + /** + * @param array params [ + * InputPeer peer, + * InputMedia media, + * ] + * + * @return MessageMedia + */ + public function uploadMedia(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int reply_to_msg_id, + * ] + * + * @return Updates + */ + public function sendScreenshotNotification(array $params); + + /** + * @param array params [ + * int hash, + * ] + * + * @return messages_FavedStickers + */ + public function getFavedStickers(array $params); + + /** + * @param array params [ + * InputDocument id, + * Bool unfave, + * ] + * + * @return bool + */ + public function faveSticker(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int offset_id, + * int add_offset, + * int limit, + * int max_id, + * int min_id, + * ] + * + * @return messages_Messages + */ + public function getUnreadMentions(array $params); + + /** + * @param array params [ + * InputPeer peer, + * ] + * + * @return messages_AffectedHistory + */ + public function readMentions(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int limit, + * int hash, + * ] + * + * @return messages_Messages + */ + public function getRecentLocations(array $params); + + /** + * @param array params [ + * boolean silent, + * boolean background, + * boolean clear_draft, + * InputPeer peer, + * int reply_to_msg_id, + * InputSingleMedia multi_media, + * ] + * + * @return Updates + */ + public function sendMultiMedia(array $params); + + /** + * @param array params [ + * InputEncryptedChat peer, + * InputEncryptedFile file, + * ] + * + * @return EncryptedFile + */ + public function uploadEncryptedFile(array $params); + + /** + * @param array params [ + * boolean exclude_featured, + * string q, + * int hash, + * ] + * + * @return messages_FoundStickerSets + */ + public function searchStickerSets(array $params); + + /** + * @return Vector_of_MessageRange + */ + public function getSplitRanges(); + + /** + * @param array params [ + * boolean unread, + * InputDialogPeer peer, + * ] + * + * @return bool + */ + public function markDialogUnread(array $params); + + /** + * @return Vector_of_DialogPeer + */ + public function getDialogUnreadMarks(); + + /** + * @return bool + */ + public function clearAllDrafts(); + + /** + * @param array params [ + * boolean silent, + * InputPeer peer, + * int id, + * ] + * + * @return Updates + */ + public function updatePinnedMessage(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int msg_id, + * bytes options, + * ] + * + * @return Updates + */ + public function sendVote(array $params); + + /** + * @param array params [ + * InputPeer peer, + * int msg_id, + * ] + * + * @return Updates + */ + public function getPollResults(array $params); + + /** + * @param array params [ + * InputPeer peer, + * ] + * + * @return ChatOnlines + */ + public function getOnlines(array $params); + + /** + * @param array params [ + * boolean dark, + * InputPeer peer, + * string params, + * ] + * + * @return StatsURL + */ + public function getStatsURL(array $params); + + /** + * @param array params [ + * InputPeer peer, + * string about, + * ] + * + * @return bool + */ + public function editChatAbout(array $params); + + /** + * @param array params [ + * InputPeer peer, + * ChatBannedRights banned_rights, + * ] + * + * @return Updates + */ + public function editChatDefaultBannedRights(array $params); + + /** + * @param array params [ + * string lang_code, + * ] + * + * @return EmojiKeywordsDifference + */ + public function getEmojiKeywords(array $params); + + /** + * @param array params [ + * string lang_code, + * int from_version, + * ] + * + * @return EmojiKeywordsDifference + */ + public function getEmojiKeywordsDifference(array $params); + + /** + * @param array params [ + * string lang_code, + * ] + * + * @return EmojiURL + */ + public function getEmojiURL(array $params); } interface updates @@ -697,6 +1985,7 @@ interface updates /** * @param array params [ * int pts, + * int pts_total_limit, * int date, * int qts, * ] @@ -704,6 +1993,19 @@ interface updates * @return updates_Difference */ public function getDifference(array $params); + + /** + * @param array params [ + * boolean force, + * InputChannel channel, + * ChannelMessagesFilter filter, + * int pts, + * int limit, + * ] + * + * @return updates_ChannelDifference + */ + public function getChannelDifference(array $params); } interface photos @@ -711,7 +2013,6 @@ interface photos /** * @param array params [ * InputPhoto id, - * InputPhotoCrop crop, * ] * * @return UserProfilePhoto @@ -721,9 +2022,6 @@ interface photos /** * @param array params [ * InputFile file, - * string caption, - * InputGeoPoint geo_point, - * InputPhotoCrop crop, * ] * * @return photos_Photo @@ -743,7 +2041,7 @@ interface photos * @param array params [ * InputUser user_id, * int offset, - * int max_id, + * long max_id, * int limit, * ] * @@ -787,6 +2085,58 @@ interface upload * @return bool */ public function saveBigFilePart(array $params); + + /** + * @param array params [ + * InputWebFileLocation location, + * int offset, + * int limit, + * ] + * + * @return upload_WebFile + */ + public function getWebFile(array $params); + + /** + * @param array params [ + * bytes file_token, + * int offset, + * int limit, + * ] + * + * @return upload_CdnFile + */ + public function getCdnFile(array $params); + + /** + * @param array params [ + * bytes file_token, + * bytes request_token, + * ] + * + * @return Vector_of_FileHash + */ + public function reuploadCdnFile(array $params); + + /** + * @param array params [ + * bytes file_token, + * int offset, + * ] + * + * @return Vector_of_FileHash + */ + public function getCdnFileHashes(array $params); + + /** + * @param array params [ + * InputFileLocation location, + * int offset, + * ] + * + * @return Vector_of_FileHash + */ + public function getFileHashes(array $params); } interface help @@ -803,16 +2153,89 @@ interface help /** * @param array params [ - * string device_model, - * string system_version, - * string app_version, - * string lang_code, + * string source, * ] * * @return help_AppUpdate */ public function getAppUpdate(array $params); + /** + * @return help_InviteText + */ + public function getInviteText(); + + /** + * @return help_Support + */ + public function getSupport(); + + /** + * @param array params [ + * string prev_app_version, + * ] + * + * @return Updates + */ + public function getAppChangelog(array $params); + + /** + * @param array params [ + * int pending_updates_count, + * string message, + * ] + * + * @return bool + */ + public function setBotUpdatesStatus(array $params); + + /** + * @return CdnConfig + */ + public function getCdnConfig(); + + /** + * @param array params [ + * string referer, + * ] + * + * @return help_RecentMeUrls + */ + public function getRecentMeUrls(array $params); + + /** + * @return help_ProxyData + */ + public function getProxyData(); + + /** + * @return help_TermsOfServiceUpdate + */ + public function getTermsOfServiceUpdate(); + + /** + * @param array params [ + * DataJSON id, + * ] + * + * @return bool + */ + public function acceptTermsOfService(array $params); + + /** + * @param array params [ + * string path, + * ] + * + * @return help_DeepLinkInfo + */ + public function getDeepLinkInfo(array $params); + + /** + * @return JSONValue + */ + public function getAppConfig(); + /** * @param array params [ * InputAppEvent events, @@ -824,15 +2247,597 @@ interface help /** * @param array params [ + * int hash, + * ] + * + * @return help_PassportConfig + */ + public function getPassportConfig(array $params); + + /** + * @return help_SupportName + */ + public function getSupportName(); + + /** + * @param array params [ + * InputUser user_id, + * ] + * + * @return help_UserInfo + */ + public function getUserInfo(array $params); + + /** + * @param array params [ + * InputUser user_id, + * string message, + * MessageEntity entities, + * ] + * + * @return help_UserInfo + */ + public function editUserInfo(array $params); +} + +interface channels +{ + /** + * @param array params [ + * InputChannel channel, + * int max_id, + * ] + * + * @return bool + */ + public function readHistory(array $params); + + /** + * @param array params [ + * InputChannel channel, + * int id, + * ] + * + * @return messages_AffectedMessages + */ + public function deleteMessages(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputUser user_id, + * ] + * + * @return messages_AffectedHistory + */ + public function deleteUserHistory(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputUser user_id, + * int id, + * ] + * + * @return bool + */ + public function reportSpam(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputMessage id, + * ] + * + * @return messages_Messages + */ + public function getMessages(array $params); + + /** + * @param array params [ + * InputChannel channel, + * ChannelParticipantsFilter filter, + * int offset, + * int limit, + * int hash, + * ] + * + * @return channels_ChannelParticipants + */ + public function getParticipants(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputUser user_id, + * ] + * + * @return channels_ChannelParticipant + */ + public function getParticipant(array $params); + + /** + * @param array params [ + * InputChannel id, + * ] + * + * @return messages_Chats + */ + public function getChannels(array $params); + + /** + * @param array params [ + * InputChannel channel, + * ] + * + * @return messages_ChatFull + */ + public function getFullChannel(array $params); + + /** + * @param array params [ + * boolean broadcast, + * boolean megagroup, + * string title, + * string about, + * ] + * + * @return Updates + */ + public function createChannel(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputUser user_id, + * ChatAdminRights admin_rights, + * ] + * + * @return Updates + */ + public function editAdmin(array $params); + + /** + * @param array params [ + * InputChannel channel, + * string title, + * ] + * + * @return Updates + */ + public function editTitle(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputChatPhoto photo, + * ] + * + * @return Updates + */ + public function editPhoto(array $params); + + /** + * @param array params [ + * InputChannel channel, + * string username, + * ] + * + * @return bool + */ + public function checkUsername(array $params); + + /** + * @param array params [ + * InputChannel channel, + * string username, + * ] + * + * @return bool + */ + public function updateUsername(array $params); + + /** + * @param array params [ + * InputChannel channel, + * ] + * + * @return Updates + */ + public function joinChannel(array $params); + + /** + * @param array params [ + * InputChannel channel, + * ] + * + * @return Updates + */ + public function leaveChannel(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputUser users, + * ] + * + * @return Updates + */ + public function inviteToChannel(array $params); + + /** + * @param array params [ + * InputChannel channel, + * ] + * + * @return Updates + */ + public function deleteChannel(array $params); + + /** + * @param array params [ + * InputChannel channel, + * int id, + * Bool grouped, + * ] + * + * @return ExportedMessageLink + */ + public function exportMessageLink(array $params); + + /** + * @param array params [ + * InputChannel channel, + * Bool enabled, + * ] + * + * @return Updates + */ + public function toggleSignatures(array $params); + + /** + * @return messages_Chats + */ + public function getAdminedPublicChannels(); + + /** + * @param array params [ + * InputChannel channel, + * InputUser user_id, + * ChatBannedRights banned_rights, + * ] + * + * @return Updates + */ + public function editBanned(array $params); + + /** + * @param array params [ + * InputChannel channel, + * string q, + * ChannelAdminLogEventsFilter events_filter, + * InputUser admins, + * long max_id, + * long min_id, + * int limit, + * ] + * + * @return channels_AdminLogResults + */ + public function getAdminLog(array $params); + + /** + * @param array params [ + * InputChannel channel, + * InputStickerSet stickerset, + * ] + * + * @return bool + */ + public function setStickers(array $params); + + /** + * @param array params [ + * InputChannel channel, + * int id, + * ] + * + * @return bool + */ + public function readMessageContents(array $params); + + /** + * @param array params [ + * InputChannel channel, + * int max_id, + * ] + * + * @return bool + */ + public function deleteHistory(array $params); + + /** + * @param array params [ + * InputChannel channel, + * Bool enabled, + * ] + * + * @return Updates + */ + public function togglePreHistoryHidden(array $params); + + /** + * @param array params [ + * int offset, + * ] + * + * @return messages_Chats + */ + public function getLeftChannels(array $params); +} + +interface bots +{ + /** + * @param array params [ + * string custom_method, + * DataJSON params, + * ] + * + * @return DataJSON + */ + public function sendCustomRequest(array $params); + + /** + * @param array params [ + * long query_id, + * DataJSON data, + * ] + * + * @return bool + */ + public function answerWebhookJSONQuery(array $params); +} + +interface payments +{ + /** + * @param array params [ + * int msg_id, + * ] + * + * @return payments_PaymentForm + */ + public function getPaymentForm(array $params); + + /** + * @param array params [ + * int msg_id, + * ] + * + * @return payments_PaymentReceipt + */ + public function getPaymentReceipt(array $params); + + /** + * @param array params [ + * boolean save, + * int msg_id, + * PaymentRequestedInfo info, + * ] + * + * @return payments_ValidatedRequestedInfo + */ + public function validateRequestedInfo(array $params); + + /** + * @param array params [ + * int msg_id, + * string requested_info_id, + * string shipping_option_id, + * InputPaymentCredentials credentials, + * ] + * + * @return payments_PaymentResult + */ + public function sendPaymentForm(array $params); + + /** + * @return payments_SavedInfo + */ + public function getSavedInfo(); + + /** + * @param array params [ + * boolean credentials, + * boolean info, + * ] + * + * @return bool + */ + public function clearSavedInfo(array $params); +} + +interface stickers +{ + /** + * @param array params [ + * boolean masks, + * InputUser user_id, + * string title, + * string short_name, + * InputStickerSetItem stickers, + * ] + * + * @return messages_StickerSet + */ + public function createStickerSet(array $params); + + /** + * @param array params [ + * InputDocument sticker, + * ] + * + * @return messages_StickerSet + */ + public function removeStickerFromSet(array $params); + + /** + * @param array params [ + * InputDocument sticker, + * int position, + * ] + * + * @return messages_StickerSet + */ + public function changeStickerPosition(array $params); + + /** + * @param array params [ + * InputStickerSet stickerset, + * InputStickerSetItem sticker, + * ] + * + * @return messages_StickerSet + */ + public function addStickerToSet(array $params); +} + +interface phone +{ + /** + * @return DataJSON + */ + public function getCallConfig(); + + /** + * @param array params [ + * InputUser user_id, + * bytes g_a_hash, + * PhoneCallProtocol protocol, + * ] + * + * @return phone_PhoneCall + */ + public function requestCall(array $params); + + /** + * @param array params [ + * InputPhoneCall peer, + * bytes g_b, + * PhoneCallProtocol protocol, + * ] + * + * @return phone_PhoneCall + */ + public function acceptCall(array $params); + + /** + * @param array params [ + * InputPhoneCall peer, + * bytes g_a, + * long key_fingerprint, + * PhoneCallProtocol protocol, + * ] + * + * @return phone_PhoneCall + */ + public function confirmCall(array $params); + + /** + * @param array params [ + * InputPhoneCall peer, + * ] + * + * @return bool + */ + public function receivedCall(array $params); + + /** + * @param array params [ + * InputPhoneCall peer, + * int duration, + * PhoneCallDiscardReason reason, + * long connection_id, + * ] + * + * @return Updates + */ + public function discardCall(array $params); + + /** + * @param array params [ + * boolean user_initiative, + * InputPhoneCall peer, + * int rating, + * string comment, + * ] + * + * @return Updates + */ + public function setCallRating(array $params); + + /** + * @param array params [ + * InputPhoneCall peer, + * DataJSON debug, + * ] + * + * @return bool + */ + public function saveCallDebug(array $params); +} + +interface langpack +{ + /** + * @param array params [ + * string lang_pack, * string lang_code, * ] * - * @return help_InviteText + * @return LangPackDifference */ - public function getInviteText(array $params); + public function getLangPack(array $params); /** - * @return help_Support + * @param array params [ + * string lang_pack, + * string lang_code, + * string keys, + * ] + * + * @return Vector_of_LangPackString */ - public function getSupport(); + public function getStrings(array $params); + + /** + * @param array params [ + * string lang_pack, + * string lang_code, + * int from_version, + * ] + * + * @return LangPackDifference + */ + public function getDifference(array $params); + + /** + * @param array params [ + * string lang_pack, + * ] + * + * @return Vector_of_LangPackLanguage + */ + public function getLanguages(array $params); + + /** + * @param array params [ + * string lang_pack, + * string lang_code, + * ] + * + * @return LangPackLanguage + */ + public function getLanguage(array $params); } diff --git a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php index 1da25923f..854c4fef4 100644 --- a/src/danog/MadelineProto/Loop/Connection/WriteLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/WriteLoop.php @@ -162,7 +162,7 @@ class WriteLoop extends ResumableSignalLoop } } if ($API->is_http($datacenter) && !$has_http_wait) { - $connection->pending_outgoing[$connection->pending_outgoing_key++] = ['_' => 'http_wait', 'serialized_body' => yield $this->API->serialize_object_async(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 1], 'http_wait'), 'content_related' => true, 'unencrypted' => false, 'method' => true]; + $connection->pending_outgoing[$connection->pending_outgoing_key++] = ['_' => 'http_wait', 'serialized_body' => yield $this->API->serialize_object_async(['type' => ''], ['_' => 'http_wait', 'max_wait' => 30000, 'wait_after' => 0, 'max_delay' => 0], 'http_wait'), 'content_related' => true, 'unencrypted' => false, 'method' => true]; $connection->pending_outgoing_key %= Connection::PENDING_MAX; $has_http_wait = true; } diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index f8e0eeaf8..2c8d3d215 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -253,7 +253,7 @@ class MTProto extends AsyncConstruct implements TLCallback { return $this->datacenter->fileGetContents($url); } - + public function __wakeup() { $backtrace = debug_backtrace(0, 3); @@ -906,9 +906,11 @@ class MTProto extends AsyncConstruct implements TLCallback public function startUpdateSystem($anyway = false) { - if ($this->asyncInitPromise || $anyway) { + if ($this->asyncInitPromise || !$anyway) { + $this->logger("Not starting update system"); return; } + $this->logger("Starting update system"); if (!isset($this->seqUpdater)) { $this->seqUpdater = new SeqLoop($this); diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index 8dce19972..f74208571 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -29,6 +29,8 @@ use function Amp\Promise\first; use function Amp\Promise\some; use function Amp\Promise\timeout; use function Amp\Promise\wait; +use function Amp\ByteStream\getStdin; +use function Amp\ByteStream\getStdout; /** * Some tools. @@ -331,7 +333,26 @@ trait Tools { return new \Amp\Delayed($time * 1000); } + public function readLine($prompt = '') + { + return $this->call($this->readLineAsync($prompt)); + } + public function readLineAsync($prompt = '') + { + $stdin = getStdin(); + $stdout = getStdout(); + if ($prompt) { + yield $stdout->write($prompt); + } + static $lines = ['']; + while (count($lines) < 2 && ($chunk = yield $stdin->read()) !== null) { + $chunk = explode("\n", str_replace(["\r", "\n\n"], "\n", $chunk)); + $lines[count($lines) - 1] .= array_shift($chunk); + $lines = array_merge($lines, $chunk); + } + return array_shift($lines); + } public function is_array_or_alike($var) { return is_array($var) || diff --git a/src/danog/MadelineProto/Wrappers/ApiStart.php b/src/danog/MadelineProto/Wrappers/ApiStart.php index 8fd095de1..a2ee389ab 100644 --- a/src/danog/MadelineProto/Wrappers/ApiStart.php +++ b/src/danog/MadelineProto/Wrappers/ApiStart.php @@ -19,7 +19,6 @@ namespace danog\MadelineProto\Wrappers; -use function Amp\ByteStream\getStdin; use function Amp\ByteStream\getStdout; /** @@ -30,45 +29,31 @@ trait ApiStart public function api_start_async($settings) { if (php_sapi_name() === 'cli') { - $stdin = getStdin(); $stdout = getStdout(); - $readline = function ($prompt = null) use ($stdout, $stdin) { - if ($prompt) { - yield $stdout->write($prompt); - } - static $lines = ['']; - while (count($lines) < 2 && ($chunk = yield $stdin->read()) !== null) { - $chunk = explode("\n", str_replace(["\r", "\n\n"], "\n", $chunk)); - $lines[count($lines) - 1] .= array_shift($chunk); - $lines = array_merge($lines, $chunk); - } - - return array_shift($lines); - }; - echo 'You did not define a valid API ID/API hash. Do you want to define it now manually, or automatically? (m/a) -Note that you can also provide the API parameters directly in the code using the settings: https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsapp_infoapi_id'.PHP_EOL; - if (strpos(yield $readline('Your choice (m/a): '), 'm') !== false) { - echo '1) Login to my.telegram.org + yield $stdout->write('You did not define a valid API ID/API hash. Do you want to define it now manually, or automatically? (m/a) +Note that you can also provide the API parameters directly in the code using the settings: https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsapp_infoapi_id'.PHP_EOL); + if (strpos(yield $this->readLine('Your choice (m/a): '), 'm') !== false) { + yield $stdout->write('1) Login to my.telegram.org 2) Go to API development tools 3) App title: your app\'s name, can be anything Short name: your app\'s short name, can be anything URL: your app/website\'s URL, or t.me/yourusername Platform: anything Description: Describe your app here -4) Click on create application'.PHP_EOL; - $app['api_id'] = yield $readline('5) Enter your API ID: '); - $app['api_hash'] = yield $readline('6) Enter your API hash: '); +4) Click on create application'.PHP_EOL); + $app['api_id'] = yield $this->readLine('5) Enter your API ID: '); + $app['api_hash'] = yield $this->readLine('6) Enter your API hash: '); return $app; } else { $this->my_telegram_org_wrapper = new \danog\MadelineProto\MyTelegramOrgWrapper($settings); - yield $this->my_telegram_org_wrapper->login_async(yield $readline('Enter a phone number that is already registered on Telegram: ')); - yield $this->my_telegram_org_wrapper->complete_login_async(yield $readline('Enter the verification code you received in telegram: ')); + yield $this->my_telegram_org_wrapper->login_async(yield $this->readLine('Enter a phone number that is already registered on Telegram: ')); + yield $this->my_telegram_org_wrapper->complete_login_async(yield $this->readLine('Enter the verification code you received in telegram: ')); if (!yield $this->my_telegram_org_wrapper->has_app_async()) { - $app_title = yield $readline('Enter the app\'s name, can be anything: '); - $short_name = yield $readline('Enter the app\'s short name, can be anything: '); - $url = yield $readline('Enter the app/website\'s URL, or t.me/yourusername: '); - $description = yield $readline('Describe your app: '); + $app_title = yield $this->readLine('Enter the app\'s name, can be anything: '); + $short_name = yield $this->readLine('Enter the app\'s short name, can be anything: '); + $url = yield $this->readLine('Enter the app/website\'s URL, or t.me/yourusername: '); + $description = yield $this->readLine('Describe your app: '); $app = yield $this->my_telegram_org_wrapper->create_app_async(['app_title' => $app_title, 'app_shortname' => $short_name, 'app_url' => $url, 'app_platform' => 'web', 'app_desc' => $description]); } else { $app = yield $this->my_telegram_org_wrapper->get_app_async(); diff --git a/src/danog/MadelineProto/Wrappers/Start.php b/src/danog/MadelineProto/Wrappers/Start.php index 6d9feea67..7ebdee4dc 100644 --- a/src/danog/MadelineProto/Wrappers/Start.php +++ b/src/danog/MadelineProto/Wrappers/Start.php @@ -33,31 +33,16 @@ trait Start return yield $this->get_self_async(); } if (php_sapi_name() === 'cli') { - $stdin = getStdin(); - $stdout = getStdout(); - $readline = function ($prompt = null) use ($stdout, $stdin) { - if ($prompt) { - yield $stdout->write($prompt); - } - static $lines = ['']; - while (count($lines) < 2 && ($chunk = yield $stdin->read()) !== null) { - $chunk = explode("\n", str_replace(["\r", "\n\n"], "\n", $chunk)); - $lines[count($lines) - 1] .= array_shift($chunk); - $lines = array_merge($lines, $chunk); - } - - return array_shift($lines); - }; - if (strpos(yield $readline('Do you want to login as user or bot (u/b)? '), 'b') !== false) { - yield $this->bot_login_async(yield $readline('Enter your bot token: ')); + if (strpos(yield $this->readLine('Do you want to login as user or bot (u/b)? '), 'b') !== false) { + yield $this->bot_login_async(yield $this->readLine('Enter your bot token: ')); } else { - yield $this->phone_login_async(yield $readline('Enter your phone number: ')); - $authorization = yield $this->complete_phone_login_async(yield $readline('Enter the phone code: ')); + yield $this->phone_login_async(yield $this->readLine('Enter your phone number: ')); + $authorization = yield $this->complete_phone_login_async(yield $this->readLine('Enter the phone code: ')); if ($authorization['_'] === 'account.password') { - $authorization = yield $this->complete_2fa_login_async(yield $readline('Please enter your password (hint '.$authorization['hint'].'): ')); + $authorization = yield $this->complete_2fa_login_async(yield $this->readLine('Please enter your password (hint '.$authorization['hint'].'): ')); } if ($authorization['_'] === 'account.needSignup') { - $authorization = yield $this->complete_signup_async(yield $readline('Please enter your first name: '), yield $readline('Please enter your last name (can be empty): ')); + $authorization = yield $this->complete_signup_async(yield $this->readLine('Please enter your first name: '), yield $this->readLine('Please enter your last name (can be empty): ')); } } $this->serialize(); diff --git a/tests/testing.php b/tests/testing.php index 9a9f28d1d..dcb27526e 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -51,11 +51,6 @@ try { $MadelineProto->accept_tos(); } } - -/* - * If this session is not logged in, login - */ -if ($MadelineProto->get_self() === false) { /* * If a BOT_TOKEN is defined in .env, use it to login, else prompt for login info */ @@ -64,7 +59,6 @@ if ($MadelineProto->get_self() === false) { } else { $MadelineProto->bot_login(getenv('BOT_TOKEN')); } -} //var_dump(count($MadelineProto->get_pwr_chat('@madelineproto')['participants']));