From d19c74e35ac186c2036e6b43460e7ae7374ebaa2 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 28 Nov 2024 00:29:30 -0500 Subject: [PATCH] Add GetGameHighScores method --- src/TgBotLib/Enums/Methods.php | 3 + src/TgBotLib/Methods/GetGameHighScores.php | 42 ++++++++++++ src/TgBotLib/Objects/GameHighScore.php | 79 ++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 src/TgBotLib/Methods/GetGameHighScores.php create mode 100644 src/TgBotLib/Objects/GameHighScore.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index d9c54b3..5f984f1 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -55,6 +55,7 @@ use TgBotLib\Methods\GetCustomEmojiStickers; use TgBotLib\Methods\GetFile; use TgBotLib\Methods\GetForumTopicIconStickers; + use TgBotLib\Methods\GetGameHighScores; use TgBotLib\Methods\GetMe; use TgBotLib\Methods\GetMyCommands; use TgBotLib\Methods\GetMyDefaultAdministratorRights; @@ -256,6 +257,7 @@ case SET_PASSPORT_DATA_ERRORS = 'setPassportDataErrors'; case SEND_GAME = 'sendGame'; case SET_GAME_SCORE = 'setGameScore'; + case GET_GAME_HIGH_SCORES = 'getGameHighScores'; /** * Executes a command on the provided bot with the given parameters. @@ -393,6 +395,7 @@ self::SET_PASSPORT_DATA_ERRORS => SetPassportDataErrors::execute($bot, $parameters), self::SEND_GAME => SendGame::execute($bot, $parameters), self::SET_GAME_SCORE => SetGameScore::execute($bot, $parameters), + self::GET_GAME_HIGH_SCORES => GetGameHighScores::execute($bot, $parameters) }; } } diff --git a/src/TgBotLib/Methods/GetGameHighScores.php b/src/TgBotLib/Methods/GetGameHighScores.php new file mode 100644 index 0000000..6e07ba1 --- /dev/null +++ b/src/TgBotLib/Methods/GetGameHighScores.php @@ -0,0 +1,42 @@ + GameHighScore::fromArray($items), self::executeCurl(self::buildPost($bot, Methods::GET_GAME_HIGH_SCORES->value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'user_id' + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'chat_id', + 'message_id', + 'inline_message_id' + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/GameHighScore.php b/src/TgBotLib/Objects/GameHighScore.php new file mode 100644 index 0000000..78be49f --- /dev/null +++ b/src/TgBotLib/Objects/GameHighScore.php @@ -0,0 +1,79 @@ +position = $data['position']; + $this->user = User::fromArray($data['user']); + $this->score = $data['score']; + } + + /** + * Position in high score table for the game + * + * @return int + */ + public function getPosition(): int + { + return $this->position; + } + + /** + * User + * + * @return User + */ + public function getUser(): User + { + return $this->user; + } + + /** + * Score + * + * @return int + */ + public function getScore(): int + { + return $this->score; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'position' => $this->position, + 'user' => $this->user->toArray(), + 'score' => $this->score + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?GameHighScore + { + return new self($data); + } + } \ No newline at end of file