diff --git a/CHANGELOG.md b/CHANGELOG.md index fc3e10ce..b2d104a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,16 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ### Notes - [:ledger: View file changes][Unreleased] ∙ [:page_with_curl: DB migration script][unreleased-sql-migration] ### Added +- Ability to directly set commands paths. (@wright-tw, @noplanman) (#1252) - Bot API 5.4. (@TiiFuchs, @noplanman) (#1266) - Bot API 5.5. (@TiiFuchs, @noplanman) (#1267) - The field `message_auto_delete_time` was added to the Chat Entity (@TiiFuchs) (#1265) ### Changed ### Deprecated ### Removed -- [:exclamation:][unreleased-bc-removed-chatactions] Removed ChatAction::RECORD_AUDIO and ChatAction::UPLOAD_AUDIO since it is deprecated for a while now. Use RECORD_VOICE and UPLOAD_VOICE instead. +- [:exclamation:][unreleased-bc-removed-chatactions] Removed deprecated `ChatAction::` `RECORD_AUDIO` and `UPLOAD_AUDIO`. Use `RECORD_VOICE` and `UPLOAD_VOICE` instead. ### Fixed +- PHP 8.1 deprecations. (@maxgorovenko) (#1260) ### Security ## [0.74.0] - 2021-06-26 @@ -541,7 +543,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ### Deprecated - Move `hideKeyboard` to `removeKeyboard`. -[unreleased-sql-migration]: # +[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/0.74.0-unreleased.sql [unreleased-bc-removed-chatactions]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#removed-deprecated-chatactions [0.74.0-bc-chatmember-subentities]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#chatmember-subentities [0.73.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.72.0-0.73.0.sql diff --git a/README.md b/README.md index 9e231908..32ec69c3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A Telegram Bot based on the official [Telegram Bot API] -[![API Version](https://img.shields.io/badge/Bot%20API-5.3%20%28June%202021%29-32a2da.svg)](https://core.telegram.org/bots/api#june-25-2021) +[![API Version](https://img.shields.io/badge/Bot%20API-5.5%20%28December%202021%29-32a2da.svg)](https://core.telegram.org/bots/api#december-7-2021) [![Join the bot support group on Telegram](https://img.shields.io/badge/telegram-@PHP__Telegram__Bot__Support-64659d.svg)](https://telegram.me/PHP_Telegram_Bot_Support) [![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate%20%2F%20Support%20Us-blue.svg)](#donate) @@ -78,7 +78,7 @@ This Bot aims to provide a platform where one can simply write a bot and have in The Bot can: - Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods. -- Supports all types and methods according to Telegram Bot API 5.3 (June 2021). +- Supports all types and methods according to Telegram Bot API 5.5 (December 2021). - Supports supergroups. - Handle commands in chat with other bots. - Manage Channel from the bot admin interface. @@ -389,15 +389,15 @@ The reason for denying an update can be defined with the `$reason` parameter. Th ### Types -All types are implemented according to Telegram API 5.3 (June 2021). +All types are implemented according to Telegram API 5.5 (December 2021). ### Inline Query -Full support for inline query according to Telegram API 5.3 (June 2021). +Full support for inline query according to Telegram API 5.5 (December 2021). ### Methods -All methods are implemented according to Telegram API 5.3 (June 2021). +All methods are implemented according to Telegram API 5.5 (December 2021). #### Send Message diff --git a/src/Entities/Message.php b/src/Entities/Message.php index 25a64006..c7c8b3d7 100644 --- a/src/Entities/Message.php +++ b/src/Entities/Message.php @@ -159,8 +159,8 @@ public function getCommand(): ?string return $command; } - $full_command = $this->getFullCommand(); - if (!is_string($full_command) || strpos($full_command, '/') !== 0) { + $full_command = $this->getFullCommand() ?? ''; + if (strpos($full_command, '/') !== 0) { return null; } $full_command = substr($full_command, 1); @@ -263,7 +263,7 @@ public function getType(): string 'reply_markup', ]; - $is_command = is_string($command = $this->getCommand()) && strlen($command) > 0; + $is_command = $this->getCommand() !== null; foreach ($types as $type) { if ($this->getProperty($type) !== null) { if ($is_command && $type === 'text') { diff --git a/src/Telegram.php b/src/Telegram.php index c5bad748..5bbf0054 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -831,6 +831,22 @@ public function addCommandClasses(array $command_classes): Telegram return $this; } + /** + * Set a single custom commands path + * + * @param string $path Custom commands path to set + * + * @return Telegram + */ + public function setCommandsPath(string $path): Telegram + { + $this->commands_paths = []; + + $this->addCommandsPath($path); + + return $this; + } + /** * Add a single custom commands path * @@ -855,19 +871,17 @@ public function addCommandsPath(string $path, bool $before = true): Telegram } /** - * change Command folder path (other command folder about to invalid) + * Set multiple custom commands paths + * + * @param array $paths Custom commands paths to add * - * @param string $path Custom commands path - * @author Wright * @return Telegram */ - public function resetCommandsPaths(string $path): Telegram + public function setCommandsPaths(array $paths): Telegram { - if (!is_dir($path)) { - TelegramLog::error('reset commands path "' . $path . '" does not exist.'); - } elseif (!in_array($path, $this->commands_paths, true)) { - $this->commands_paths = [$path]; - } + $this->commands_paths = []; + + $this->addCommandsPaths($paths); return $this; } @@ -880,7 +894,7 @@ public function resetCommandsPaths(string $path): Telegram * * @return Telegram */ - public function addCommandsPaths(array $paths, $before = true): Telegram + public function addCommandsPaths(array $paths, bool $before = true): Telegram { foreach ($paths as $path) { $this->addCommandsPath($path, $before); @@ -1048,7 +1062,7 @@ public function setWebhook(string $url, array $data = []): ServerResponse 'ip_address', 'max_connections', 'allowed_updates', - 'drop_pending_updates' + 'drop_pending_updates', ])); $data['url'] = $url; diff --git a/structure.sql b/structure.sql index 92716c29..df1cc2b5 100644 --- a/structure.sql +++ b/structure.sql @@ -80,10 +80,12 @@ CREATE TABLE IF NOT EXISTS `message` ( `forward_signature` TEXT NULL DEFAULT NULL COMMENT 'For messages forwarded from channels, signature of the post author if present', `forward_sender_name` TEXT NULL DEFAULT NULL COMMENT 'Sender''s name for messages forwarded from users who disallow adding a link to their account in forwarded messages', `forward_date` timestamp NULL DEFAULT NULL COMMENT 'date the original message was sent in timestamp format', + `is_automatic_forward` tinyint(1) DEFAULT 0 COMMENT 'True, if the message is a channel post that was automatically forwarded to the connected discussion group', `reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier', `reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message that this message is reply to', `via_bot` bigint NULL DEFAULT NULL COMMENT 'Optional. Bot through which the message was sent', `edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was last edited in Unix time', + `has_protected_content` tinyint(1) DEFAULT 0 COMMENT 'True, if the message can''t be forwarded', `media_group_id` TEXT COMMENT 'The unique identifier of a media message group this message belongs to', `author_signature` TEXT COMMENT 'Signature of the post author for messages in channels', `text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8mb4', diff --git a/utils/db-schema-update/0.74.0-unreleased.sql b/utils/db-schema-update/0.74.0-unreleased.sql index a1a0900f..02872e91 100644 --- a/utils/db-schema-update/0.74.0-unreleased.sql +++ b/utils/db-schema-update/0.74.0-unreleased.sql @@ -15,3 +15,6 @@ CREATE TABLE IF NOT EXISTS `chat_join_request` ( ALTER TABLE `telegram_update` ADD COLUMN `chat_join_request_id` BIGINT UNSIGNED NULL COMMENT 'A request to join the chat has been sent'; ALTER TABLE `telegram_update` ADD FOREIGN KEY (`chat_join_request_id`) REFERENCES `chat_join_request` (`id`); + +ALTER TABLE `message` ADD COLUMN `is_automatic_forward` tinyint(1) DEFAULT 0 COMMENT 'True, if the message is a channel post that was automatically forwarded to the connected discussion group' AFTER `forward_date`; +ALTER TABLE `message` ADD COLUMN `has_protected_content` tinyint(1) DEFAULT 0 COMMENT 'True, if the message can''t be forwarded' AFTER `edit_date`;