summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJellyBrick <shlee1503@naver.com>2018-05-29 21:55:25 +0900
committerJellyBrick <shlee1503@naver.com>2018-05-29 21:55:25 +0900
commitad8ca77ece2b3185ca546f120dc4f7a13e602aa2 (patch)
tree5e10d871a3223690a23874d29826939dceaff4e5 /include
parent1107db6e8890774fc55fa43160b0afa442443056 (diff)
Bot API 2.2 (Game) update
Diffstat (limited to 'include')
-rw-r--r--include/tgbot/Api.h44
-rw-r--r--include/tgbot/TgTypeParser.h12
-rw-r--r--include/tgbot/types/Animation.h72
-rw-r--r--include/tgbot/types/CallbackGame.h42
-rw-r--r--include/tgbot/types/Game.h82
-rw-r--r--include/tgbot/types/GameHighScore.h61
-rw-r--r--include/tgbot/types/InlineKeyboardButton.h11
-rw-r--r--include/tgbot/types/Message.h6
8 files changed, 329 insertions, 1 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index f3b4957..cb07aac 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -42,6 +42,7 @@
#include "tgbot/types/StickerSet.h"
#include "tgbot/types/File.h"
#include "tgbot/types/InputMedia.h"
+#include "tgbot/types/GameHighScore.h"
namespace TgBot {
@@ -397,6 +398,18 @@ public:
const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const;
/**
+ * @brief Use this method to send a game.
+ * @param chatId Unique identifier for the target chat.
+ * @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
+ * @param replyToMessageId Optional. If the message is a reply, ID of the original message.
+ * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game.
+ * @param disableNotification Optional. Sends the message silenty.
+ * @return On success, the sent message is returned.
+ */
+ Message::Ptr sendGame(int64_t chatId, const std::string& gameShortName, int32_t replyToMessageId = 0,
+ const InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>(), bool disableNotification = false) const;
+
+ /**
* @brief Use this method to send point on the map.
* @param chatId Unique identifier for the target chat.
* @param latitude Latitude of location.
@@ -770,6 +783,37 @@ public:
*/
bool unpinChatMessage(int64_t chatId) const;
+ /**
+ * @brief Use this method to set the score of the specified user in a game.
+ *
+ * Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
+ *
+ * @param userId User identifier.
+ * @param score New score, must be non-negative.
+ * @param force Optional. Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters.
+ * @param disableEditMessage Optional. Pass True, if the game message should not be automatically edited to include the current scoreboard.
+ * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat
+ * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message
+ * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message
+ * @return On success, if the message was sent by the bot, returns the edited Message, otherwise returns nullptr.
+ */
+ Message::Ptr setGameScore(int32_t userId, int32_t score, bool force = false, bool disableEditMessage = false,
+ int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "") const;
+
+ /**
+ * @brief 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.
+ *
+ * @param userId User identifier.
+ * @param chatId Optional. Required if inlineMessageId is not specified. Unique identifier for the target chat
+ * @param messageId Optional. Required if inlineMessageId is not specified. Identifier of the sent message
+ * @param inlineMessageId Optional. Required if chatId and messageId are not specified. Identifier of the inline message
+ * @return On success, returns an Array of GameHighScore objects.
+ */
+ std::vector<GameHighScore::Ptr> getGameHighScores(int32_t userId, int32_t score, bool force = false,
+ bool disableEditMessage = false, int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "") const;
+
/**
* @brief Downloads file from Telegram and saves it in memory.
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index b5e51ed..aea4f8b 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -75,6 +75,10 @@
#include "tgbot/types/InlineQueryResultVideo.h"
#include "tgbot/types/InlineQueryResultVoice.h"
#include "tgbot/types/ChosenInlineResult.h"
+#include "tgbot/types/CallbackGame.h"
+#include "tgbot/types/Animation.h"
+#include "tgbot/types/Game.h"
+#include "tgbot/types/GameHighScore.h"
#include "tgbot/types/CallbackQuery.h"
#include "tgbot/types/InlineKeyboardMarkup.h"
#include "tgbot/types/InlineKeyboardButton.h"
@@ -113,7 +117,7 @@ public:
std::string parseChat(const Chat::Ptr& object) const;
User::Ptr parseJsonAndGetUser(const boost::property_tree::ptree& data) const;
std::string parseUser(const User::Ptr& object) const;
- MessageEntity::Ptr parseJsonAndGetEntity(const boost::property_tree::ptree& data) const;
+ MessageEntity::Ptr parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const;
Message::Ptr parseJsonAndGetMessage(const boost::property_tree::ptree& data) const;
std::string parseMessage(const Message::Ptr& object) const;
PhotoSize::Ptr parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const;
@@ -132,6 +136,12 @@ public:
std::string parseVideo(const Video::Ptr& object) const;
VideoNote::Ptr parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const;
std::string parseVideoNote(const VideoNote::Ptr& object) const;
+ Game::Ptr parseJsonAndGetGame(const boost::property_tree::ptree& data) const;
+ std::string parseGame(const Game::Ptr& object) const;
+ GameHighScore::Ptr parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const;
+ std::string parseGameHighScore(const GameHighScore::Ptr& object) const;
+ Animation::Ptr parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const;
+ std::string parseAnimation(const Animation::Ptr& object) const;
Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const;
std::string parseContact(const Contact::Ptr& object) const;
Location::Ptr parseJsonAndGetLocation(const boost::property_tree::ptree& data) const;
diff --git a/include/tgbot/types/Animation.h b/include/tgbot/types/Animation.h
new file mode 100644
index 0000000..ab8dd54
--- /dev/null
+++ b/include/tgbot/types/Animation.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * Copyright (c) 2018 JellyBrick
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_ANIMATION_H
+#define TGBOT_ANIMATION_H
+
+#include <memory>
+#include <string>
+
+#include "tgbot/types/PhotoSize.h"
+
+namespace TgBot {
+
+/**
+ * @brief 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.
+ *
+ * @ingroup types
+ */
+class Animation {
+public:
+ typedef std::shared_ptr<Animation> Ptr;
+
+ /**
+ * @brief Unique file identifier.
+ */
+ std::string fileId;
+
+ /**
+ * @brief Optional. Animation thumbnail as defined by sender.
+ */
+ PhotoSize::Ptr thumb;
+
+ /**
+ * @brief Optional. Original animation filename as defined by sender.
+ */
+ std::string fileName;
+
+ /**
+ * @brief Optional. MIME type of the file as defined by sender.
+ */
+ std::string mimeType;
+
+ /**
+ * @brief Optional. File size.
+ */
+ int32_t fileSize;
+};
+}
+
+#endif //TGBOT_ANIMATION_H \ No newline at end of file
diff --git a/include/tgbot/types/CallbackGame.h b/include/tgbot/types/CallbackGame.h
new file mode 100644
index 0000000..9aabc0a
--- /dev/null
+++ b/include/tgbot/types/CallbackGame.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * Copyright (c) 2018 JellyBrick
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_CALLBACKGAME_H
+#define TGBOT_CALLBACKGAME_H
+
+#include <memory>
+
+namespace TgBot {
+
+/**
+ * @brief A placeholder, currently holds no information. Use BotFather to set up your game.
+ *
+ * @ingroup types
+ */
+class CallbackGame {
+public:
+ typedef std::shared_ptr<CallbackGame> Ptr;
+};
+}
+
+#endif //TGBOT_CALLBACKGAME_H \ No newline at end of file
diff --git a/include/tgbot/types/Game.h b/include/tgbot/types/Game.h
new file mode 100644
index 0000000..b3723b7
--- /dev/null
+++ b/include/tgbot/types/Game.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * Copyright (c) 2018 JellyBrick
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_GAME_H
+#define TGBOT_GAME_H
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "tgbot/types/MessageEntity.h"
+#include "tgbot/types/Animation.h"
+#include "tgbot/types/PhotoSize.h"
+
+namespace TgBot {
+
+/**
+ * @brief This object represents a game.
+ *
+ * Use BotFather to create and edit games, their short names will act as unique identifiers.
+ *
+ * @ingroup types
+ */
+class Game {
+public:
+ typedef std::shared_ptr<Game> Ptr;
+
+ /**
+ * @brief Title of the game.
+ */
+ std::string title;
+
+ /**
+ * @brief Description of the game.
+ */
+ std::string description;
+
+ /**
+ * @brief Photo that will be displayed in the game message in chats.
+ */
+ std::vector<PhotoSize::Ptr> photo;
+
+ /**
+ * @brief 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.
+ */
+ std::string text;
+
+ /**
+ * @brief Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.
+ */
+ std::vector<MessageEntity::Ptr> textEntities;
+
+ /**
+ * @brief Optional. Animation that will be displayed in the game message in chats. Upload via BotFather.
+ */
+ Animation::Ptr animation;
+};
+}
+
+#endif //TGBOT_GAME_H \ No newline at end of file
diff --git a/include/tgbot/types/GameHighScore.h b/include/tgbot/types/GameHighScore.h
new file mode 100644
index 0000000..f78fbf0
--- /dev/null
+++ b/include/tgbot/types/GameHighScore.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015 Oleg Morozenkov
+ * Copyright (c) 2018 JellyBrick
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_GAMEHIGHSCORE_H
+#define TGBOT_GAMEHIGHSCORE_H
+
+#include <memory>
+#include <string>
+
+#include "tgbot/types/PhotoSize.h"
+#include "tgbot/types/User.h"
+
+namespace TgBot {
+
+/**
+ * @brief This object represents one row of the high scores table for a game.
+ *
+ * @ingroup types
+ */
+class GameHighScore {
+public:
+ typedef std::shared_ptr<GameHighScore> Ptr;
+
+ /**
+ * @brief Position in high score table for the game.
+ */
+ std::string position;
+
+ /**
+ * @brief User.
+ */
+ User::Ptr user;
+
+ /**
+ * @brief Score.
+ */
+ int32_t score;
+};
+}
+
+#endif //TGBOT_GAMEHIGHSCORE_H \ No newline at end of file
diff --git a/include/tgbot/types/InlineKeyboardButton.h b/include/tgbot/types/InlineKeyboardButton.h
index c3da2c8..51ec58f 100644
--- a/include/tgbot/types/InlineKeyboardButton.h
+++ b/include/tgbot/types/InlineKeyboardButton.h
@@ -8,6 +8,8 @@
#include <string>
#include <memory>
+#include "tgbot/types/CallbackGame.h"
+
namespace TgBot {
/**
@@ -36,6 +38,8 @@ public:
/**
* @brief 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.
+ *
+ * Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm… actions – in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.
*/
std::string switchInlineQuery;
@@ -43,6 +47,13 @@ public:
* @brief 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.
*/
std::string switchInlineQueryCurrentChat;
+
+ /**
+ * @brief Optional. Description of the game that will be launched when the user presses the button.
+ *
+ * NOTE: This type of button must always be the first button in the first row.
+ */
+ CallbackGame::Ptr callbackGame;
};
}
diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h
index 6b7484f..4f982fa 100644
--- a/include/tgbot/types/Message.h
+++ b/include/tgbot/types/Message.h
@@ -36,6 +36,7 @@
#include "tgbot/types/Video.h"
#include "tgbot/types/Contact.h"
#include "tgbot/types/Location.h"
+#include "tgbot/types/Game.h"
#include "tgbot/types/PhotoSize.h"
#include "tgbot/types/MessageEntity.h"
#include "tgbot/types/Venue.h"
@@ -147,6 +148,11 @@ public:
Document::Ptr document;
/**
+ * @brief Optional. Message is a game, information about the game.
+ */
+ Game::Ptr game;
+
+ /**
* @brief Optional. Message is a photo, available sizes of the photo.
*/
std::vector<PhotoSize::Ptr> photo;