Skip to content

Commit

Permalink
Various code updates and tweaks to readme and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
noplanman committed Dec 11, 2021
1 parent bf7ed5b commit 8709149
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -263,7 +263,7 @@ public function getType(): string
'reply_markup',
];

$is_command = is_string($command = $this->getCommand()) && strlen($command) > 0;
$is_command = ($this->getCommand() ?? '') !== '';
foreach ($types as $type) {
if ($this->getProperty($type) !== null) {
if ($is_command && $type === 'text') {
Expand Down
36 changes: 25 additions & 11 deletions src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 <[email protected]>
* @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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions utils/db-schema-update/0.74.0-unreleased.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`;

0 comments on commit 8709149

Please sign in to comment.