Unverified Commit 6e12b420 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #732 from noplanman/726-games

Implement Telegram Games platform.
parents 9bf5c34e 4c7beab8
...@@ -6,6 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -6,6 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased] ## [Unreleased]
### Added ### Added
- `ChatAction` class to simplify chat action selection. - `ChatAction` class to simplify chat action selection.
- Telegram Games platform!
### Changed ### Changed
- [:exclamation:][unreleased-bc-rename-constants] Rename and ensure no redefinition of constants: `BASE_PATH` -> `TB_BASE_PATH`, `BASE_COMMANDS_PATH` -> `TB_BASE_COMMANDS_PATH`. - [:exclamation:][unreleased-bc-rename-constants] Rename and ensure no redefinition of constants: `BASE_PATH` -> `TB_BASE_PATH`, `BASE_COMMANDS_PATH` -> `TB_BASE_COMMANDS_PATH`.
### Deprecated ### Deprecated
......
...@@ -825,7 +825,7 @@ class DB ...@@ -825,7 +825,7 @@ class DB
( (
`id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`, `id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
`forward_date`, `reply_to_chat`, `reply_to_message`, `media_group_id`, `text`, `entities`, `audio`, `document`, `forward_date`, `reply_to_chat`, `reply_to_message`, `media_group_id`, `text`, `entities`, `audio`, `document`,
`photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`, `game`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
`location`, `venue`, `new_chat_members`, `left_chat_member`, `location`, `venue`, `new_chat_members`, `left_chat_member`,
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`, `new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_chat_created`, `supergroup_chat_created`, `channel_chat_created`,
...@@ -833,7 +833,7 @@ class DB ...@@ -833,7 +833,7 @@ class DB
) VALUES ( ) VALUES (
:message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id, :message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
:forward_date, :reply_to_chat, :reply_to_message, :media_group_id, :text, :entities, :audio, :document, :forward_date, :reply_to_chat, :reply_to_message, :media_group_id, :text, :entities, :audio, :document,
:photo, :sticker, :video, :voice, :video_note, :caption, :contact, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
:location, :venue, :new_chat_members, :left_chat_member, :location, :venue, :new_chat_members, :left_chat_member,
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created, :new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
:supergroup_chat_created, :channel_chat_created, :supergroup_chat_created, :channel_chat_created,
...@@ -877,6 +877,7 @@ class DB ...@@ -877,6 +877,7 @@ class DB
$sth->bindValue(':entities', $t = self::entitiesArrayToJson($message->getEntities(), null)); $sth->bindValue(':entities', $t = self::entitiesArrayToJson($message->getEntities(), null));
$sth->bindValue(':audio', $message->getAudio()); $sth->bindValue(':audio', $message->getAudio());
$sth->bindValue(':document', $message->getDocument()); $sth->bindValue(':document', $message->getDocument());
$sth->bindValue(':game', $message->getGame());
$sth->bindValue(':photo', $t = self::entitiesArrayToJson($message->getPhoto(), null)); $sth->bindValue(':photo', $t = self::entitiesArrayToJson($message->getPhoto(), null));
$sth->bindValue(':sticker', $message->getSticker()); $sth->bindValue(':sticker', $message->getSticker());
$sth->bindValue(':video', $message->getVideo()); $sth->bindValue(':video', $message->getVideo());
......
...@@ -22,6 +22,7 @@ use Longman\TelegramBot\Request; ...@@ -22,6 +22,7 @@ use Longman\TelegramBot\Request;
* @method Message getMessage() Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old * @method Message getMessage() Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
* @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query * @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query
* @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field * @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
* @method string getGameShortName() Optional. Short name of a Game to be returned, serves as the unique identifier for the game
*/ */
class CallbackQuery extends Entity class CallbackQuery extends Entity
{ {
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\Games;
use Longman\TelegramBot\Entities\Entity;
/**
* Class Animation
*
* You can provide an animation for your game so that it looks stylish in chats (check out Lumberjack for an example). This object represents an animation file to be displayed in the message containing a game.
*
* @link https://core.telegram.org/bots/api#animation
*
* @method string getFileId() Unique file identifier
* @method PhotoSize getThumb() Optional. Animation thumbnail as defined by sender
* @method string getFileName() Optional. Original animation filename as defined by sender
* @method string getMimeType() Optional. MIME type of the file as defined by sender
* @method int getFileSize() Optional. File size
**/
class Animation extends Entity
{
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\Games;
use Longman\TelegramBot\Entities\Entity;
/**
* Class CallbackGame
*
* A placeholder, currently holds no information. Use BotFather to set up your game.
*
* @link https://core.telegram.org/bots/api#callbackgame
**/
class CallbackGame extends Entity
{
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\Games;
use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\MessageEntity;
/**
* Class Game
*
* This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers.
*
* @link https://core.telegram.org/bots/api#game
*
* @method string getTitle() Title of the game
* @method string getDescription() Description of the game
* @method string getText() Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
* @method Animation getAnimation() Optional. Animation that will be displayed in the game message in chats. Upload via BotFather
**/
class Game extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities()
{
return [
'photo' => PhotoSize::class,
'text_entities' => MessageEntity::class,
'animation' => Animation::class,
];
}
/**
* Photo that will be displayed in the game message in chats.
*
* This method overrides the default getPhoto method
* and returns a nice array of PhotoSize objects.
*
* @return null|PhotoSize[]
*/
public function getPhoto()
{
$pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo');
return empty($pretty_array) ? null : $pretty_array;
}
/**
* Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.
*
* This method overrides the default getTextEntities method
* and returns a nice array of MessageEntity objects.
*
* @return null|MessageEntity[]
*/
public function getTextEntities()
{
$pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'text_entities');
return empty($pretty_array) ? null : $pretty_array;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\Games;
use Longman\TelegramBot\Entities\Entity;
/**
* Class GameHighScore
*
* This object represents one row of the high scores table for a game.
*
* @link https://core.telegram.org/bots/api#gamehighscore
*
* @method int getPosition() Position in high score table for the game
* @method User getUser() User
* @method int getScore() Score
**/
class GameHighScore extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities()
{
return [
'user' => User::class,
];
}
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace Longman\TelegramBot\Entities; namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Entities\Games\CallbackGame;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
/** /**
...@@ -17,18 +18,20 @@ use Longman\TelegramBot\Exception\TelegramException; ...@@ -17,18 +18,20 @@ use Longman\TelegramBot\Exception\TelegramException;
* *
* @link https://core.telegram.org/bots/api#inlinekeyboardbutton * @link https://core.telegram.org/bots/api#inlinekeyboardbutton
* *
* @method string getText() Label text on the button * @method string getText() Label text on the button
* @method string getUrl() Optional. HTTP url to be opened when button is pressed * @method string getUrl() Optional. HTTP url to be opened when button is pressed
* @method string getCallbackData() Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes * @method string getCallbackData() Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
* @method string getSwitchInlineQuery() Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. * @method string getSwitchInlineQuery() Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
* @method string getSwitchInlineQueryCurrentChat() Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. * @method string getSwitchInlineQueryCurrentChat() Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
* @method bool getPay() Optional. Specify True, to send a Pay button. * @method CallbackGame getCallbackGame() Optional. Description of the game that will be launched when the user presses the button.
* @method bool getPay() Optional. Specify True, to send a Pay button.
* *
* @method $this setText(string $text) Label text on the button * @method $this setText(string $text) Label text on the button
* @method $this setUrl(string $url) Optional. HTTP url to be opened when button is pressed * @method $this setUrl(string $url) Optional. HTTP url to be opened when button is pressed
* @method $this setCallbackData(string $callback_data) Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes * @method $this setCallbackData(string $callback_data) Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
* @method $this setSwitchInlineQuery(string $switch_inline_query) Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. * @method $this setSwitchInlineQuery(string $switch_inline_query) Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
* @method $this setSwitchInlineQueryCurrentChat(string $switch_inline_query_current_chat) Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. * @method $this setSwitchInlineQueryCurrentChat(string $switch_inline_query_current_chat) Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
* @method $this setCallbackGame(CallbackGame $callback_game) Optional. Description of the game that will be launched when the user presses the button.
* @method $this setPay(bool $pay) Optional. Specify True, to send a Pay button. * @method $this setPay(bool $pay) Optional. Specify True, to send a Pay button.
*/ */
class InlineKeyboardButton extends KeyboardButton class InlineKeyboardButton extends KeyboardButton
...@@ -48,6 +51,7 @@ class InlineKeyboardButton extends KeyboardButton ...@@ -48,6 +51,7 @@ class InlineKeyboardButton extends KeyboardButton
array_key_exists('callback_data', $data) || array_key_exists('callback_data', $data) ||
array_key_exists('switch_inline_query', $data) || array_key_exists('switch_inline_query', $data) ||
array_key_exists('switch_inline_query_current_chat', $data) || array_key_exists('switch_inline_query_current_chat', $data) ||
array_key_exists('callback_game', $data) ||
array_key_exists('pay', $data) array_key_exists('pay', $data)
); );
} }
...@@ -63,7 +67,7 @@ class InlineKeyboardButton extends KeyboardButton ...@@ -63,7 +67,7 @@ class InlineKeyboardButton extends KeyboardButton
$num_params = 0; $num_params = 0;
foreach (['url', 'callback_data', 'pay'] as $param) { foreach (['url', 'callback_data', 'callback_game', 'pay'] as $param) {
if ($this->getProperty($param, '') !== '') { if ($this->getProperty($param, '') !== '') {
$num_params++; $num_params++;
} }
...@@ -76,7 +80,7 @@ class InlineKeyboardButton extends KeyboardButton ...@@ -76,7 +80,7 @@ class InlineKeyboardButton extends KeyboardButton
} }
if ($num_params !== 1) { if ($num_params !== 1) {
throw new TelegramException('You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, pay!'); throw new TelegramException('You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!');
} }
} }
...@@ -86,8 +90,8 @@ class InlineKeyboardButton extends KeyboardButton ...@@ -86,8 +90,8 @@ class InlineKeyboardButton extends KeyboardButton
public function __call($method, $args) public function __call($method, $args)
{ {
// Only 1 of these can be set, so clear the others when setting a new one. // Only 1 of these can be set, so clear the others when setting a new one.
if (in_array($method, ['setUrl', 'setCallbackData', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setPay'], true)) { if (in_array($method, ['setUrl', 'setCallbackData', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setCallbackGame', 'setPay'], true)) {
unset($this->url, $this->callback_data, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->pay); unset($this->url, $this->callback_data, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->callback_game, $this->pay);
} }
return parent::__call($method, $args); return parent::__call($method, $args);
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\InlineKeyboard;
/**
* Class InlineQueryResultGame
*
* @link https://core.telegram.org/bots/api#inlinequeryresultgame
*
* <code>
* $data = [
* 'id' => '',
* 'game_short_name' => '',
* 'reply_markup' => <InlineKeyboard>,
* ];
* </code>
*
* @method string getType() Type of the result, must be game
* @method string getId() Unique identifier for this result, 1-64 bytes
* @method string getGameShortName() Short name of the game
* @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message
*
* @method $this setId(string $id) Unique identifier for this result, 1-64 bytes
* @method $this setGameShortName(string $game_short_name) Short name of the game
* @method $this setReplyMarkup(InlineKeyboard $reply_markup) Optional. Inline keyboard attached to the message
*/
class InlineQueryResultGame extends InlineEntity implements InlineQueryResult
{
/**
* InlineQueryResultGame constructor
*
* @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data = [])
{
$data['type'] = 'game';
parent::__construct($data);
}
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace Longman\TelegramBot\Entities; namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Entities\Games\Game;
use Longman\TelegramBot\Entities\Payments\Invoice; use Longman\TelegramBot\Entities\Payments\Invoice;
use Longman\TelegramBot\Entities\Payments\SuccessfulPayment; use Longman\TelegramBot\Entities\Payments\SuccessfulPayment;
...@@ -33,6 +34,7 @@ use Longman\TelegramBot\Entities\Payments\SuccessfulPayment; ...@@ -33,6 +34,7 @@ use Longman\TelegramBot\Entities\Payments\SuccessfulPayment;
* @method string getAuthorSignature() Optional. Signature of the post author for messages in channels * @method string getAuthorSignature() Optional. Signature of the post author for messages in channels
* @method Audio getAudio() Optional. Message is an audio file, information about the file * @method Audio getAudio() Optional. Message is an audio file, information about the file
* @method Document getDocument() Optional. Message is a general file, information about the file * @method Document getDocument() Optional. Message is a general file, information about the file
* @method Game getGame() Optional. Message is a game, information about the game.
* @method Sticker getSticker() Optional. Message is a sticker, information about the sticker * @method Sticker getSticker() Optional. Message is a sticker, information about the sticker
* @method Video getVideo() Optional. Message is a video, information about the video * @method Video getVideo() Optional. Message is a video, information about the video
* @method Voice getVoice() Optional. Message is a voice message, information about the file * @method Voice getVoice() Optional. Message is a voice message, information about the file
...@@ -71,6 +73,7 @@ class Message extends Entity ...@@ -71,6 +73,7 @@ class Message extends Entity
'caption_entities' => MessageEntity::class, 'caption_entities' => MessageEntity::class,
'audio' => Audio::class, 'audio' => Audio::class,
'document' => Document::class, 'document' => Document::class,
'game' => Game::class,
'photo' => PhotoSize::class, 'photo' => PhotoSize::class,
'sticker' => Sticker::class, 'sticker' => Sticker::class,
'video' => Video::class, 'video' => Video::class,
......
...@@ -75,6 +75,9 @@ use Longman\TelegramBot\Exception\TelegramException; ...@@ -75,6 +75,9 @@ use Longman\TelegramBot\Exception\TelegramException;
* @method static ServerResponse sendInvoice(array $data) Use this method to send invoices. On success, the sent Message is returned. * @method static ServerResponse sendInvoice(array $data) Use this method to send invoices. On success, the sent Message is returned.
* @method static ServerResponse answerShippingQuery(array $data) If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned. * @method static ServerResponse answerShippingQuery(array $data) If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
* @method static ServerResponse answerPreCheckoutQuery(array $data) Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. * @method static ServerResponse answerPreCheckoutQuery(array $data) Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned.
* @method static ServerResponse sendGame(array $data) Use this method to send a game. On success, the sent Message is returned.
* @method static ServerResponse setGameScore(array $data) Use this method to set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
* @method static ServerResponse getGameHighScores(array $data) 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.
*/ */
class Request class Request
{ {
...@@ -186,6 +189,9 @@ class Request ...@@ -186,6 +189,9 @@ class Request
'sendInvoice', 'sendInvoice',
'answerShippingQuery', 'answerShippingQuery',
'answerPreCheckoutQuery', 'answerPreCheckoutQuery',
'sendGame',
'setGameScore',
'getGameHighScores',
]; ];
/** /**
...@@ -671,6 +677,8 @@ class Request ...@@ -671,6 +677,8 @@ class Request
'sendVenue', 'sendVenue',
'sendContact', 'sendContact',
'sendInvoice', 'sendInvoice',
'sendGame',
'setGameScore',
'editMessageText', 'editMessageText',
'editMessageCaption', 'editMessageCaption',
'editMessageReplyMarkup', 'editMessageReplyMarkup',
......
...@@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS `message` (
`entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text', `entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',
`audio` TEXT COMMENT 'Audio object. Message is an audio file, information about the file', `audio` TEXT COMMENT 'Audio object. Message is an audio file, information about the file',
`document` TEXT COMMENT 'Document object. Message is a general file, information about the file', `document` TEXT COMMENT 'Document object. Message is a general file, information about the file',
`game` TEXT COMMENT 'Game object. Message is a game, information about the game',
`photo` TEXT COMMENT 'Array of PhotoSize objects. Message is a photo, available sizes of the photo', `photo` TEXT COMMENT 'Array of PhotoSize objects. Message is a photo, available sizes of the photo',
`sticker` TEXT COMMENT 'Sticker object. Message is a sticker, information about the sticker', `sticker` TEXT COMMENT 'Sticker object. Message is a sticker, information about the sticker',
`video` TEXT COMMENT 'Video object. Message is a video, information about the video', `video` TEXT COMMENT 'Video object. Message is a video, information about the video',
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace Longman\TelegramBot\Tests\Unit; namespace Longman\TelegramBot\Tests\Unit;
use Longman\TelegramBot\Entities\Games\CallbackGame;
use Longman\TelegramBot\Entities\InlineKeyboardButton; use Longman\TelegramBot\Entities\InlineKeyboardButton;
/** /**
...@@ -32,7 +33,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -32,7 +33,7 @@ class InlineKeyboardButtonTest extends TestCase
/** /**
* @expectedException \Longman\TelegramBot\Exception\TelegramException * @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, pay! * @expectedExceptionMessage You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!
*/ */
public function testInlineKeyboardButtonNoParameterFail() public function testInlineKeyboardButtonNoParameterFail()
{ {
...@@ -41,7 +42,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -41,7 +42,7 @@ class InlineKeyboardButtonTest extends TestCase
/** /**
* @expectedException \Longman\TelegramBot\Exception\TelegramException * @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, pay! * @expectedExceptionMessage You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!
*/ */
public function testInlineKeyboardButtonTooManyParametersFail() public function testInlineKeyboardButtonTooManyParametersFail()
{ {
...@@ -74,6 +75,13 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -74,6 +75,13 @@ class InlineKeyboardButtonTest extends TestCase
'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value', 'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value',
]); ]);
}, },
function () {
new InlineKeyboardButton([
'text' => 'message',
'callback_data' => 'callback_data_value',
'callback_game' => new CallbackGame([]),
]);
},
function () { function () {
new InlineKeyboardButton([ new InlineKeyboardButton([
'text' => 'message', 'text' => 'message',
...@@ -94,6 +102,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -94,6 +102,7 @@ class InlineKeyboardButtonTest extends TestCase
new InlineKeyboardButton(['text' => 'message', 'switch_inline_query' => '']); // Allow empty string. new InlineKeyboardButton(['text' => 'message', 'switch_inline_query' => '']); // Allow empty string.
new InlineKeyboardButton(['text' => 'message', 'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value']); new InlineKeyboardButton(['text' => 'message', 'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value']);
new InlineKeyboardButton(['text' => 'message', 'switch_inline_query_current_chat' => '']); // Allow empty string. new InlineKeyboardButton(['text' => 'message', 'switch_inline_query_current_chat' => '']); // Allow empty string.
new InlineKeyboardButton(['text' => 'message', 'callback_game' => new CallbackGame([])]);
new InlineKeyboardButton(['text' => 'message', 'pay' => true]); new InlineKeyboardButton(['text' => 'message', 'pay' => true]);
} }
...@@ -111,6 +120,9 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -111,6 +120,9 @@ class InlineKeyboardButtonTest extends TestCase
self::assertTrue(InlineKeyboardButton::couldBe( self::assertTrue(InlineKeyboardButton::couldBe(
['text' => 'message', 'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value'] ['text' => 'message', 'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value']
)); ));
self::assertTrue(InlineKeyboardButton::couldBe(
['text' => 'message', 'callback_game' => new CallbackGame([])]
));
self::assertTrue(InlineKeyboardButton::couldBe( self::assertTrue(InlineKeyboardButton::couldBe(
['text' => 'message', 'pay' => true] ['text' => 'message', 'pay' => true]
)); ));
...@@ -124,6 +136,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -124,6 +136,7 @@ class InlineKeyboardButtonTest extends TestCase
self::assertFalse(InlineKeyboardButton::couldBe( self::assertFalse(InlineKeyboardButton::couldBe(
['switch_inline_query' => 'switch_inline_query_value'] ['switch_inline_query' => 'switch_inline_query_value']
)); ));
self::assertFalse(InlineKeyboardButton::couldBe(['callback_game' => new CallbackGame([])]));
self::assertFalse(InlineKeyboardButton::couldBe(['pay' => true])); self::assertFalse(InlineKeyboardButton::couldBe(['pay' => true]));
self::assertFalse(InlineKeyboardButton::couldBe([ self::assertFalse(InlineKeyboardButton::couldBe([
...@@ -131,6 +144,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -131,6 +144,7 @@ class InlineKeyboardButtonTest extends TestCase
'callback_data' => 'callback_data_value', 'callback_data' => 'callback_data_value',
'switch_inline_query' => 'switch_inline_query_value', 'switch_inline_query' => 'switch_inline_query_value',
'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value', 'switch_inline_query_current_chat' => 'switch_inline_query_current_chat_value',
'callback_game' => new CallbackGame([]),
'pay' => true, 'pay' => true,
])); ]));
} }
...@@ -142,6 +156,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -142,6 +156,7 @@ class InlineKeyboardButtonTest extends TestCase
self::assertEmpty($button->getCallbackData()); self::assertEmpty($button->getCallbackData());
self::assertEmpty($button->getSwitchInlineQuery()); self::assertEmpty($button->getSwitchInlineQuery());
self::assertEmpty($button->getSwitchInlineQueryCurrentChat()); self::assertEmpty($button->getSwitchInlineQueryCurrentChat());
self::assertEmpty($button->getCallbackGame());
self::assertEmpty($button->getPay()); self::assertEmpty($button->getPay());
$button->setCallbackData('callback_data_value'); $button->setCallbackData('callback_data_value');
...@@ -149,6 +164,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -149,6 +164,7 @@ class InlineKeyboardButtonTest extends TestCase
self::assertSame('callback_data_value', $button->getCallbackData()); self::assertSame('callback_data_value', $button->getCallbackData());
self::assertEmpty($button->getSwitchInlineQuery()); self::assertEmpty($button->getSwitchInlineQuery());
self::assertEmpty($button->getSwitchInlineQueryCurrentChat()); self::assertEmpty($button->getSwitchInlineQueryCurrentChat());
self::assertEmpty($button->getCallbackGame());
self::assertEmpty($button->getPay()); self::assertEmpty($button->getPay());
$button->setSwitchInlineQuery('switch_inline_query_value'); $button->setSwitchInlineQuery('switch_inline_query_value');
...@@ -156,6 +172,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -156,6 +172,7 @@ class InlineKeyboardButtonTest extends TestCase
self::assertEmpty($button->getCallbackData()); self::assertEmpty($button->getCallbackData());
self::assertSame('switch_inline_query_value', $button->getSwitchInlineQuery()); self::assertSame('switch_inline_query_value', $button->getSwitchInlineQuery());
self::assertEmpty($button->getSwitchInlineQueryCurrentChat()); self::assertEmpty($button->getSwitchInlineQueryCurrentChat());
self::assertEmpty($button->getCallbackGame());
self::assertEmpty($button->getPay()); self::assertEmpty($button->getPay());
$button->setSwitchInlineQueryCurrentChat('switch_inline_query_current_chat_value'); $button->setSwitchInlineQueryCurrentChat('switch_inline_query_current_chat_value');
...@@ -163,6 +180,15 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -163,6 +180,15 @@ class InlineKeyboardButtonTest extends TestCase
self::assertEmpty($button->getCallbackData()); self::assertEmpty($button->getCallbackData());
self::assertEmpty($button->getSwitchInlineQuery()); self::assertEmpty($button->getSwitchInlineQuery());
self::assertSame('switch_inline_query_current_chat_value', $button->getSwitchInlineQueryCurrentChat()); self::assertSame('switch_inline_query_current_chat_value', $button->getSwitchInlineQueryCurrentChat());
self::assertEmpty($button->getCallbackGame());
self::assertEmpty($button->getPay());
$button->setCallbackGame($callback_game = new CallbackGame([]));
self::assertEmpty($button->getUrl());
self::assertEmpty($button->getCallbackData());
self::assertEmpty($button->getSwitchInlineQuery());
self::assertEmpty($button->getSwitchInlineQueryCurrentChat());
self::assertSame($callback_game, $button->getCallbackGame());
self::assertEmpty($button->getPay()); self::assertEmpty($button->getPay());
$button->setPay(true); $button->setPay(true);
...@@ -170,6 +196,7 @@ class InlineKeyboardButtonTest extends TestCase ...@@ -170,6 +196,7 @@ class InlineKeyboardButtonTest extends TestCase
self::assertEmpty($button->getCallbackData()); self::assertEmpty($button->getCallbackData());
self::assertEmpty($button->getSwitchInlineQuery()); self::assertEmpty($button->getSwitchInlineQuery());
self::assertEmpty($button->getSwitchInlineQueryCurrentChat()); self::assertEmpty($button->getSwitchInlineQueryCurrentChat());
self::assertSame(true, $button->getPay()); self::assertEmpty($button->getCallbackGame());
self::assertTrue($button->getPay());
} }
} }
ALTER TABLE `message` ADD COLUMN `game` TEXT COMMENT 'Game object. Message is a game, information about the game' AFTER `document`;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment