diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | include/tgbot/Api.h | 2 | ||||
-rw-r--r-- | include/tgbot/EventHandler.h | 6 | ||||
-rw-r--r-- | include/tgbot/net/HttpReqArg.h | 17 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultArticle.h | 6 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultGif.h | 6 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultMpeg4Gif.h | 6 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultPhoto.h | 6 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultVideo.h | 6 | ||||
-rw-r--r-- | src/Api.cpp | 7 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 2 | ||||
-rw-r--r-- | test/InlineQueryResult.cpp | 16 |
12 files changed, 47 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a31acc0..167c1c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(SRC_LIST src/net/HttpParser.cpp src/net/TgLongPoll.cpp src/tools/StringTools.cpp -) + test/InlineQueryResult.cpp) ### libs # threads diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 96dc683..22dbe30 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -242,7 +242,7 @@ public: * @param isPersonal Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query. * @param nextOffset Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes. */ - void answerInlineQuery(const std::string inlineQueryId, const std::vector<InlineQueryResult::Ptr> results, + void answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results, int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset=""); private: diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index aee230a..64f74cd 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -31,8 +31,8 @@ namespace TgBot { class EventHandler { - inline void handleMessage(const Message::Ptr& message){ - _broadcaster->broadcastAnyMessage(update->message); + void handleMessage(const Message::Ptr& message) const { + _broadcaster->broadcastAnyMessage(message); if (StringTools::startsWith(message->text, "/")) { unsigned long splitPosition; @@ -68,7 +68,7 @@ public: if (update->chosenInlineResult != NULL) _broadcaster->broadcastChosenInlineResult(update->chosenInlineResult); if (update->message != NULL) - handleMessag(update->message); + handleMessage(update->message); } private: diff --git a/include/tgbot/net/HttpReqArg.h b/include/tgbot/net/HttpReqArg.h index 5056e6c..5aa60fd 100644 --- a/include/tgbot/net/HttpReqArg.h +++ b/include/tgbot/net/HttpReqArg.h @@ -25,6 +25,7 @@ #include <string> #include <vector> +#include <functional> #include <boost/lexical_cast.hpp> @@ -43,22 +44,6 @@ public: { } - template<typename T> - HttpReqArg(const std::string& name, const std::vector<T>& list, function<std::string (const T&)> parsingFunction){ - this->name = name; - value = "["; - for (const T& item : list){ - value += parsingFunction(item); - value += ','; - } - value.erase(this->value.length() - 1); - value += ']'; - - isFile = false; - mimeType = "text/plain"; - fileName = ""; - } - /** * Name of an argument. */ diff --git a/include/tgbot/types/InlineQueryResultArticle.h b/include/tgbot/types/InlineQueryResultArticle.h index 9d0b043..484ee30 100644 --- a/include/tgbot/types/InlineQueryResultArticle.h +++ b/include/tgbot/types/InlineQueryResultArticle.h @@ -18,11 +18,13 @@ namespace TgBot { */ class InlineQueryResultArticle : public InlineQueryResult { public: - static const std::string TYPE = "article"; + static const std::string TYPE; typedef std::shared_ptr<InlineQueryResultArticle> Ptr; - InlineQueryResultArticle() : type(TYPE) {}; + InlineQueryResultArticle() { + this->type = TYPE; + } /** * Optional. URL of the result. diff --git a/include/tgbot/types/InlineQueryResultGif.h b/include/tgbot/types/InlineQueryResultGif.h index 06e63ae..ef82f29 100644 --- a/include/tgbot/types/InlineQueryResultGif.h +++ b/include/tgbot/types/InlineQueryResultGif.h @@ -18,11 +18,13 @@ namespace TgBot { */ class InlineQueryResultGif : public InlineQueryResult { public: - static const std::string TYPE = "gif"; + static const std::string TYPE; typedef std::shared_ptr<InlineQueryResultGif> Ptr; - InlineQueryResultGif() : type(TYPE) {}; + InlineQueryResultGif() { + this->type = TYPE; + } /** * A valid URL for the GIF file. diff --git a/include/tgbot/types/InlineQueryResultMpeg4Gif.h b/include/tgbot/types/InlineQueryResultMpeg4Gif.h index 170b0fa..9807e51 100644 --- a/include/tgbot/types/InlineQueryResultMpeg4Gif.h +++ b/include/tgbot/types/InlineQueryResultMpeg4Gif.h @@ -13,11 +13,13 @@ namespace TgBot { */ class InlineQueryResultMpeg4Gif : public InlineQueryResult { public: - static const std::string TYPE = "mpeg4_gif"; + static const std::string TYPE; typedef std::shared_ptr<InlineQueryResultMpeg4Gif> Ptr; - InlineQueryResultMpeg4Gif() : type(TYPE) {}; + InlineQueryResultMpeg4Gif() { + this->type = TYPE; + } /** * A valid URL for the MP4 file. diff --git a/include/tgbot/types/InlineQueryResultPhoto.h b/include/tgbot/types/InlineQueryResultPhoto.h index 07e1f35..63491f8 100644 --- a/include/tgbot/types/InlineQueryResultPhoto.h +++ b/include/tgbot/types/InlineQueryResultPhoto.h @@ -18,11 +18,13 @@ namespace TgBot { */ class InlineQueryResultPhoto : public InlineQueryResult { public: - static const std::string TYPE = "photo"; + static const std::string TYPE; typedef std::shared_ptr<InlineQueryResultPhoto> Ptr; - InlineQueryResultPhoto() : type(TYPE) {}; + InlineQueryResultPhoto() { + this->type = TYPE; + } /** * A valid URL of the photo. diff --git a/include/tgbot/types/InlineQueryResultVideo.h b/include/tgbot/types/InlineQueryResultVideo.h index f3e5029..0062d36 100644 --- a/include/tgbot/types/InlineQueryResultVideo.h +++ b/include/tgbot/types/InlineQueryResultVideo.h @@ -13,11 +13,13 @@ namespace TgBot { */ class InlineQueryResultVideo : public InlineQueryResult { public: - static const std::string TYPE = "video"; + static const std::string TYPE; typedef std::shared_ptr<InlineQueryResultVideo> Ptr; - InlineQueryResultVideo() : type(TYPE) {}; + InlineQueryResultVideo() { + this->type = TYPE; + }; /** * A valid URL for the embedded video player or video file. diff --git a/src/Api.cpp b/src/Api.cpp index 47c7882..325978f 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -255,11 +255,12 @@ void Api::setWebhook(const string& url) const { sendRequest("setWebhook", args); } -void Api::answerInlineQuery(const std::string inlineQueryId, const std::vector<InlineQueryResult::Ptr> results, - int32_t cacheTime=300, bool isPersonal=false, const std::string& nextOffset=""){ +void Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results, + int32_t cacheTime, bool isPersonal, const std::string& nextOffset){ vector<HttpReqArg> args; args.push_back(HttpReqArg("inline_query_id", inlineQueryId)); - args.push_back(HttpReqArg("results", results, TgTypeParser::getInstance().parseInlineQueryResult)); + string resultsJson = TgTypeParser::getInstance().parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results); + args.push_back(HttpReqArg("results", resultsJson)); args.push_back(HttpReqArg("cache_time", cacheTime)); args.push_back(HttpReqArg("is_personal", isPersonal)); args.push_back(HttpReqArg("next_offset", nextOffset)); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index eb7f769..079e073 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -362,7 +362,7 @@ string TgTypeParser::parseUpdate(const Update::Ptr& object) const { appendToJson(result, "update_id", object->updateId); appendToJson(result, "message", parseMessage(object->message)); appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery)); - appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult)) + appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult)); result.erase(result.length() - 1); result += '}'; return result; diff --git a/test/InlineQueryResult.cpp b/test/InlineQueryResult.cpp new file mode 100644 index 0000000..be1f14a --- /dev/null +++ b/test/InlineQueryResult.cpp @@ -0,0 +1,16 @@ +// +// Created by Andrea Giove on 27/03/16. +// +#include "tgbot/types/InlineQueryResultArticle.h" +#include "tgbot/types/InlineQueryResultGif.h" +#include "tgbot/types/InlineQueryResultMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultPhoto.h" +#include "tgbot/types/InlineQueryResultVideo.h" + +using namespace TgBot; + +const std::string InlineQueryResultArticle::TYPE = "article"; +const std::string InlineQueryResultGif::TYPE = "gif"; +const std::string InlineQueryResultMpeg4Gif::TYPE = "mpeg4_gif"; +const std::string InlineQueryResultPhoto::TYPE = "photo"; +const std::string InlineQueryResultVideo::TYPE = "video"; |