diff options
-rw-r--r-- | include/tgbot/Api.h | 2 | ||||
-rw-r--r-- | include/tgbot/tools/FileTools.h | 7 | ||||
-rw-r--r-- | src/Api.cpp | 4 | ||||
-rw-r--r-- | src/EventHandler.cpp | 1 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 2 | ||||
-rw-r--r-- | src/tools/FileTools.cpp | 10 | ||||
-rw-r--r-- | src/tools/StringTools.cpp | 2 |
7 files changed, 22 insertions, 6 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index b2f6911..bddcd87 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -323,7 +323,7 @@ public: * @param fileId File identifier to get info about * @return A File object. */ - File::Ptr getFile(int32_t fileId) const; + File::Ptr getFile(const std::string &fileId) const; /** * Use this method for your bot to leave a group, supergroup or channel. diff --git a/include/tgbot/tools/FileTools.h b/include/tgbot/tools/FileTools.h index 7329a8e..97fb52c 100644 --- a/include/tgbot/tools/FileTools.h +++ b/include/tgbot/tools/FileTools.h @@ -19,6 +19,13 @@ namespace FileTools { */ std::string read(const std::string& filePath); +/** +* Save file to disk. +* @param filePath Path to a file +* @return bool success +*/ +bool write(const std::string& content, const std::string& filePath); + }; diff --git a/src/Api.cpp b/src/Api.cpp index 984deb5..6fd86c2 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -310,7 +310,7 @@ Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const st if (disableNotification){ args.push_back(HttpReqArg("disable_notification", disableNotification)); } - return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args)); + return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args)); } Message::Ptr Api::sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const { @@ -410,7 +410,7 @@ UserProfilePhotos::Ptr Api::getUserProfilePhotos(int32_t userId, int32_t offset, return TgTypeParser::getInstance().parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); } -File::Ptr Api::getFile(int32_t fileId) const +File::Ptr Api::getFile(const std::string &fileId) const { vector<HttpReqArg> args; args.push_back(HttpReqArg("file_id", fileId)); diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 8529400..d679683 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -3,6 +3,7 @@ // #include "tgbot/EventHandler.h" +#include <algorithm> namespace TgBot { diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index eeaba5e..cd30b02 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -270,7 +270,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const { result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); - result->emoji = data.get<string>("emoji"); + result->emoji = data.get("emoji", ""); result->fileSize = data.get("file_size", 0); return result; } diff --git a/src/tools/FileTools.cpp b/src/tools/FileTools.cpp index e92e96d..14c322c 100644 --- a/src/tools/FileTools.cpp +++ b/src/tools/FileTools.cpp @@ -22,4 +22,14 @@ std::string read(const std::string& filePath) { throw errno; } +bool write(const std::string& content, const std::string& filePath) { + ofstream out(filePath, ios::out | ios::binary); + if (out) { + out << content; + out.close(); + return true; + } + return false; +} + }; diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index ab7da46..0e68dcc 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -90,12 +90,10 @@ string generateRandomString(size_t length) { string urlEncode(const string& value, const std::string& additionalLegitChars) { static const string legitPunctuation = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~:"; std::stringstream ss; - std::string t; for (auto const &c : value) { if ((legitPunctuation.find(c) == std::string::npos) && (additionalLegitChars.find(c)==std::string::npos)) { ss << '%' << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)(unsigned char)c; - t = ss.str(); } else { ss << c; } |