-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Last bits of missing methods and types
- Loading branch information
Showing
5 changed files
with
158 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace unreal4u\TelegramAPI\Telegram\Methods; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use unreal4u\TelegramAPI\Abstracts\TelegramMethods; | ||
use unreal4u\TelegramAPI\Abstracts\TelegramTypes; | ||
use unreal4u\TelegramAPI\Exceptions\InvalidResultType; | ||
use unreal4u\TelegramAPI\InternalFunctionality\TelegramRawData; | ||
use unreal4u\TelegramAPI\Telegram\Types\Custom\GameHighScoreArray; | ||
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean; | ||
use unreal4u\TelegramAPI\Telegram\Types\Message; | ||
|
||
/** | ||
* Use this method to get data for high score tables. Will return the score of the specified user and several of his | ||
* neighbors in a game. On success, returns an Array of GameHighScore objects. | ||
* | ||
* This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will | ||
* also return the top three users if the user and his neighbors are not among them. Please note that this behavior is | ||
* subject to change. | ||
* | ||
* Objects defined as-is January 2017 | ||
* | ||
* @see https://core.telegram.org/bots/api#getgamescore | ||
*/ | ||
class GetGameScore extends TelegramMethods | ||
{ | ||
/** | ||
* Target user id | ||
* @var int | ||
*/ | ||
public $user_id = 0; | ||
|
||
/** | ||
* Required if inline_message_id is not specified. Unique identifier for the target chat | ||
* @var int | ||
*/ | ||
public $chat_id; | ||
|
||
/** | ||
* Required if inline_message_id is not specified. Identifier of the sent message | ||
* @var int | ||
*/ | ||
public $message_id; | ||
|
||
/** | ||
* Required if chat_id and message_id are not specified. Identifier of the inline message | ||
* @var string | ||
*/ | ||
public $inline_message_id; | ||
|
||
public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes | ||
{ | ||
return new GameHighScoreArray($data->getResult(), $logger); | ||
} | ||
|
||
public function getMandatoryFields(): array | ||
{ | ||
// user_id and score are always mandatory | ||
$returnValue[] = 'user_id'; | ||
return $this->mandatoryUserOrInlineMessageId($returnValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace unreal4u\TelegramAPI\Telegram\Types\Custom; | ||
|
||
use unreal4u\TelegramAPI\Abstracts\CustomType; | ||
use unreal4u\TelegramAPI\Telegram\Types\ChatMember; | ||
use unreal4u\TelegramAPI\Interfaces\CustomArrayType; | ||
use Psr\Log\LoggerInterface; | ||
use unreal4u\TelegramAPI\Telegram\Types\GameHighScore; | ||
|
||
/** | ||
* Mockup class to generate a real telegram GameHighScore representation | ||
*/ | ||
class GameHighScoreArray extends CustomType implements CustomArrayType | ||
{ | ||
public $data = []; | ||
|
||
public function __construct(array $data = null, LoggerInterface $logger = null) | ||
{ | ||
if (!empty($data)) { | ||
foreach ($data as $id => $gameHighScore) { | ||
$this->data[$id] = new GameHighScore($gameHighScore, $logger); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Traverses through our $data, yielding the result set | ||
* | ||
* @return ChatMember[] | ||
*/ | ||
public function traverseObject() | ||
{ | ||
foreach ($this->data as $chatMember) { | ||
yield $chatMember; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace unreal4u\TelegramAPI\Telegram\Types; | ||
|
||
use unreal4u\TelegramAPI\Abstracts\TelegramTypes; | ||
use unreal4u\TelegramAPI\Telegram\Types\Custom\MessageEntityArray; | ||
use unreal4u\TelegramAPI\Telegram\Types\Custom\PhotoSizeArray; | ||
|
||
/** | ||
* This object represents one row of the high scores table for a game | ||
* | ||
* Objects defined as-is January 2017 | ||
* | ||
* @see https://core.telegram.org/bots/api#gamehighscore | ||
*/ | ||
class GameHighScore extends TelegramTypes | ||
{ | ||
/** | ||
* Position in high score table for the game | ||
* @var string | ||
*/ | ||
public $position = 0; | ||
|
||
/** | ||
* User | ||
* @var string | ||
*/ | ||
public $user; | ||
|
||
/** | ||
* Score | ||
* @var PhotoSize[] | ||
*/ | ||
public $score = 0; | ||
|
||
public function mapSubObjects(string $key, array $data): TelegramTypes | ||
{ | ||
switch ($key) { | ||
case 'user': | ||
return new User($data, $this->logger); | ||
} | ||
|
||
return parent::mapSubObjects($key, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters