From 40d25a15f128ef6bf2736a66929fdc00094f79c4 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 30 Apr 2023 14:01:51 -0400 Subject: [PATCH] Added set methods to \TgBotLib\Objects\Telegram\InputMessageContent\InputTextMessageContent https://git.n64.cc/nosial/libs/tgbot/-/issues/3 --- .../InputTextMessageContent.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/TgBotLib/Objects/Telegram/InputMessageContent/InputTextMessageContent.php b/src/TgBotLib/Objects/Telegram/InputMessageContent/InputTextMessageContent.php index d2a4850..be6fb8b 100644 --- a/src/TgBotLib/Objects/Telegram/InputMessageContent/InputTextMessageContent.php +++ b/src/TgBotLib/Objects/Telegram/InputMessageContent/InputTextMessageContent.php @@ -1,9 +1,12 @@ message_text; } + /** + * Sets the value of 'message_text' property + * Text of the message to be sent, 1-4096 characters + * + * @param string $message_text + * @return $this + */ + public function setMessageText(string $message_text): self + { + if(!Validate::length($message_text, 1, 4096)) + throw new InvalidArgumentException('message_text should be between 1-4096 characters'); + + $this->message_text = $message_text; + return $this; + } + /** * Optional. Mode for parsing entities in the message text. * @@ -50,6 +69,28 @@ return $this->parse_mode; } + /** + * Sets the value of 'parse_mode' property + * Optional. Mode for parsing entities in the message text. + * + * @param string|null $parse_mode + * @return $this + */ + public function setParseMode(?string $parse_mode): self + { + if($parse_mode == null) + { + $this->parse_mode = null; + return $this; + } + + if(!in_array(strtolower($parse_mode), ['markdown', 'html'])) + throw new InvalidArgumentException('parse_mode should be either Markdown or HTML'); + + $this->parse_mode = strtolower($parse_mode); + return $this; + } + /** * Optional. List of special entities that appear in message text, which can be specified instead of parse_mode * @@ -60,16 +101,55 @@ return $this->entities; } + /** + * Sets the value of 'entities' property + * Optional. List of special entities that appear in message text, which can be specified instead of parse_mode + * + * @param MessageEntity[]|null $entities + * @return $this + */ + public function setEntities(?array $entities): self + { + if($entities == null) + { + $this->entities = null; + return $this; + } + + foreach($entities as $entity) + { + if(!($entity instanceof MessageEntity)) + throw new InvalidArgumentException('entities should be an array of MessageEntity objects'); + } + + $this->entities = $entities; + return $this; + } + /** * Optional. Disables link previews for links in the sent message * * @return bool + * @noinspection PhpUnused */ public function isDisableWebPagePreview(): bool { return $this->disable_web_page_preview; } + /** + * Sets the value of 'disable_web_page_preview' property + * Optional. Disables link previews for links in the sent message + * + * @param bool $disable_web_page_preview + * @return $this + */ + public function setDisableWebPagePreview(bool $disable_web_page_preview): self + { + $this->disable_web_page_preview = $disable_web_page_preview; + return $this; + } + /** * Returns an array representation of the object *