From 8119e791e4f98797462a5121e636abf63a7ce1a8 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 5 Nov 2024 21:22:33 -0500 Subject: [PATCH] Add RestrictChatMember method to bot library --- src/TgBotLib/Enums/Methods.php | 3 ++ src/TgBotLib/Methods/RestrictChatMember.php | 52 +++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/TgBotLib/Methods/RestrictChatMember.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 011005c..933aad0 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -18,6 +18,7 @@ use TgBotLib\Methods\GetUserProfilePhotos; use TgBotLib\Methods\GetWebhookInfo; use TgBotLib\Methods\Logout; + use TgBotLib\Methods\RestrictChatMember; use TgBotLib\Methods\SendAnimation; use TgBotLib\Methods\SendAudio; use TgBotLib\Methods\SendChatAction; @@ -72,6 +73,7 @@ case GET_FILE = 'getFile'; case BAN_CHAT_MEMBER = 'banChatMember'; case UNBAN_CHAT_MEMBER = 'unbanChatMember'; + case RESTRICT_CHAT_MEMBER = 'restrictChatMember'; /** * Executes a command on the provided bot with the given parameters. @@ -117,6 +119,7 @@ self::GET_FILE => GetFile::execute($bot, $parameters), self::BAN_CHAT_MEMBER => BanChatMember::execute($bot, $parameters), self::UNBAN_CHAT_MEMBER => UnbanChatMember::execute($bot, $parameters), + self::RESTRICT_CHAT_MEMBER => RestrictChatMember::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/RestrictChatMember.php b/src/TgBotLib/Methods/RestrictChatMember.php new file mode 100644 index 0000000..1e5f5ee --- /dev/null +++ b/src/TgBotLib/Methods/RestrictChatMember.php @@ -0,0 +1,52 @@ +toArray()); + } + else + { + $parameters['permissions'] = json_encode($parameters['permissions']); + } + + return (bool)$bot->sendRequest(Methods::RESTRICT_CHAT_MEMBER->value, $parameters); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id', + 'user_id', + 'permissions' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'use_independent_chat_permissions', + 'until_date' + ]; + } + } \ No newline at end of file