From 307521debc55262770f450d6bd2437dfc1c60ea7 Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 6 Nov 2024 00:23:10 -0500 Subject: [PATCH] Add SetChatPermissions method to TgBotLib --- src/TgBotLib/Enums/Methods.php | 5 ++- src/TgBotLib/Methods/SetChatPermissions.php | 50 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/TgBotLib/Methods/SetChatPermissions.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 4f2d4c6..9657d4f 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -38,6 +38,7 @@ use TgBotLib\Methods\SendVideoNote; use TgBotLib\Methods\SendVoice; use TgBotLib\Methods\SetChatAdministratorCustomTitle; + use TgBotLib\Methods\SetChatPermissions; use TgBotLib\Methods\SetMessageReaction; use TgBotLib\Methods\SetWebhook; use TgBotLib\Methods\UnbanChatMember; @@ -82,6 +83,7 @@ case SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE = 'setChatAdministratorCustomTitle'; case BAN_CHAT_SENDER_CHAT = 'banChatSenderChat'; case UNBAN_CHAT_SENDER_CHAT = 'unbanChatSenderChat'; + case SET_CHAT_PERMISSIONS = 'setChatPermissions'; /** * Executes a command on the provided bot with the given parameters. @@ -131,7 +133,8 @@ self::PROMOTE_CHAT_MEMBER => PromoteChatMember::execute($bot, $parameters), self::SET_CHAT_ADMINISTRATOR_CUSTOM_TITLE => SetChatAdministratorCustomTitle::execute($bot, $parameters), self::BAN_CHAT_SENDER_CHAT => BanChatSenderChat::execute($bot, $parameters), - self::UNBAN_CHAT_SENDER_CHAT => UnbanChatSenderChat::execute($bot, $parameters) + self::UNBAN_CHAT_SENDER_CHAT => UnbanChatSenderChat::execute($bot, $parameters), + self::SET_CHAT_PERMISSIONS => SetChatPermissions::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SetChatPermissions.php b/src/TgBotLib/Methods/SetChatPermissions.php new file mode 100644 index 0000000..5d10fda --- /dev/null +++ b/src/TgBotLib/Methods/SetChatPermissions.php @@ -0,0 +1,50 @@ +toArray()); + } + else + { + $parameters['permissions'] = json_encode($parameters['permissions']); + } + + return (bool)$bot->sendRequest(Methods::SET_CHAT_PERMISSIONS->value, $parameters); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id', + 'permissions' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'use_independent_chat_permissions' + ]; + } + } \ No newline at end of file