Skip to content

Commit

Permalink
Merge pull request #444 from BoShurik/ban-user
Browse files Browse the repository at this point in the history
Add getChatMemberCount and banChatMember
  • Loading branch information
BoShurik authored Aug 9, 2023
2 parents 2a76145 + f6a61d5 commit 8b5c551
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file
- Add missing phpDoc for `$replyMarkup` parameters
- Fix phpDoc for `\TelegramBot\Api\BotApi::setWebhook` `$allowedUpdates` parameter. Automatically serialize if array passed
- Fix phpDoc for `\TelegramBot\Api\Types\Message::$newChatMembers`
- Add `\TelegramBot\Api\BotApi::getChatMemberCount` method
- Add `\TelegramBot\Api\BotApi::banChatMember` method

### Deprecated
- Deprecate using `thumb*` methods in `\TelegramBot\Api\BotApi`
- Deprecate method `\TelegramBot\Api\BotApi::setStickerSetThumb`. Use `\TelegramBot\Api\BotApi::setStickerSetThumbnail` instead
- Deprecate `\TelegramBot\Api\Types\ReplyKeyboardHide` class
- Deprecate `\TelegramBot\Api\BotApi::getChatMembersCount`. Use `\TelegramBot\Api\BotApi::getChatMemberCount` instead
- Deprecate `\TelegramBot\Api\BotApi::kickChatMember`. Use `\TelegramBot\Api\BotApi::banChatMember` instead

## 2.4.0 - 2023-05-11

Expand Down
58 changes: 52 additions & 6 deletions src/BotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -1515,13 +1515,44 @@ function ($item) {
*/
public function kickChatMember($chatId, $userId, $untilDate = null)
{
@trigger_error(sprintf('Method "%s::%s" is deprecated. Use "banChatMember"', __CLASS__, __METHOD__), \E_USER_DEPRECATED);

return $this->call('kickChatMember', [
'chat_id' => $chatId,
'user_id' => $userId,
'until_date' => $untilDate
]);
}

/**
* Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels,
* the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first.
* The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
* Returns True on success.
*
* @param int|string $chatId Unique identifier for the target group or username of the
* target supergroup or channel (in the format @channelusername)
* @param int $userId Unique identifier of the target user
* @param null|int $untilDate Date when the user will be unbanned, unix time.
* If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever.
* Applied for supergroups and channels only.
* @param bool|null $revokeMessages Pass True to delete all messages from the chat for the user that is being removed.
* If False, the user will be able to see messages in the group that were sent before the user was removed.
* Always True for supergroups and channels.
*
* @return bool
* @throws Exception
*/
public function banChatMember($chatId, $userId, $untilDate = null, $revokeMessages = null)
{
return $this->call('banChatMember', [
'chat_id' => $chatId,
'user_id' => $userId,
'until_date' => $untilDate,
'revoke_messages' => $revokeMessages,
]);
}

/**
* Use this method to unban a previously kicked user in a supergroup.
* The user will not return to the group automatically, but will be able to join via link, etc.
Expand Down Expand Up @@ -2269,12 +2300,27 @@ public function leaveChat($chatId)
*/
public function getChatMembersCount($chatId)
{
return $this->call(
'getChatMembersCount',
[
'chat_id' => $chatId
]
);
@trigger_error(sprintf('Method "%s::%s" is deprecated. Use "getChatMemberCount"', __CLASS__, __METHOD__), \E_USER_DEPRECATED);

return $this->call('getChatMembersCount', [
'chat_id' => $chatId
]);
}

/**
* Use this method to get the number of members in a chat. Returns Int on success.
*
* @param string|int $chatId Unique identifier for the target chat or username of the target supergroup or channel
* (in the format @channelusername)
*
* @return int
* @throws Exception
*/
public function getChatMemberCount($chatId)
{
return $this->call('getChatMemberCount', [
'chat_id' => $chatId
]);
}

/**
Expand Down

0 comments on commit 8b5c551

Please sign in to comment.