From 6119b39ec7ee87ddcf7906ac459fe9048af90639 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 28 Nov 2024 00:22:42 -0500 Subject: [PATCH] Add SendGame method --- src/TgBotLib/Enums/Methods.php | 6 ++- src/TgBotLib/Methods/SendGame.php | 68 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/TgBotLib/Methods/SendGame.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index b8af170..39baf1b 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -32,6 +32,7 @@ use TgBotLib\Methods\DeleteMessages; use TgBotLib\Methods\DeleteMyCommands; use TgBotLib\Methods\DeleteStickerFromSet; + use TgBotLib\Methods\DeleteStickerSet; use TgBotLib\Methods\DeleteWebhook; use TgBotLib\Methods\EditChatInviteLink; use TgBotLib\Methods\EditChatSubscriptionInviteLink; @@ -83,6 +84,7 @@ use TgBotLib\Methods\SendContact; use TgBotLib\Methods\SendDice; use TgBotLib\Methods\SendDocument; + use TgBotLib\Methods\SendGame; use TgBotLib\Methods\SendInvoice; use TgBotLib\Methods\SendLocation; use TgBotLib\Methods\SendMediaGroup; @@ -251,6 +253,7 @@ case ANSWER_PRE_CHECKOUT_QUERY = 'answerPreCheckoutQuery'; case GET_STAR_TRANSACTIONS = 'getStarTransactions'; case SET_PASSPORT_DATA_ERRORS = 'setPassportDataErrors'; + case SEND_GAME = 'sendGame'; /** * Executes a command on the provided bot with the given parameters. @@ -376,7 +379,7 @@ self::SET_STICKER_SET_TITLE => SetStickerSetTitle::execute($bot, $parameters), self::SET_STICKER_SET_THUMBNAIL => SetStickerSetThumbnail::execute($bot, $parameters), self::SET_CUSTOM_EMOJI_STICKER_SET_THUMBNAIL => SetCustomEmojiStickerSetThumbnail::execute($bot, $parameters), - self::DELETE_STICKER_SET => DeleteStickerFromSet::execute($bot, $parameters), + self::DELETE_STICKER_SET => DeleteStickerSet::execute($bot, $parameters), self::ANSWER_INLINE_QUERY => AnswerInlineQuery::execute($bot, $parameters), self::ANSWER_WEB_APP_QUERY => AnswerWebAppQuery::execute($bot, $parameters), self::SAVE_PREPARED_INLINE_MESSAGE => SavePreparedInlineMessage::execute($bot, $parameters), @@ -386,6 +389,7 @@ self::ANSWER_PRE_CHECKOUT_QUERY => AnswerPreCheckoutQuery::execute($bot, $parameters), self::GET_STAR_TRANSACTIONS => GetStarTransactions::execute($bot, $parameters), self::SET_PASSPORT_DATA_ERRORS => SetPassportDataErrors::execute($bot, $parameters), + self::SEND_GAME => SendGame::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SendGame.php b/src/TgBotLib/Methods/SendGame.php new file mode 100644 index 0000000..159e37a --- /dev/null +++ b/src/TgBotLib/Methods/SendGame.php @@ -0,0 +1,68 @@ +toArray(); + } + + if (isset($parameters['reply_markup'])) + { + if ($parameters['reply_markup'] instanceof ObjectTypeInterface) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']->toArray()); + } + elseif (is_array($parameters['reply_markup'])) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']); + } + } + + return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::SEND_GAME->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id', + 'game_short_name' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'message_thread_id', + 'disable_notification', + 'protect_content', + 'allow_paid_broadcasts', + 'message_effect_id', + 'reply_parameters', + 'reply_markup' + ]; + } + } \ No newline at end of file