Add GetGameHighScores method
This commit is contained in:
parent
ecac3c6ae5
commit
d19c74e35a
3 changed files with 124 additions and 0 deletions
|
@ -55,6 +55,7 @@
|
||||||
use TgBotLib\Methods\GetCustomEmojiStickers;
|
use TgBotLib\Methods\GetCustomEmojiStickers;
|
||||||
use TgBotLib\Methods\GetFile;
|
use TgBotLib\Methods\GetFile;
|
||||||
use TgBotLib\Methods\GetForumTopicIconStickers;
|
use TgBotLib\Methods\GetForumTopicIconStickers;
|
||||||
|
use TgBotLib\Methods\GetGameHighScores;
|
||||||
use TgBotLib\Methods\GetMe;
|
use TgBotLib\Methods\GetMe;
|
||||||
use TgBotLib\Methods\GetMyCommands;
|
use TgBotLib\Methods\GetMyCommands;
|
||||||
use TgBotLib\Methods\GetMyDefaultAdministratorRights;
|
use TgBotLib\Methods\GetMyDefaultAdministratorRights;
|
||||||
|
@ -256,6 +257,7 @@
|
||||||
case SET_PASSPORT_DATA_ERRORS = 'setPassportDataErrors';
|
case SET_PASSPORT_DATA_ERRORS = 'setPassportDataErrors';
|
||||||
case SEND_GAME = 'sendGame';
|
case SEND_GAME = 'sendGame';
|
||||||
case SET_GAME_SCORE = 'setGameScore';
|
case SET_GAME_SCORE = 'setGameScore';
|
||||||
|
case GET_GAME_HIGH_SCORES = 'getGameHighScores';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a command on the provided bot with the given parameters.
|
* 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::SET_PASSPORT_DATA_ERRORS => SetPassportDataErrors::execute($bot, $parameters),
|
||||||
self::SEND_GAME => SendGame::execute($bot, $parameters),
|
self::SEND_GAME => SendGame::execute($bot, $parameters),
|
||||||
self::SET_GAME_SCORE => SetGameScore::execute($bot, $parameters),
|
self::SET_GAME_SCORE => SetGameScore::execute($bot, $parameters),
|
||||||
|
self::GET_GAME_HIGH_SCORES => GetGameHighScores::execute($bot, $parameters)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
42
src/TgBotLib/Methods/GetGameHighScores.php
Normal file
42
src/TgBotLib/Methods/GetGameHighScores.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Methods;
|
||||||
|
|
||||||
|
use TgBotLib\Abstracts\Method;
|
||||||
|
use TgBotLib\Bot;
|
||||||
|
use TgBotLib\Enums\Methods;
|
||||||
|
use TgBotLib\Objects\GameHighScore;
|
||||||
|
|
||||||
|
class GetGameHighScores extends Method
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(Bot $bot, array $parameters = []): array
|
||||||
|
{
|
||||||
|
return array_map(fn(array $items) => 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'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
79
src/TgBotLib/Objects/GameHighScore.php
Normal file
79
src/TgBotLib/Objects/GameHighScore.php
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Objects;
|
||||||
|
|
||||||
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
|
|
||||||
|
class GameHighScore implements ObjectTypeInterface
|
||||||
|
{
|
||||||
|
private int $position;
|
||||||
|
private User $user;
|
||||||
|
private int $score;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This object represents one row of the high scores table for a game.
|
||||||
|
*
|
||||||
|
* @param array|null $data
|
||||||
|
*/
|
||||||
|
public function __construct(?array $data=null)
|
||||||
|
{
|
||||||
|
if($data === null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue