From b8f6c81833ab7faed8a7b1906c9c68c14d9f5774 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 31 Oct 2024 00:07:09 -0400 Subject: [PATCH] Added method SendDice --- src/TgBotLib/Enums/Methods.php | 3 + src/TgBotLib/Methods/SendDice.php | 60 +++++++++++++++ tests/TgBotLib/Methods/SendDiceTest.php | 99 +++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 src/TgBotLib/Methods/SendDice.php create mode 100644 tests/TgBotLib/Methods/SendDiceTest.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index aa84c61..a3739f3 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -15,6 +15,7 @@ use TgBotLib\Methods\SendAnimation; use TgBotLib\Methods\SendAudio; use TgBotLib\Methods\SendContact; + use TgBotLib\Methods\SendDice; use TgBotLib\Methods\SendDocument; use TgBotLib\Methods\SendLocation; use TgBotLib\Methods\SendMediaGroup; @@ -50,6 +51,7 @@ case SEND_VENUE = 'sendVenue'; case SEND_CONTACT = 'sendContact'; case SEND_POLL = 'sendPoll'; + case SEND_DICE = 'sendDice'; /** * Executes a command on the provided bot with the given parameters. @@ -84,6 +86,7 @@ self::SEND_VENUE => SendVenue::execute($bot, $parameters), self::SEND_CONTACT => SendContact::execute($bot, $parameters), self::SEND_POLL => SendPoll::execute($bot, $parameters), + self::SEND_DICE => SendDice::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SendDice.php b/src/TgBotLib/Methods/SendDice.php new file mode 100644 index 0000000..32ad303 --- /dev/null +++ b/src/TgBotLib/Methods/SendDice.php @@ -0,0 +1,60 @@ +toArray(); + } + + // Handle reply markup + if (isset($parameters['reply_markup']) && method_exists($parameters['reply_markup'], 'toArray')) + { + $parameters['reply_markup'] = $parameters['reply_markup']->toArray(); + } + + // Make request + return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::SEND_DICE->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'chat_id' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'message_thread_id', + 'emoji', + 'disable_notification', + 'protect_content', + 'message_effect_id', + 'reply_parameters', + 'reply_markup' + ]; + } + } \ No newline at end of file diff --git a/tests/TgBotLib/Methods/SendDiceTest.php b/tests/TgBotLib/Methods/SendDiceTest.php new file mode 100644 index 0000000..a65daad --- /dev/null +++ b/tests/TgBotLib/Methods/SendDiceTest.php @@ -0,0 +1,99 @@ +setAutoRetry(true); + } + + /** + * Tests the basic `sendVenue` functionality + * + * @return void + */ + public function testSendDice(): void + { + $result = self::$bot->sendDice( + chat_id: TEST_CHAT_ID, + emoji: '🎲' + ); + + $this->assertInstanceOf(Message::class, $result); + $this->assertNotNull($result->getDice()); + $this->assertEquals('🎲', $result->getDice()->getEmoji()); + } + + public function testSendTargetTest(): void + { + $result = self::$bot->sendDice( + chat_id: TEST_CHAT_ID, + emoji: '🎯' + ); + + $this->assertInstanceOf(Message::class, $result); + $this->assertNotNull($result->getDice()); + $this->assertEquals('🎯', $result->getDice()->getEmoji()); + } + + public function testSendBasketballTest(): void + { + $result = self::$bot->sendDice( + chat_id: TEST_CHAT_ID, + emoji: '🏀' + ); + + $this->assertInstanceOf(Message::class, $result); + $this->assertNotNull($result->getDice()); + $this->assertEquals('🏀', $result->getDice()->getEmoji()); + } + + public function testSendCousinsBowlingTest(): void + { + $result = self::$bot->sendDice( + chat_id: TEST_CHAT_ID, + emoji: '🎳' + ); + + $this->assertInstanceOf(Message::class, $result); + $this->assertNotNull($result->getDice()); + $this->assertEquals('🎳', $result->getDice()->getEmoji()); + } + + public function testSendSoccerTest(): void + { + $result = self::$bot->sendDice( + chat_id: TEST_CHAT_ID, + emoji: '⚽' + ); + + $this->assertInstanceOf(Message::class, $result); + $this->assertNotNull($result->getDice()); + $this->assertEquals('⚽', $result->getDice()->getEmoji()); + } + + public function testSlotMachineTest(): void + { + $result = self::$bot->sendDice( + chat_id: TEST_CHAT_ID, + emoji: '🎰' + ); + + $this->assertInstanceOf(Message::class, $result); + $this->assertNotNull($result->getDice()); + $this->assertEquals('🎰', $result->getDice()->getEmoji()); + } +} \ No newline at end of file