From 5ec6f7271add538b7fad31dbede24f1af6518cfc Mon Sep 17 00:00:00 2001 From: Netkas Date: Wed, 9 Aug 2023 15:32:45 -0400 Subject: [PATCH] * Renamed namespace from `\TgBotLib\Abstracts` to `\TgBotLib\Enums` * Updated class type to `final class` in `\TgBotLib\Enums > BotCommandScopeType` * Updated class type to `final class` in `\TgBotLib\Enums > ChatActionType` * Updated class type to `final class` in `\TgBotLib\Enums > ChatMemberStatus` * Updated class type to `final class` in `\TgBotLib\Enums > ChatType` * Updated class type to `final class` in `\TgBotLib\Enums > EventType` * Updated class type to `final class` in `\TgBotLib\Enums > InlineQueryResultType` * Updated class type to `final class` in `\TgBotLib\Enums > InputMediaType` * Updated class type to `final class` in `\TgBotLib\Enums > InputButtonType` * Updated class type to `final class` in `\TgBotLib\Enums > MessageEntityType` * Updated class type to `final class` in `\TgBotLib\Enums > PassportElementType` * Updated class type to `final class` in `\TgBotLib\Enums > PollType` * Updated class type to `final class` in `\TgBotLib\Enums > StickerFormat` * Updated class type to `final class` in `\TgBotLib\Enums > StickerType` * Updated class type to `final class` in `\TgBotLib\Enums > ThumbnailMimeType` * Updated class type to `final class` in `\TgBotLib\Enums > UpdateEventType` --- .idea/inspectionProfiles/Project_Default.xml | 3 + CHANGELOG.md | 16 ++ .../Abstracts/BotCommandScopeType.php | 14 -- src/TgBotLib/Abstracts/ChatActionType.php | 17 -- src/TgBotLib/Abstracts/ChatMemberStatus.php | 13 -- src/TgBotLib/Abstracts/ChatType.php | 11 - src/TgBotLib/Abstracts/EventType.php | 43 ---- src/TgBotLib/Abstracts/InputMediaType.php | 12 - src/TgBotLib/Abstracts/MenuButtonType.php | 11 - src/TgBotLib/Abstracts/MessageEntityType.php | 41 ---- .../Abstracts/PassportElementType.php | 20 -- src/TgBotLib/Abstracts/PollType.php | 10 - src/TgBotLib/Abstracts/StickerFormat.php | 10 - src/TgBotLib/Abstracts/StickerType.php | 12 - src/TgBotLib/Abstracts/ThumbnailMimeType.php | 10 - src/TgBotLib/Abstracts/UpdateEventType.php | 12 - src/TgBotLib/Bot.php | 46 ++-- src/TgBotLib/Classes/Validate.php | 1 - src/TgBotLib/Enums/BotCommandScopeType.php | 14 ++ src/TgBotLib/Enums/ChatActionType.php | 17 ++ src/TgBotLib/Enums/ChatMemberStatus.php | 13 ++ src/TgBotLib/Enums/ChatType.php | 11 + src/TgBotLib/Enums/EventType.php | 43 ++++ .../InlineQueryResultType.php | 54 ++--- src/TgBotLib/Enums/InputMediaType.php | 12 + src/TgBotLib/Enums/MenuButtonType.php | 10 + src/TgBotLib/Enums/MessageEntityType.php | 41 ++++ src/TgBotLib/Enums/PassportElementType.php | 20 ++ src/TgBotLib/Enums/PollType.php | 10 + src/TgBotLib/Enums/StickerFormat.php | 10 + src/TgBotLib/Enums/StickerType.php | 12 + src/TgBotLib/Enums/ThumbnailMimeType.php | 10 + src/TgBotLib/Enums/UpdateEventType.php | 12 + .../BotCommandScopeAllChatAdministrators.php | 4 +- .../BotCommandScopeAllGroupChats.php | 4 +- .../BotCommandScopeAllPrivateChats.php | 4 +- .../BotCommandScope/BotCommandScopeChat.php | 4 +- .../BotCommandScopeChatAdministrators.php | 4 +- .../BotCommandScopeChatMember.php | 4 +- .../BotCommandScopeDefault.php | 4 +- src/TgBotLib/Objects/Telegram/Chat.php | 2 +- .../ChatMember/ChatMemberAdministrator.php | 4 +- .../Telegram/ChatMember/ChatMemberBanned.php | 4 +- .../Telegram/ChatMember/ChatMemberLeft.php | 4 +- .../Telegram/ChatMember/ChatMemberMember.php | 4 +- .../Telegram/ChatMember/ChatMemberOwner.php | 4 +- .../ChatMember/ChatMemberRestricted.php | 4 +- .../Objects/Telegram/InlineQueryResult.php | 28 +-- .../InlineQueryResultArticle.php | 142 +++++++++++ .../InlineQueryResultAudio.php | 186 +++++++++++++++ .../InlineQueryResultContact.php | 139 +++++++++++ .../InlineQueryResultDocument.php | 205 ++++++++++++++++ .../InlineQueryResultGame.php | 39 ++++ .../InlineQueryResultGif.php | 221 +++++++++++++++++- .../InputMedia/InputMediaAnimation.php | 4 +- src/TgBotLib/Objects/Telegram/StickerSet.php | 2 +- 56 files changed, 1279 insertions(+), 332 deletions(-) delete mode 100644 src/TgBotLib/Abstracts/BotCommandScopeType.php delete mode 100644 src/TgBotLib/Abstracts/ChatActionType.php delete mode 100644 src/TgBotLib/Abstracts/ChatMemberStatus.php delete mode 100644 src/TgBotLib/Abstracts/ChatType.php delete mode 100644 src/TgBotLib/Abstracts/EventType.php delete mode 100644 src/TgBotLib/Abstracts/InputMediaType.php delete mode 100644 src/TgBotLib/Abstracts/MenuButtonType.php delete mode 100644 src/TgBotLib/Abstracts/MessageEntityType.php delete mode 100644 src/TgBotLib/Abstracts/PassportElementType.php delete mode 100644 src/TgBotLib/Abstracts/PollType.php delete mode 100644 src/TgBotLib/Abstracts/StickerFormat.php delete mode 100644 src/TgBotLib/Abstracts/StickerType.php delete mode 100644 src/TgBotLib/Abstracts/ThumbnailMimeType.php delete mode 100644 src/TgBotLib/Abstracts/UpdateEventType.php create mode 100644 src/TgBotLib/Enums/BotCommandScopeType.php create mode 100644 src/TgBotLib/Enums/ChatActionType.php create mode 100644 src/TgBotLib/Enums/ChatMemberStatus.php create mode 100644 src/TgBotLib/Enums/ChatType.php create mode 100644 src/TgBotLib/Enums/EventType.php rename src/TgBotLib/{Abstracts => Enums}/InlineQueryResultType.php (58%) create mode 100644 src/TgBotLib/Enums/InputMediaType.php create mode 100644 src/TgBotLib/Enums/MenuButtonType.php create mode 100644 src/TgBotLib/Enums/MessageEntityType.php create mode 100644 src/TgBotLib/Enums/PassportElementType.php create mode 100644 src/TgBotLib/Enums/PollType.php create mode 100644 src/TgBotLib/Enums/StickerFormat.php create mode 100644 src/TgBotLib/Enums/StickerType.php create mode 100644 src/TgBotLib/Enums/ThumbnailMimeType.php create mode 100644 src/TgBotLib/Enums/UpdateEventType.php diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index ea8af9c..a854623 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -19,6 +19,9 @@ diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d318b4..6ea6984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,22 @@ input objects for methods that require input objects. * Added method `\TgBotLib\Objects\Telegram\WebAppInfo::setUrl` to `\TgBotLib\Objects\Telegram\WebAppInfo` * Added methods `\TgBotLib\Classes\Validate::url`, `\TgBotLib\Classes\Validate::length`, & `\TgBotLib\Classes\Validate::isHttps` to `\TgBotLib\Classes\Validate` * Updated documentation for `\TgBotLib\Bot::editMessageMedia` + * Renamed namespace from `\TgBotLib\Abstracts` to `\TgBotLib\Enums` + * Updated class type to `final class` in `\TgBotLib\Enums > BotCommandScopeType` + * Updated class type to `final class` in `\TgBotLib\Enums > ChatActionType` + * Updated class type to `final class` in `\TgBotLib\Enums > ChatMemberStatus` + * Updated class type to `final class` in `\TgBotLib\Enums > ChatType` + * Updated class type to `final class` in `\TgBotLib\Enums > EventType` + * Updated class type to `final class` in `\TgBotLib\Enums > InlineQueryResultType` + * Updated class type to `final class` in `\TgBotLib\Enums > InputMediaType` + * Updated class type to `final class` in `\TgBotLib\Enums > InputButtonType` + * Updated class type to `final class` in `\TgBotLib\Enums > MessageEntityType` + * Updated class type to `final class` in `\TgBotLib\Enums > PassportElementType` + * Updated class type to `final class` in `\TgBotLib\Enums > PollType` + * Updated class type to `final class` in `\TgBotLib\Enums > StickerFormat` + * Updated class type to `final class` in `\TgBotLib\Enums > StickerType` + * Updated class type to `final class` in `\TgBotLib\Enums > ThumbnailMimeType` + * Updated class type to `final class` in `\TgBotLib\Enums > UpdateEventType` ## [6.6.0] - 2023-04-10 diff --git a/src/TgBotLib/Abstracts/BotCommandScopeType.php b/src/TgBotLib/Abstracts/BotCommandScopeType.php deleted file mode 100644 index eb6b79f..0000000 --- a/src/TgBotLib/Abstracts/BotCommandScopeType.php +++ /dev/null @@ -1,14 +0,0 @@ -handle($this, $update); break; - case EventType::Message: + case EventType::MESSAGE: if(($update->getMessage() ?? null) !== null) { $do_handle = true; } break; - case EventType::EditedMessage: + case EventType::EDITED_MESSAGE: if(($update->getEditedMessage() ?? null) !== null) { $do_handle = true; } break; - case EventType::GenericCommandMessage: + case EventType::GENERIC_COMMAND_MESSAGE: if(($update->getMessage() ?? null) !== null && ($update->getMessage()->getText() ?? null) !== null) { $text = $update->getMessage()->getText(); @@ -364,25 +364,25 @@ } break; - case EventType::ChatMemberJoined: + case EventType::CHAT_MEMBER_JOINED: if(($update->getMessage() ?? null) !== null && ($update->getMessage()->getNewChatMembers() ?? null) !== null) { $do_handle = true; } break; - case EventType::ChatMemberLeft: + case EventType::CHAT_MEMBER_LEFT: if(($update->getMessage() ?? null) !== null && ($update->getMessage()->getLeftChatMember() ?? null) !== null) { $do_handle = true; } break; - case EventType::ChatMemberKicked: + case EventType::CHAT_MEMBER_KICKED: if(($update->getMyChatMember() ?? null) !== null && ($update->getMyChatMember()->getNewChatMember() ?? null) !== null) { if( - $update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::Kicked && + $update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::KICKED && $update->getMyChatMember()->getNewChatMember()->getUntilDate() === null ) { @@ -391,11 +391,11 @@ } break; - case EventType::ChatMemberBanned: + case EventType::CHAT_MEMBER_BANNED: if(($update->getMyChatMember() ?? null) !== null && ($update->getMyChatMember()->getNewChatMember() ?? null) !== null) { if( - $update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::Kicked && + $update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::KICKED && $update->getMyChatMember()->getNewChatMember()->getUntilDate() !== null ) { @@ -404,53 +404,53 @@ } break; - case EventType::ChatMemberUnrestricted: - case EventType::ChatMemberDemoted: - case EventType::ChatMemberUnbanned: + case EventType::CHAT_MEMBER_UNRESTRICTED: + case EventType::CHAT_MEMBER_DEMOTED: + case EventType::CHAT_MEMBER_UNBANNED: if(($update->getMyChatMember() ?? null) !== null && ($update->getMyChatMember()->getNewChatMember() ?? null) !== null) { - if($update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::Member) + if($update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::MEMBER) { $do_handle = true; } } break; - case EventType::ChatMemberPromoted: + case EventType::CHAT_MEMBER_PROMOTED: if(($update->getMyChatMember() ?? null) !== null && ($update->getMyChatMember()->getNewChatMember() ?? null) !== null) { - if($update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::Administrator) + if($update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::ADMINISTRATOR) { $do_handle = true; } } break; - case EventType::ChatMemberRestricted: + case EventType::CHAT_MEMBER_RESTRICTED: if(($update->getMyChatMember() ?? null) !== null && ($update->getMyChatMember()->getNewChatMember() ?? null) !== null) { - if($update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::Restricted) + if($update->getMyChatMember()->getNewChatMember()->getStatus() === ChatMemberStatus::RESTRICTED) { $do_handle = true; } } break; - case EventType::ChatTitleChanged: + case EventType::CHAT_TITLE_CHANGED: if(($update->getMessage() ?? null) !== null && ($update->getMessage()->getNewChatTitle() ?? null) !== null) { $handler->handle($this, $update); } break; - case EventType::ChatPhotoChanged: + case EventType::CHAT_PHOTO_CHANGED: if(($update->getMessage() ?? null) !== null && ($update->getMessage()->getNewChatPhoto() ?? null) !== null) { $do_handle = true; } break; - case EventType::CallbackQuery: + case EventType::CALLBACK_QUERY: if(($update->getCallbackQuery() ?? null) !== null) { $do_handle = true; diff --git a/src/TgBotLib/Classes/Validate.php b/src/TgBotLib/Classes/Validate.php index 0793c9d..aa28921 100644 --- a/src/TgBotLib/Classes/Validate.php +++ b/src/TgBotLib/Classes/Validate.php @@ -26,7 +26,6 @@ public static function length(string $input, int $min_length, int $max_length): bool { $length = strlen($input); - return $length >= $min_length && $length <= $max_length; } diff --git a/src/TgBotLib/Enums/BotCommandScopeType.php b/src/TgBotLib/Enums/BotCommandScopeType.php new file mode 100644 index 0000000..1019015 --- /dev/null +++ b/src/TgBotLib/Enums/BotCommandScopeType.php @@ -0,0 +1,14 @@ +type = $data['type'] ?? BotCommandScopeType::AllChatAdministrators; + $object->type = $data['type'] ?? BotCommandScopeType::ALL_CHAT_ADMINISTRATORS; $object->chat_id = $data['chat_id'] ?? null; return $object; diff --git a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllGroupChats.php b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllGroupChats.php index 9dbe5cb..066e710 100644 --- a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllGroupChats.php +++ b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllGroupChats.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\BotCommandScope; - use TgBotLib\Abstracts\BotCommandScopeType; + use TgBotLib\Enums\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\BotCommandScope; @@ -47,7 +47,7 @@ { $object = new self(); - $object->type = $data['type'] ?? BotCommandScopeType::AllGroupChats; + $object->type = $data['type'] ?? BotCommandScopeType::ALL_CHAT_GROUPS; return $object; } diff --git a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllPrivateChats.php b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllPrivateChats.php index 01738f4..83e0403 100644 --- a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllPrivateChats.php +++ b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeAllPrivateChats.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\BotCommandScope; - use TgBotLib\Abstracts\BotCommandScopeType; + use TgBotLib\Enums\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\BotCommandScope; @@ -47,7 +47,7 @@ { $object = new self(); - $object->type = $data['type'] ?? BotCommandScopeType::AllPrivateChats; + $object->type = $data['type'] ?? BotCommandScopeType::ALL_PRIVATE_CHATS; return $object; } diff --git a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChat.php b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChat.php index 109d31b..1584ff7 100644 --- a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChat.php +++ b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChat.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\BotCommandScope; - use TgBotLib\Abstracts\BotCommandScopeType; + use TgBotLib\Enums\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\BotCommandScope; @@ -63,7 +63,7 @@ { $object = new self(); - $object->type = $data['type'] ?? BotCommandScopeType::Chat; + $object->type = $data['type'] ?? BotCommandScopeType::CHAT; $object->chat_id = $data['chat_id'] ?? null; return $object; diff --git a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatAdministrators.php b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatAdministrators.php index 4bab7c2..cf3d77f 100644 --- a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatAdministrators.php +++ b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatAdministrators.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\BotCommandScope; - use TgBotLib\Abstracts\BotCommandScopeType; + use TgBotLib\Enums\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\BotCommandScope; @@ -47,7 +47,7 @@ { $object = new self(); - $object->type = $data['type'] ?? BotCommandScopeType::ChatAdministrators; + $object->type = $data['type'] ?? BotCommandScopeType::CHAT_ADMINISTRATORS; return $object; } diff --git a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatMember.php b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatMember.php index 0f17768..d3f1a61 100644 --- a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatMember.php +++ b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeChatMember.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\BotCommandScope; - use TgBotLib\Abstracts\BotCommandScopeType; + use TgBotLib\Enums\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\BotCommandScope; @@ -79,7 +79,7 @@ { $object = new self(); - $object->type = $data['type'] ?? BotCommandScopeType::ChatMember; + $object->type = $data['type'] ?? BotCommandScopeType::CHAT_MEMBER; $object->chat_id = $data['chat_id'] ?? null; $object->user_id = $data['user_id'] ?? null; diff --git a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeDefault.php b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeDefault.php index cdb36dd..0bb4e5a 100644 --- a/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeDefault.php +++ b/src/TgBotLib/Objects/Telegram/BotCommandScope/BotCommandScopeDefault.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\BotCommandScope; - use TgBotLib\Abstracts\BotCommandScopeType; + use TgBotLib\Enums\BotCommandScopeType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\BotCommandScope; @@ -47,7 +47,7 @@ { $object = new self(); - $object->type = $data['type'] ?? BotCommandScopeType::Default; + $object->type = $data['type'] ?? BotCommandScopeType::DEFAULT; return $object; } diff --git a/src/TgBotLib/Objects/Telegram/Chat.php b/src/TgBotLib/Objects/Telegram/Chat.php index 7bd9941..b1d560f 100644 --- a/src/TgBotLib/Objects/Telegram/Chat.php +++ b/src/TgBotLib/Objects/Telegram/Chat.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram; - use TgBotLib\Abstracts\ChatType; + use TgBotLib\Enums\ChatType; use TgBotLib\Interfaces\ObjectTypeInterface; class Chat implements ObjectTypeInterface diff --git a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberAdministrator.php b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberAdministrator.php index 8a8ef15..90402d3 100644 --- a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberAdministrator.php +++ b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberAdministrator.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\ChatMember; - use TgBotLib\Abstracts\ChatMemberStatus; + use TgBotLib\Enums\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\ChatMember; use TgBotLib\Objects\Telegram\User; @@ -292,7 +292,7 @@ { $object = new self(); - $object->status = $data['status'] ?? ChatMemberStatus::Administrator; + $object->status = $data['status'] ?? ChatMemberStatus::ADMINISTRATOR; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->can_be_edited = $data['can_be_edited'] ?? false; $object->is_anonymous = $data['is_anonymous'] ?? false; diff --git a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberBanned.php b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberBanned.php index c30b8b8..69913d4 100644 --- a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberBanned.php +++ b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberBanned.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\ChatMember; - use TgBotLib\Abstracts\ChatMemberStatus; + use TgBotLib\Enums\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\ChatMember; use TgBotLib\Objects\Telegram\User; @@ -80,7 +80,7 @@ { $object = new self(); - $object->status = $data['status'] ?? ChatMemberStatus::Kicked; + $object->status = $data['status'] ?? ChatMemberStatus::KICKED; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->until_date = $data['until_date'] ?? null; diff --git a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberLeft.php b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberLeft.php index 7416a06..9134de0 100644 --- a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberLeft.php +++ b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberLeft.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\ChatMember; - use TgBotLib\Abstracts\ChatMemberStatus; + use TgBotLib\Enums\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\ChatMember; use TgBotLib\Objects\Telegram\User; @@ -64,7 +64,7 @@ { $object = new self(); - $object->status = $data['status'] ?? ChatMemberStatus::Left; + $object->status = $data['status'] ?? ChatMemberStatus::LEFT; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; return $object; diff --git a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberMember.php b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberMember.php index 935b235..d9c7329 100644 --- a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberMember.php +++ b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberMember.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\ChatMember; - use TgBotLib\Abstracts\ChatMemberStatus; + use TgBotLib\Enums\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\ChatMember; use TgBotLib\Objects\Telegram\User; @@ -64,7 +64,7 @@ { $object = new self(); - $object->status = $data['status'] ?? ChatMemberStatus::Member; + $object->status = $data['status'] ?? ChatMemberStatus::MEMBER; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; return $object; diff --git a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberOwner.php b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberOwner.php index 35c0522..2f93d2e 100644 --- a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberOwner.php +++ b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberOwner.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\ChatMember; - use TgBotLib\Abstracts\ChatMemberStatus; + use TgBotLib\Enums\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\ChatMember; use TgBotLib\Objects\Telegram\User; @@ -96,7 +96,7 @@ { $object = new ChatMemberOwner(); - $object->status = $data['status'] ?? ChatMemberStatus::Creator; + $object->status = $data['status'] ?? ChatMemberStatus::CREATOR; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->is_anonymous = $data['is_anonymous'] ?? false; $object->custom_title = $data['custom_title'] ?? null; diff --git a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberRestricted.php b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberRestricted.php index d575f96..bd53c8b 100644 --- a/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberRestricted.php +++ b/src/TgBotLib/Objects/Telegram/ChatMember/ChatMemberRestricted.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\ChatMember; - use TgBotLib\Abstracts\ChatMemberStatus; + use TgBotLib\Enums\ChatMemberStatus; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\ChatMember; use TgBotLib\Objects\Telegram\User; @@ -321,7 +321,7 @@ { $object = new static(); - $object->status = $data['status'] ?? ChatMemberStatus::Restricted; + $object->status = $data['status'] ?? ChatMemberStatus::RESTRICTED; $object->user = isset($data['user']) ? User::fromArray($data['user']) : null; $object->is_member = $data['is_member'] ?? false; $object->can_send_messages = $data['can_send_messages'] ?? false; diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult.php index 7abe31a..b306e65 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult.php @@ -3,7 +3,7 @@ namespace TgBotLib\Objects\Telegram; use InvalidArgumentException; - use TgBotLib\Abstracts\InlineQueryResultType; + use TgBotLib\Enums\InlineQueryResultType; use TgBotLib\Exceptions\NotImplementedException; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\InlineQueryResult\InlineQueryResultArticle; @@ -49,32 +49,32 @@ switch(strtolower($data['type'])) { - case InlineQueryResultType::Article: + case InlineQueryResultType::ARTICLE: return InlineQueryResultArticle::fromArray($data); - case InlineQueryResultType::Photo: + case InlineQueryResultType::PHOTO: return InlineQueryResultPhoto::fromArray($data); - case InlineQueryResultType::Gif: + case InlineQueryResultType::GIF: return InlineQueryResultGif::fromArray($data); - case InlineQueryResultType::Mpeg4Gif: + case InlineQueryResultType::MPEG_4_GIF: return InlineQueryResultMpeg4Gif::fromArray($data); - case InlineQueryResultType::Video: + case InlineQueryResultType::VIDEO: return InlineQueryResultVideo::fromArray($data); - case InlineQueryResultType::Audio: + case InlineQueryResultType::AUDIO: return InlineQueryResultAudio::fromArray($data); - case InlineQueryResultType::Voice: + case InlineQueryResultType::VOICE: return InlineQueryResultVoice::fromArray($data); - case InlineQueryResultType::Document: + case InlineQueryResultType::DOCUMENT: return InlineQueryResultDocument::fromArray($data); - case InlineQueryResultType::Location: + case InlineQueryResultType::LOCATION: return InlineQueryResultLocation::fromArray($data); - case InlineQueryResultType::Venue: + case InlineQueryResultType::VENUE: return InlineQueryResultVenue::fromArray($data); - case InlineQueryResultType::Contact: + case InlineQueryResultType::CONTACT: return InlineQueryResultContact::fromArray($data); - case InlineQueryResultType::Game: + case InlineQueryResultType::GAME: return InlineQueryResultGame::fromArray($data); default: - throw new InvalidArgumentException(sprintf('The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"', $data['type'], implode('", "', InlineQueryResultType::All))); + throw new InvalidArgumentException(sprintf('The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"', $data['type'], implode('", "', InlineQueryResultType::ALL))); } } } \ No newline at end of file diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultArticle.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultArticle.php index 5e65f7a..4908103 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultArticle.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultArticle.php @@ -1,9 +1,12 @@ id; } + /** + * Sets the value of the 'id' field. + * Unique identifier for this result, 1-64 Bytes + * + * @param string $id + * @return $this + */ + public function setId(string $id): InlineQueryResultArticle + { + if(!Validate::length($id, 1, 64)) + throw new InvalidArgumentException('id should be between 1-64 characters'); + + $this->id = $id; + return $this; + } + /** * Title of the result * @@ -107,6 +126,19 @@ return $this->title; } + /** + * Sets the value of the 'title' field. + * Title of the result + * + * @param string $title + * @return $this + */ + public function setTitle(string $title): InlineQueryResultArticle + { + $this->title = $title; + return $this; + } + /** * Content of the message to be sent * @@ -117,6 +149,19 @@ return $this->input_message_content; } + /** + * Sets the value of the 'input_message_content' field. + * Content of the message to be sent + * + * @param InputContactMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null $input_message_content + * @return $this + */ + public function setInputMessageContent(InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|null $input_message_content): InlineQueryResultArticle + { + $this->input_message_content = $input_message_content; + return $this; + } + /** * Optional. Inline keyboard attached to the message * @@ -127,6 +172,19 @@ return $this->reply_markup; } + /** + * Sets the value of the 'reply_markup' field. + * Optional. Inline keyboard attached to the message + * + * @param InlineKeyboardMarkup|null $reply_markup + * @return $this + */ + public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultArticle + { + $this->reply_markup = $reply_markup; + return $this; + } + /** * Optional. URL of the result * @@ -137,6 +195,22 @@ return $this->url; } + /** + * Sets the value of the 'url' field. + * Optional. URL of the result + * + * @param string|null $url + * @return $this + */ + public function setUrl(?string $url): InlineQueryResultArticle + { + if(!Validate::url($url)) + throw new InvalidArgumentException(sprintf('url is not a valid url: %s', $url)); + + $this->url = $url; + return $this; + } + /** * Optional. Pass True if you don't want the URL to be shown in the message * @@ -147,6 +221,19 @@ return $this->hide_url; } + /** + * Sets the value of the 'hide_url' field. + * Optional. Pass True if you don't want the URL to be shown in the message + * + * @param bool $hide_url + * @return $this + */ + public function setHideUrl(bool $hide_url): InlineQueryResultArticle + { + $this->hide_url = $hide_url; + return $this; + } + /** * Optional. Short description of the result * @@ -157,6 +244,19 @@ return $this->description; } + /** + * Sets the value of the 'description' field. + * Optional. Short description of the result + * + * @param string|null $description + * @return $this + */ + public function setDescription(?string $description): InlineQueryResultArticle + { + $this->description = $description; + return $this; + } + /** * Optional. Url of the thumbnail for the result * @@ -167,6 +267,22 @@ return $this->thumbnail_url; } + /** + * Sets the value of the 'thumbnail_url' field. + * Optional. Url of the thumbnail for the result + * + * @param string|null $thumbnail_url + * @return $this + */ + public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultArticle + { + if(!Validate::url($thumbnail_url)) + throw new InvalidArgumentException(sprintf('thumbnail_url is not a valid url: %s', $thumbnail_url)); + + $this->thumbnail_url = $thumbnail_url; + return $this; + } + /** * Optional. Thumbnail width * @@ -177,6 +293,19 @@ return $this->thumbnail_width; } + /** + * Sets the value of the 'thumbnail_width' field. + * Optional. Thumbnail width + * + * @param int|null $thumbnail_width + * @return $this + */ + public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultArticle + { + $this->thumbnail_width = $thumbnail_width; + return $this; + } + /** * Optional. Thumbnail height * @@ -187,6 +316,19 @@ return $this->thumbnail_height; } + /** + * Sets the value of the 'thumbnail_height' field. + * Optional. Thumbnail height + * + * @param int|null $thumbnail_height + * @return $this + */ + public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultArticle + { + $this->thumbnail_height = $thumbnail_height; + return $this; + } + /** * Returns an array representation of the object * diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultAudio.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultAudio.php index efe8e1a..fd6ff1c 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultAudio.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultAudio.php @@ -1,9 +1,12 @@ id; } + /** + * Sets the value of 'id' property + * Unique identifier for this result, 1-64 bytes + * + * @param string $id + * @return $this + */ + public function setId(string $id): InlineQueryResultAudio + { + if(!Validate::length($id, 1, 64)) + { + throw new InvalidArgumentException(sprintf('id must be between 1 and 64 characters long, got %s characters', $id)); + } + + $this->id = $id; + return $this; + } + /** * A valid URL for the audio file * @@ -108,6 +129,22 @@ return $this->audio_url; } + /** + * Sets the value of 'audio_url' property + * A valid URL for the audio file + * + * @param string $audio_url + * @return $this + */ + public function setAudioUrl(string $audio_url): InlineQueryResultAudio + { + if(!Validate::url($audio_url)) + throw new InvalidArgumentException(sprintf('audio_url is not a valid URL: %s', $audio_url)); + + $this->audio_url = $audio_url; + return $this; + } + /** * Title * @@ -118,6 +155,19 @@ return $this->title; } + /** + * Sets the value of 'title' property + * Title + * + * @param string $title + * @return $this + */ + public function setTitle(string $title): InlineQueryResultAudio + { + $this->title = $title; + return $this; + } + /** * Optional. Caption, 0-1024 characters after entities parsing * @@ -128,6 +178,28 @@ return $this->caption; } + /** + * Sets the value of 'caption' property + * Optional. Caption, 0-1024 characters after entities parsing + * + * @param string|null $caption + * @return $this + */ + public function setCaption(?string $caption): InlineQueryResultAudio + { + if($caption == null) + { + $this->caption = null; + return $this; + } + + if(!Validate::length($caption, 0, 1024)) + throw new InvalidArgumentException(sprintf('caption must be between 0 and 1024 characters long, got %s characters', $caption)); + + $this->caption = $caption; + return $this; + } + /** * Optional. Mode for parsing entities in the audio caption. See formatting options for more details. * @@ -138,6 +210,28 @@ return $this->parse_mode; } + /** + * Sets the value of 'parse_mode' property + * Optional. Mode for parsing entities in the audio caption. See formatting options for more details. + * + * @param string|null $parse_mode + * @return $this + */ + public function setParseMode(?string $parse_mode): InlineQueryResultAudio + { + if($parse_mode == null) + { + $this->parse_mode = null; + return $this; + } + + if(!in_array(strtolower($parse_mode), ['markdown', 'html'])) + throw new InvalidArgumentException(sprintf('parse_mode must be one of Markdown, HTML, got %s', $parse_mode)); + + $this->parse_mode = $parse_mode; + return $this; + } + /** * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode * @@ -148,6 +242,34 @@ return $this->caption_entities; } + /** + * Sets the value of 'caption_entities' property + * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + * + * @param MessageEntity[]|null $caption_entities + * @return $this + */ + public function setCaptionEntities(?array $caption_entities): InlineQueryResultAudio + { + if($caption_entities == null) + { + $this->caption_entities = null; + return $this; + } + + $this->caption_entities = []; + + foreach($caption_entities as $entity) + { + if(!$entity instanceof MessageEntity) + throw new InvalidArgumentException(sprintf('caption_entities must be array of MessageEntity, got %s', gettype($entity))); + + $this->caption_entities[] = $entity; + } + + return $this; + } + /** * Optional. Performer * @@ -158,6 +280,25 @@ return $this->performer; } + /** + * Sets the value of 'performer' property + * Optional. Performer + * + * @param string|null $performer + * @return $this + */ + public function setPerformer(?string $performer): InlineQueryResultAudio + { + if($performer == null) + { + $this->performer = null; + return $this; + } + + $this->performer = $performer; + return $this; + } + /** * Optional. Audio duration in seconds * @@ -168,6 +309,25 @@ return $this->audio_duration; } + /** + * Sets the value of 'audio_duration' property + * Optional. Audio duration in seconds + * + * @param int|null $audio_duration + * @return $this + */ + public function setAudioDuration(?int $audio_duration): InlineQueryResultAudio + { + if($audio_duration == null) + { + $this->audio_duration = null; + return $this; + } + + $this->audio_duration = $audio_duration; + return $this; + } + /** * Optional. Inline keyboard attached to the message * @@ -178,6 +338,19 @@ return $this->reply_markup; } + /** + * Sets the value of 'reply_markup' property + * Optional. Inline keyboard attached to the message + * + * @param InlineKeyboardMarkup|null $reply_markup + * @return $this + */ + public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultAudio + { + $this->reply_markup = $reply_markup; + return $this; + } + /** * Optional. Content of the message to be sent instead of the audio * @@ -188,6 +361,19 @@ return $this->input_message_content; } + /** + * Sets the value of 'input_message_content' property + * Optional. Content of the message to be sent instead of the audio + * + * @param InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null $input_message_content + * @return $this + */ + public function setInputMessageContent(InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null $input_message_content): InlineQueryResultAudio + { + $this->input_message_content = $input_message_content; + return $this; + } + /** * Returns an array representation of the object * diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultContact.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultContact.php index 51f066a..2511c48 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultContact.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultContact.php @@ -1,9 +1,12 @@ id; } + /** + * Sets the value of 'id' property + * Unique identifier for this result, 1-64 Bytes + * + * @param string $id + * @return $this + */ + public function setId(string $id): self + { + if(!Validate::length($id, 1, 64)) + throw new InvalidArgumentException('id should be between 1-64 characters'); + + $this->id = $id; + return $this; + } + /** * Contact's phone number * @@ -108,6 +127,19 @@ return $this->phone_number; } + /** + * Sets the value of 'phone_number' property + * Contact's phone number + * + * @param string $phone_number + * @return $this + */ + public function setPhoneNumber(string $phone_number): self + { + $this->phone_number = $phone_number; + return $this; + } + /** * Contact's first name * @@ -118,6 +150,19 @@ return $this->first_name; } + /** + * Sets the value of 'first_name' property + * Contact's first name + * + * @param string $first_name + * @return $this + */ + public function setFirstName(string $first_name): self + { + $this->first_name = $first_name; + return $this; + } + /** * Optional. Contact's last name * @@ -128,6 +173,19 @@ return $this->last_name; } + /** + * Sets the value of 'last_name' property + * Optional. Contact's last name + * + * @param string|null $last_name + * @return $this + */ + public function setLastName(?string $last_name): self + { + $this->last_name = $last_name; + return $this; + } + /** * Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes * @@ -138,6 +196,22 @@ return $this->vcard; } + /** + * Sets the value of 'vcard' property + * Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes + * + * @param string|null $vcard + * @return $this + */ + public function setVcard(?string $vcard): self + { + if(!Validate::length($vcard, 0, 2048)) + throw new InvalidArgumentException('vcard should be between 0-2048 characters'); + + $this->vcard = $vcard; + return $this; + } + /** * Optional. Inline keyboard attached to the message * @@ -148,6 +222,19 @@ return $this->reply_markup; } + /** + * Sets the value of 'reply_markup' property + * Optional. Inline keyboard attached to the message + * + * @param InlineKeyboardMarkup|null $reply_markup + * @return $this + */ + public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): self + { + $this->reply_markup = $reply_markup; + return $this; + } + /** * Optional. Content of the message to be sent instead of the contact * @@ -158,6 +245,19 @@ return $this->input_message_content; } + /** + * Sets the value of 'input_message_content' property + * Optional. Content of the message to be sent instead of the contact + * + * @param InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null $input_message_content + * @return $this + */ + public function setInputMessageContent(InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null $input_message_content): self + { + $this->input_message_content = $input_message_content; + return $this; + } + /** * Optional. Url of the thumbnail for the result * @@ -168,6 +268,19 @@ return $this->thumbnail_url; } + /** + * Sets the value of 'thumbnail_url' property + * Optional. Url of the thumbnail for the result + * + * @param string|null $thumbnail_url + * @return $this + */ + public function setThumbnailUrl(?string $thumbnail_url): self + { + $this->thumbnail_url = $thumbnail_url; + return $this; + } + /** * Optional. Thumbnail width * @@ -178,6 +291,19 @@ return $this->thumbnail_width; } + /** + * Sets the value of 'thumbnail_width' property + * Optional. Thumbnail width + * + * @param int|null $thumbnail_width + * @return $this + */ + public function setThumbnailWidth(?int $thumbnail_width): self + { + $this->thumbnail_width = $thumbnail_width; + return $this; + } + /** * Optional. Thumbnail height * @@ -188,6 +314,19 @@ return $this->thumbnail_height; } + /** + * Sets the value of 'thumbnail_height' property + * Optional. Thumbnail height + * + * @param int|null $thumbnail_height + * @return $this + */ + public function setThumbnailHeight(?int $thumbnail_height): self + { + $this->thumbnail_height = $thumbnail_height; + return $this; + } + /** * Returns an array representation of the object * diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultDocument.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultDocument.php index dc13922..b2facc3 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultDocument.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultDocument.php @@ -1,9 +1,12 @@ title; } + /** + * Sets the value of the 'title' field. + * Title for the result + * + * @param string $title + * @return $this + */ + public function setTitle(string $title): InlineQueryResultDocument + { + $this->title = $title; + return $this; + } + /** * Optional. Caption of the document to be sent, 0-1024 characters after entities parsing * @@ -133,6 +149,30 @@ return $this->caption; } + /** + * Sets the value of the 'caption' field. + * Optional. Caption of the document to be sent, 0-1024 characters after entities parsing + * + * @param string|null $caption + * @return $this + */ + public function setCaption(?string $caption): InlineQueryResultDocument + { + if($caption == null) + { + $this->caption = null; + return $this; + } + + if(!Validate::length($caption, 0, 1024)) + { + throw new InvalidArgumentException("Caption must be between 0 and 1024 characters"); + } + + $this->caption = $caption; + return $this; + } + /** * Optional. Mode for parsing entities in the document caption. See formatting options for more details. * @@ -143,6 +183,30 @@ return $this->parse_mode; } + /** + * Sets the value of the 'parse_mode' field. + * Optional. Mode for parsing entities in the document caption. See formatting options for more details. + * + * @param string|null $parse_mode + * @return $this + */ + public function setParseMode(?string $parse_mode): InlineQueryResultDocument + { + if($parse_mode == null) + { + $this->parse_mode = null; + return $this; + } + + if(!in_array(strtolower($parse_mode), ['markdown', 'html'])) + { + throw new InvalidArgumentException("Parse mode must be either Markdown or HTML"); + } + + $this->parse_mode = $parse_mode; + return $this; + } + /** * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode * @@ -153,6 +217,33 @@ return $this->caption_entities; } + /** + * Sets the value of the 'caption_entities' field. + * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + * + * @param MessageEntity[]|null $caption_entities + * @return $this + */ + public function setCaptionEntities(?array $caption_entities): InlineQueryResultDocument + { + if($caption_entities == null) + { + $this->caption_entities = null; + return $this; + } + + foreach($caption_entities as $entity) + { + if(!($entity instanceof MessageEntity)) + { + throw new InvalidArgumentException("Caption entities must be an array of MessageEntity"); + } + } + + $this->caption_entities = $caption_entities; + return $this; + } + /** * A valid URL for the file * @@ -163,6 +254,24 @@ return $this->document_url; } + /** + * Sets the value of the 'document_url' field. + * A valid URL for the file + * + * @param string $document_url + * @return $this + */ + public function setDocumentUrl(string $document_url): InlineQueryResultDocument + { + if(!Validate::url($document_url)) + { + throw new InvalidArgumentException("Document URL must be a valid URL"); + } + + $this->document_url = $document_url; + return $this; + } + /** * MIME type of the content of the file, either “application/pdf” or “application/zip” * @@ -173,6 +282,19 @@ return $this->mime_type; } + /** + * Sets the value of the 'mime_type' field. + * MIME type of the content of the file, either “application/pdf” or “application/zip” + * + * @param string $mime_type + * @return $this + */ + public function setMimeType(string $mime_type): InlineQueryResultDocument + { + $this->mime_type = $mime_type; + return $this; + } + /** * Optional. Short description of the result * @@ -183,6 +305,19 @@ return $this->description; } + /** + * Sets the value of the 'description' field. + * Optional. Short description of the result + * + * @param string|null $description + * @return $this + */ + public function setDescription(?string $description): InlineQueryResultDocument + { + $this->description = $description; + return $this; + } + /** * Optional. Inline keyboard attached to the message * @@ -193,6 +328,19 @@ return $this->reply_markup; } + /** + * Sets the value of the 'reply_markup' field. + * Optional. Inline keyboard attached to the message + * + * @param InlineKeyboardMarkup|null $reply_markup + * @return $this + */ + public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultDocument + { + $this->reply_markup = $reply_markup; + return $this; + } + /** * Optional. Content of the message to be sent instead of the file * @@ -203,6 +351,19 @@ return $this->input_message_content; } + /** + * Sets the value of the 'input_message_content' field. + * Optional. Content of the message to be sent instead of the file + * + * @param InputContactMessageContent|InputInvoiceMessageContent|InputLocationMessageContent|InputTextMessageContent|InputVenueMessageContent|null $input_message_content + * @return $this + */ + public function setInputMessageContent(InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null $input_message_content): InlineQueryResultDocument + { + $this->input_message_content = $input_message_content; + return $this; + } + /** * Optional. URL of the thumbnail (JPEG only) for the file * @@ -213,6 +374,24 @@ return $this->thumbnail_url; } + /** + * Sets the value of the 'thumbnail_url' field. + * Optional. URL of the thumbnail (JPEG only) for the file + * + * @param string|null $thumbnail_url + * @return $this + */ + public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultDocument + { + if($thumbnail_url != null && !Validate::url($thumbnail_url)) + { + throw new InvalidArgumentException("Thumbnail URL must be a valid URL"); + } + + $this->thumbnail_url = $thumbnail_url; + return $this; + } + /** * Optional. Thumbnail width * @@ -223,6 +402,19 @@ return $this->thumbnail_width; } + /** + * Sets the value of the 'thumbnail_width' field. + * Optional. Thumbnail width + * + * @param int|null $thumbnail_width + * @return $this + */ + public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultDocument + { + $this->thumbnail_width = $thumbnail_width; + return $this; + } + /** * Optional. Thumbnail height * @@ -233,6 +425,19 @@ return $this->thumbnail_height; } + /** + * Sets the value of the 'thumbnail_height' field. + * Optional. Thumbnail height + * + * @param int|null $thumbnail_height + * @return $this + */ + public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultDocument + { + $this->thumbnail_height = $thumbnail_height; + return $this; + } + /** * Returns an array representation of the object * diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGame.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGame.php index 8ec5717..25c7a43 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGame.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGame.php @@ -1,5 +1,6 @@ id; } + /** + * Sets the value of the 'id' field + * Unique identifier for this result, 1-64 bytes + * + * @param string $id + * @return InlineQueryResultGame + */ + public function setId(string $id): InlineQueryResultGame + { + $this->id = $id; + return $this; + } + /** * Short name of the game * @@ -59,6 +73,19 @@ return $this->game_short_name; } + /** + * Sets the value of the 'game_short_name' field + * Short name of the game + * + * @param string $game_short_name + * @return InlineQueryResultGame + */ + public function setGameShortName(string $game_short_name): InlineQueryResultGame + { + $this->game_short_name = $game_short_name; + return $this; + } + /** * Optional. Inline keyboard attached to the message * @@ -69,6 +96,18 @@ return $this->reply_markup; } + /** + * Optional. Inline keyboard attached to the message + * + * @param InlineKeyboardMarkup|null $reply_markup + * @return InlineQueryResultGame + */ + public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultGame + { + $this->reply_markup = $reply_markup; + return $this; + } + /** * Returns an array representation of the object * diff --git a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGif.php b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGif.php index a91bbd8..abe63bb 100644 --- a/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGif.php +++ b/src/TgBotLib/Objects/Telegram/InlineQueryResult/InlineQueryResultGif.php @@ -5,7 +5,9 @@ namespace TgBotLib\Objects\Telegram\InlineQueryResult; - use TgBotLib\Abstracts\ThumbnailMimeType; + use InvalidArgumentException; + use TgBotLib\Enums\ThumbnailMimeType; + use TgBotLib\Classes\Validate; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\InlineKeyboardMarkup; use TgBotLib\Objects\Telegram\InputMessageContent\InputContactMessageContent; @@ -116,6 +118,24 @@ return $this->id; } + /** + * Sets the value of the 'id' field. + * Unique identifier for this result, 1-64 bytes + * + * @param string $id + * @return $this + */ + public function setId(string $id): InlineQueryResultGif + { + if(!Validate::length($id, 1, 64)) + { + throw new InvalidArgumentException(); + } + + $this->id = $id; + return $this; + } + /** * A valid URL for the GIF file. File size must not exceed 1MB * @@ -126,6 +146,24 @@ return $this->gif_url; } + /** + * Sets the value of the 'gif_url' field. + * A valid URL for the GIF file. File size must not exceed 1MB + * + * @param string $gif_url + * @return $this + */ + public function setGifUrl(string $gif_url): InlineQueryResultGif + { + if(!Validate::url($gif_url)) + { + throw new InvalidArgumentException(sprintf('"%s" is not a valid url', $gif_url)); + } + + $this->gif_url = $gif_url; + return $this; + } + /** * Optional. Width of the GIF * @@ -136,6 +174,19 @@ return $this->gif_width; } + /** + * Sets the value of the 'gif_width' field. + * Optional. Width of the GIF + * + * @param int $gif_width + * @return $this + */ + public function setGifWidth(int $gif_width): InlineQueryResultGif + { + $this->gif_width = $gif_width; + return $this; + } + /** * Optional. Height of the GIF * @@ -146,6 +197,25 @@ return $this->gif_height; } + /** + * Sets the value of the 'gif_height' field. + * Optional. Height of the GIF + * + * @param int|null $gif_height + * @return $this + */ + public function setGifHeight(?int $gif_height): InlineQueryResultGif + { + if(is_null($gif_height)) + { + $this->gif_height = null; + return $this; + } + + $this->gif_height = $gif_height; + return $this; + } + /** * Optional. Duration of the GIF in seconds * @@ -156,6 +226,25 @@ return $this->gif_duration; } + /** + * Sets the value of the 'gif_duration' field. + * Optional. Duration of the GIF in seconds + * + * @param int|null $gif_duration + * @return $this + */ + public function setGifDuration(?int $gif_duration): InlineQueryResultGif + { + if(is_null($gif_duration)) + { + $this->gif_duration = null; + return $this; + } + + $this->gif_duration = $gif_duration; + return $this; + } + /** * URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result * @@ -166,6 +255,24 @@ return $this->thumbnail_url; } + /** + * Sets the value of the 'thumbnail_url' field. + * URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result + * + * @param string $thumbnail_url + * @return $this + */ + public function setThumbnailUrl(string $thumbnail_url): InlineQueryResultGif + { + if(!Validate::url($thumbnail_url)) + { + throw new InvalidArgumentException(sprintf('"%s" is not a valid url', $thumbnail_url)); + } + + $this->thumbnail_url = $thumbnail_url; + return $this; + } + /** * Optional. MIME type of the thumbnail, must be one of “image/jpeg”, “image/gif”, or “video/mp4”. Defaults to “image/jpeg” * @@ -176,6 +283,25 @@ return $this->thumbnail_mime_type; } + /** + * Sets the value of the 'thumbnail_mime_type' field. + * Optional. MIME type of the thumbnail, must be one of “image/jpeg”, “image/gif”, or “video/mp4”. Defaults to “image/jpeg” + * + * @param string|null $thumbnail_mime_type + * @return $this + */ + public function setThumbnailMimeType(?string $thumbnail_mime_type): InlineQueryResultGif + { + if(is_null($thumbnail_mime_type)) + { + $this->thumbnail_mime_type = null; + return $this; + } + + $this->thumbnail_mime_type = $thumbnail_mime_type; + return $this; + } + /** * Optional. Title for the result * @@ -186,6 +312,19 @@ return $this->title; } + /** + * Sets the value of the 'title' field. + * Optional. Title for the result + * + * @param string|null $title + * @return $this + */ + public function setTitle(?string $title): InlineQueryResultGif + { + $this->title = $title; + return $this; + } + /** * Optional. Caption of the GIF file to be sent, 0-1024 characters after entities parsing * @@ -196,6 +335,19 @@ return $this->caption; } + /** + * Sets the value of the 'caption' field. + * Optional. Caption of the GIF file to be sent, 0-1024 characters after entities parsing + * + * @param string|null $caption + * @return $this + */ + public function setCaption(?string $caption): InlineQueryResultGif + { + $this->caption = $caption; + return $this; + } + /** * Optional. Mode for parsing entities in the caption. See formatting options for more details. * @@ -206,6 +358,19 @@ return $this->parse_mode; } + /** + * Sets the value of the 'parse_mode' field. + * Optional. Mode for parsing entities in the caption. See formatting options for more details. + * + * @param string|null $parse_mode + * @return $this + */ + public function setParseMode(?string $parse_mode): InlineQueryResultGif + { + $this->parse_mode = $parse_mode; + return $this; + } + /** * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode * @@ -216,6 +381,34 @@ return $this->caption_entities; } + /** + * Sets the value of the 'caption_entities' field. + * Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + * + * @param MessageEntity[]|null $caption_entities + * @return $this + */ + public function setCaptionEntities(?array $caption_entities): InlineQueryResultGif + { + if($caption_entities == null) + { + $this->caption_entities = null; + return $this; + } + + $this->caption_entities = []; + + foreach($caption_entities as $entity) + { + if(!$entity instanceof MessageEntity) + throw new InvalidArgumentException(sprintf('caption_entities must be array of MessageEntity, got %s', gettype($entity))); + + $this->caption_entities[] = $entity; + } + + return $this; + } + /** * Optional. Inline keyboard attached to the message * @@ -226,6 +419,19 @@ return $this->reply_markup; } + /** + * Sets the value of the 'reply_markup' field. + * Optional. Inline keyboard attached to the message + * + * @param InlineKeyboardMarkup|null $reply_markup + * @return $this + */ + public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultGif + { + $this->reply_markup = $reply_markup; + return $this; + } + /** * Optional. Content of the message to be sent instead of the GIF animation * @@ -236,6 +442,19 @@ return $this->input_message_content; } + /** + * Sets the value of the 'input_message_content' field. + * Optional. Content of the message to be sent instead of the GIF animation + * + * @param InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null $input_message_content + * @return $this + */ + public function setInputMessageContent(InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null $input_message_content): InlineQueryResultGif + { + $this->input_message_content = $input_message_content; + return $this; + } + /** * Returns an array representation of the object diff --git a/src/TgBotLib/Objects/Telegram/InputMedia/InputMediaAnimation.php b/src/TgBotLib/Objects/Telegram/InputMedia/InputMediaAnimation.php index 02fb20b..5150d4d 100644 --- a/src/TgBotLib/Objects/Telegram/InputMedia/InputMediaAnimation.php +++ b/src/TgBotLib/Objects/Telegram/InputMedia/InputMediaAnimation.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram\InputMedia; - use TgBotLib\Abstracts\InputMediaType; + use TgBotLib\Enums\InputMediaType; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Telegram\InputMedia; use TgBotLib\Objects\Telegram\MessageEntity; @@ -208,7 +208,7 @@ public static function fromArray(array $data): self { $object = new static(); - $object->type = $data['type'] ?? InputMediaType::Animation; + $object->type = $data['type'] ?? InputMediaType::ANIMATION; $object->media = $data['media'] ?? null; $object->thumb = $data['thumb'] ?? null; $object->caption = $data['caption'] ?? null; diff --git a/src/TgBotLib/Objects/Telegram/StickerSet.php b/src/TgBotLib/Objects/Telegram/StickerSet.php index 101b305..e0f961c 100644 --- a/src/TgBotLib/Objects/Telegram/StickerSet.php +++ b/src/TgBotLib/Objects/Telegram/StickerSet.php @@ -4,7 +4,7 @@ namespace TgBotLib\Objects\Telegram; - use TgBotLib\Abstracts\StickerType; + use TgBotLib\Enums\StickerType; use TgBotLib\Interfaces\ObjectTypeInterface; class StickerSet implements ObjectTypeInterface