Skip to content

Commit 643d359

Browse files
committed
Various code updates and tweaks to readme and changelog
1 parent bf7ed5b commit 643d359

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
77
### Notes
88
- [:ledger: View file changes][Unreleased][:page_with_curl: DB migration script][unreleased-sql-migration]
99
### Added
10+
- Ability to directly set commands paths. (@wright-tw, @noplanman) (#1252)
1011
- Bot API 5.4. (@TiiFuchs, @noplanman) (#1266)
1112
- Bot API 5.5. (@TiiFuchs, @noplanman) (#1267)
1213
- The field `message_auto_delete_time` was added to the Chat Entity (@TiiFuchs) (#1265)
1314
### Changed
1415
### Deprecated
1516
### Removed
16-
- [: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.
17+
- [:exclamation:][unreleased-bc-removed-chatactions] Removed deprecated `ChatAction::` `RECORD_AUDIO` and `UPLOAD_AUDIO`. Use `RECORD_VOICE` and `UPLOAD_VOICE` instead.
1718
### Fixed
19+
- PHP 8.1 deprecations. (@maxgorovenko) (#1260)
1820
### Security
1921

2022
## [0.74.0] - 2021-06-26
@@ -541,7 +543,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
541543
### Deprecated
542544
- Move `hideKeyboard` to `removeKeyboard`.
543545

544-
[unreleased-sql-migration]: #
546+
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/0.74.0-unreleased.sql
545547
[unreleased-bc-removed-chatactions]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#removed-deprecated-chatactions
546548
[0.74.0-bc-chatmember-subentities]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#chatmember-subentities
547549
[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

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A Telegram Bot based on the official [Telegram Bot API]
99

10-
[![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)
10+
[![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)
1111
[![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)
1212
[![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate%20%2F%20Support%20Us-blue.svg)](#donate)
1313

@@ -78,7 +78,7 @@ This Bot aims to provide a platform where one can simply write a bot and have in
7878

7979
The Bot can:
8080
- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods.
81-
- Supports all types and methods according to Telegram Bot API 5.3 (June 2021).
81+
- Supports all types and methods according to Telegram Bot API 5.5 (December 2021).
8282
- Supports supergroups.
8383
- Handle commands in chat with other bots.
8484
- 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
389389

390390
### Types
391391

392-
All types are implemented according to Telegram API 5.3 (June 2021).
392+
All types are implemented according to Telegram API 5.5 (December 2021).
393393

394394
### Inline Query
395395

396-
Full support for inline query according to Telegram API 5.3 (June 2021).
396+
Full support for inline query according to Telegram API 5.5 (December 2021).
397397

398398
### Methods
399399

400-
All methods are implemented according to Telegram API 5.3 (June 2021).
400+
All methods are implemented according to Telegram API 5.5 (December 2021).
401401

402402
#### Send Message
403403

src/Entities/Message.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ public function getCommand(): ?string
159159
return $command;
160160
}
161161

162-
$full_command = $this->getFullCommand();
163-
if (!is_string($full_command) || strpos($full_command, '/') !== 0) {
162+
$full_command = $this->getFullCommand() ?? '';
163+
if (strpos($full_command, '/') !== 0) {
164164
return null;
165165
}
166166
$full_command = substr($full_command, 1);
@@ -263,7 +263,7 @@ public function getType(): string
263263
'reply_markup',
264264
];
265265

266-
$is_command = is_string($command = $this->getCommand()) && strlen($command) > 0;
266+
$is_command = $this->getCommand() !== null;
267267
foreach ($types as $type) {
268268
if ($this->getProperty($type) !== null) {
269269
if ($is_command && $type === 'text') {

src/Telegram.php

+25-11
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,22 @@ public function addCommandClasses(array $command_classes): Telegram
831831
return $this;
832832
}
833833

834+
/**
835+
* Set a single custom commands path
836+
*
837+
* @param string $path Custom commands path to set
838+
*
839+
* @return Telegram
840+
*/
841+
public function setCommandsPath(string $path): Telegram
842+
{
843+
$this->commands_paths = [];
844+
845+
$this->addCommandsPath($path);
846+
847+
return $this;
848+
}
849+
834850
/**
835851
* Add a single custom commands path
836852
*
@@ -855,19 +871,17 @@ public function addCommandsPath(string $path, bool $before = true): Telegram
855871
}
856872

857873
/**
858-
* change Command folder path (other command folder about to invalid)
874+
* Set multiple custom commands paths
875+
*
876+
* @param array $paths Custom commands paths to add
859877
*
860-
* @param string $path Custom commands path
861-
* @author Wright <guan1992@gmail.com>
862878
* @return Telegram
863879
*/
864-
public function resetCommandsPaths(string $path): Telegram
880+
public function setCommandsPaths(array $paths): Telegram
865881
{
866-
if (!is_dir($path)) {
867-
TelegramLog::error('reset commands path "' . $path . '" does not exist.');
868-
} elseif (!in_array($path, $this->commands_paths, true)) {
869-
$this->commands_paths = [$path];
870-
}
882+
$this->commands_paths = [];
883+
884+
$this->addCommandsPaths($paths);
871885

872886
return $this;
873887
}
@@ -880,7 +894,7 @@ public function resetCommandsPaths(string $path): Telegram
880894
*
881895
* @return Telegram
882896
*/
883-
public function addCommandsPaths(array $paths, $before = true): Telegram
897+
public function addCommandsPaths(array $paths, bool $before = true): Telegram
884898
{
885899
foreach ($paths as $path) {
886900
$this->addCommandsPath($path, $before);
@@ -1048,7 +1062,7 @@ public function setWebhook(string $url, array $data = []): ServerResponse
10481062
'ip_address',
10491063
'max_connections',
10501064
'allowed_updates',
1051-
'drop_pending_updates'
1065+
'drop_pending_updates',
10521066
]));
10531067
$data['url'] = $url;
10541068

structure.sql

+2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ CREATE TABLE IF NOT EXISTS `message` (
8080
`forward_signature` TEXT NULL DEFAULT NULL COMMENT 'For messages forwarded from channels, signature of the post author if present',
8181
`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',
8282
`forward_date` timestamp NULL DEFAULT NULL COMMENT 'date the original message was sent in timestamp format',
83+
`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',
8384
`reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
8485
`reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message that this message is reply to',
8586
`via_bot` bigint NULL DEFAULT NULL COMMENT 'Optional. Bot through which the message was sent',
8687
`edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was last edited in Unix time',
88+
`has_protected_content` tinyint(1) DEFAULT 0 COMMENT 'True, if the message can''t be forwarded',
8789
`media_group_id` TEXT COMMENT 'The unique identifier of a media message group this message belongs to',
8890
`author_signature` TEXT COMMENT 'Signature of the post author for messages in channels',
8991
`text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8mb4',

utils/db-schema-update/0.74.0-unreleased.sql

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ CREATE TABLE IF NOT EXISTS `chat_join_request` (
1515

1616
ALTER TABLE `telegram_update` ADD COLUMN `chat_join_request_id` BIGINT UNSIGNED NULL COMMENT 'A request to join the chat has been sent';
1717
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`chat_join_request_id`) REFERENCES `chat_join_request` (`id`);
18+
19+
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`;
20+
ALTER TABLE `message` ADD COLUMN `has_protected_content` tinyint(1) DEFAULT 0 COMMENT 'True, if the message can''t be forwarded' AFTER `edit_date`;

0 commit comments

Comments
 (0)