summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Morozenkov <m@oleg.rocks>2019-12-05 00:50:28 +0300
committerGitHub <noreply@github.com>2019-12-05 00:50:28 +0300
commitd873b1ec87c70449fffba336b2aeabb259885b21 (patch)
tree87ac36248432558291c1dece547b7f220ea8da96
parent9148563cb333bb6a3127138541de2fc086ff743b (diff)
parent2318c534d4286436a668c5a33220dfc8d5b85686 (diff)
Merge pull request #114 from YJBeetle/master
fix #113 InlineQueryResult json parse bug
-rw-r--r--include/tgbot/Api.h5
-rw-r--r--include/tgbot/TgTypeParser.h18
-rw-r--r--src/Api.cpp7
-rw-r--r--src/TgTypeParser.cpp3
-rw-r--r--src/types/InlineQueryResult.cpp16
5 files changed, 33 insertions, 16 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 84a6c9b..ec9edf8 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -251,13 +251,12 @@ public:
* @brief Use this method to add a new sticker to a set created by the bot.
* @param userId User identifier of created sticker set owner.
* @param name Sticker set name.
- * @param title Sticker set title, 1-64 characters.
* @param pngSticker Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
* @param emojis One or more emoji corresponding to the sticker.
* @param maskPosition Optional. A JSON-serialized object for position where the mask should be placed on faces.
* @return Returns True on success.
*/
- bool addStickerToSet(int32_t userId, const std::string& name, const std::string& title,
+ bool addStickerToSet(int32_t userId, const std::string& name,
boost::variant<InputFile::Ptr, std::string> pngSticker, const std::string& emojis, MaskPosition::Ptr maskPosition = nullptr) const;
/**
@@ -273,7 +272,7 @@ public:
* @param stickers File identifier of the sticker.
* @return Returns True on success.
*/
- bool deleteStickerPositionInSet(const std::string& sticker) const;
+ bool deleteStickerFromSet(const std::string& sticker) const;
/**
* @brief Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index dbfa27e..979ba55 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -468,6 +468,24 @@ private:
json += ',';
}
+ template<typename T>
+ inline void appendToJsonNumber(std::string& json, const std::string& varName, const T& value) const {
+ json += '"';
+ json += varName;
+ json += R"(":)";
+ json += std::to_string(value);
+ json += ',';
+ }
+ inline void appendToJson(std::string &json, const std::string &varName, const int &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const long &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const long long &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const unsigned &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const unsigned long &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const unsigned long long &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const float &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const double &value) const { appendToJsonNumber(json, varName, value); }
+ inline void appendToJson(std::string &json, const std::string &varName, const long double &value) const { appendToJsonNumber(json, varName, value); }
+
inline void appendToJson(std::string& json, const std::string& varName, const bool& value) const {
json += '"';
json += varName;
diff --git a/src/Api.cpp b/src/Api.cpp
index 6b41947..9996108 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -335,12 +335,11 @@ bool Api::createNewStickerSet(int32_t userId, const string& name, const string&
return sendRequest("createNewStickerSet", args).get<bool>("", false);
}
-bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
+bool Api::addStickerToSet(int32_t userId, const string& name, const boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
args.reserve(6);
args.emplace_back("user_id", userId);
args.emplace_back("name", name);
- args.emplace_back("title", title);
if (pngSticker.which() == 0 /* InputFile::Ptr */) {
auto file = boost::get<InputFile::Ptr>(pngSticker);
args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName);
@@ -362,11 +361,11 @@ bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) cons
return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
}
-bool Api::deleteStickerPositionInSet(const string& sticker) const {
+bool Api::deleteStickerFromSet(const string& sticker) const {
vector<HttpReqArg> args;
args.reserve(1);
args.emplace_back("sticker", sticker);
- return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
+ return sendRequest("deleteStickerFromSet", args).get<bool>("", false);
}
Message::Ptr Api::sendVideo(int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const boost::variant<InputFile::Ptr, std::string> thumb, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 4e31c94..daa7b4b 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -1723,12 +1723,13 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::
}
string result;
result += '{';
+ if(object->pay)
+ appendToJson(result, "pay", object->pay);
appendToJson(result, "text", object->text);
appendToJson(result, "url", object->url);
appendToJson(result, "callback_data", object->callbackData);
appendToJson(result, "switch_inline_query", object->switchInlineQuery);
appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat);
- appendToJson(result, "pay", object->pay);
removeLastComma(result);
result += '}';
return result;
diff --git a/src/types/InlineQueryResult.cpp b/src/types/InlineQueryResult.cpp
index 9f90e19..79debe0 100644
--- a/src/types/InlineQueryResult.cpp
+++ b/src/types/InlineQueryResult.cpp
@@ -25,14 +25,14 @@
using namespace TgBot;
-const std::string InlineQueryResultCachedAudio::TYPE = "cached_audio";
-const std::string InlineQueryResultCachedDocument::TYPE = "cached_document";
-const std::string InlineQueryResultCachedGif::TYPE = "cached_gif";
-const std::string InlineQueryResultCachedMpeg4Gif::TYPE = "cached_mpeg4gif";
-const std::string InlineQueryResultCachedPhoto::TYPE = "cached_photo";
-const std::string InlineQueryResultCachedSticker::TYPE = "cached_sticker";
-const std::string InlineQueryResultCachedVideo::TYPE = "cached_video";
-const std::string InlineQueryResultCachedVoice::TYPE = "cached_voice";
+const std::string InlineQueryResultCachedAudio::TYPE = "audio";
+const std::string InlineQueryResultCachedDocument::TYPE = "document";
+const std::string InlineQueryResultCachedGif::TYPE = "gif";
+const std::string InlineQueryResultCachedMpeg4Gif::TYPE = "mpeg4_gif";
+const std::string InlineQueryResultCachedPhoto::TYPE = "photo";
+const std::string InlineQueryResultCachedSticker::TYPE = "sticker";
+const std::string InlineQueryResultCachedVideo::TYPE = "video";
+const std::string InlineQueryResultCachedVoice::TYPE = "voice";
const std::string InlineQueryResultArticle::TYPE = "article";
const std::string InlineQueryResultAudio::TYPE = "audio";