diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-08-11 22:13:23 +0300 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-08-11 22:13:23 +0300 |
commit | 376b88ec09ef8cf71dd823467406c58204485fcc (patch) | |
tree | 9ca599b854d18006c65b26003ce7dbdd416fdf18 /include | |
parent | d7fbf7149d0e0c1c30972dab68d510ef6ac377dd (diff) |
Fixed compiler's errors in TgTypeParser + fixed indentation + some other fixes
Diffstat (limited to 'include')
35 files changed, 659 insertions, 653 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 1b4987a..ebebfd7 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -49,13 +49,13 @@ class Api { friend Bot; public: - Api(const std::string& token); + Api(const std::string& token); - /** - * A simple method for testing your bot's auth token. - * @return Basic information about the bot in form of a User object. - */ - User::Ptr getMe() const; + /** + * A simple method for testing your bot's auth token. + * @return Basic information about the bot in form of a User object. + */ + User::Ptr getMe() const; /** * Use this method to send text messages. @@ -66,7 +66,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendMessage(int32_t chatId, const std::string& text, bool disableWebPagePreview = false, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendMessage(int32_t chatId, const std::string& text, bool disableWebPagePreview = false, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to forward messages of any kind. @@ -75,7 +75,7 @@ public: * @param messageId Unique message identifier. * @return On success, the sent message is returned. */ - Message::Ptr forwardMessage(int32_t chatId, int32_t fromChatId, int32_t messageId) const; + Message::Ptr forwardMessage(int32_t chatId, int32_t fromChatId, int32_t messageId) const; /** * Use this method to send photos. @@ -86,7 +86,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendPhoto(int32_t chatId, const InputFile::Ptr& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendPhoto(int32_t chatId, const InputFile::Ptr& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send photos. @@ -97,7 +97,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendPhoto(int32_t chatId, const std::string& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendPhoto(int32_t chatId, const std::string& photo, const std::string& caption = "", int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). @@ -108,7 +108,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(int32_t chatId, const InputFile::Ptr& audio, int32_t duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendAudio(int32_t chatId, const InputFile::Ptr& audio, int32_t duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). @@ -119,7 +119,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(int32_t chatId, const std::string& audio, int32_t duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendAudio(int32_t chatId, const std::string& audio, int32_t duration = 0, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send general files. @@ -129,7 +129,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int32_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendDocument(int32_t chatId, const InputFile::Ptr& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send general files. @@ -139,7 +139,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(int32_t chatId, const std::string& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendDocument(int32_t chatId, const std::string& document, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send .webp stickers. @@ -149,7 +149,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendSticker(int32_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendSticker(int32_t chatId, const InputFile::Ptr& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send .webp stickers. @@ -159,7 +159,7 @@ public: * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendSticker(int32_t chatId, const std::string& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendSticker(int32_t chatId, const std::string& sticker, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). @@ -169,7 +169,7 @@ public: * @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(int32_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendVideo(int32_t chatId, const InputFile::Ptr& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). @@ -179,7 +179,7 @@ public: * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(int32_t chatId, const std::string& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendVideo(int32_t chatId, const std::string& video, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method to send point on the map. @@ -190,7 +190,7 @@ public: * @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. * @return On success, the sent message is returned. */ - Message::Ptr sendLocation(int32_t chatId, float latitude, float longitude, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; + Message::Ptr sendLocation(int32_t chatId, float latitude, float longitude, int32_t replyToMessageId = 0, const GenericReply::Ptr& replyMarkup = GenericReply::Ptr()) const; /** * Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). @@ -199,7 +199,7 @@ public: * @param chatId Unique identifier for the message recipient — User or GroupChat id. * @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data. */ - void sendChatAction(int32_t chatId, const std::string& action) const; + void sendChatAction(int32_t chatId, const std::string& action) const; /** * Use this method to get a list of profile pictures for a user. @@ -208,7 +208,7 @@ public: * @param limit Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. * @return A UserProfilePhotos object. */ - UserProfilePhotos::Ptr getUserProfilePhotos(int32_t userId, int32_t offset = 0, int32_t limit = 100) const; + UserProfilePhotos::Ptr getUserProfilePhotos(int32_t userId, int32_t offset = 0, int32_t limit = 100) const; /** * Use this method to receive incoming updates using long polling. @@ -219,7 +219,7 @@ public: * @param timeout Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. * @return An Array of Update objects */ - std::vector<Update::Ptr> getUpdates(int32_t offset = 0, int32_t limit = 100, int32_t timeout = 0) const; + std::vector<Update::Ptr> getUpdates(int32_t offset = 0, int32_t limit = 100, int32_t timeout = 0) const; /** * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. @@ -229,12 +229,12 @@ public: * Ports currently supported for Webhooks: 443, 80, 88, 8443. * @param url Optional. HTTPS url to send updates to. Use an empty string to remove webhook integration. */ - void setWebhook(const std::string& url = "") const; + void setWebhook(const std::string& url = "") const; private: - boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const; + boost::property_tree::ptree sendRequest(const std::string& method, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const; - const std::string _token; + const std::string _token; }; } diff --git a/include/tgbot/Bot.h b/include/tgbot/Bot.h index 5e96642..36e723b 100644 --- a/include/tgbot/Bot.h +++ b/include/tgbot/Bot.h @@ -38,42 +38,42 @@ namespace TgBot { class Bot { public: - explicit Bot(const std::string& token) : _token(token), _api(token), _eventHandler(&_eventBroadcaster) { - } + explicit Bot(const std::string& token) : _token(token), _api(token), _eventHandler(&_eventBroadcaster) { + } - /** - * @return Token for accessing api. - */ - inline const std::string& getToken() const { - return _token; - } + /** + * @return Token for accessing api. + */ + inline const std::string& getToken() const { + return _token; + } - /** - * @return Object which can execute Telegram Bot API methods. - */ - inline const Api& getApi() const { - return _api; - } + /** + * @return Object which can execute Telegram Bot API methods. + */ + inline const Api& getApi() const { + return _api; + } - /** - * @return Object which holds all event listeners. - */ - inline EventBroadcaster& getEvents() { - return _eventBroadcaster; - } + /** + * @return Object which holds all event listeners. + */ + inline EventBroadcaster& getEvents() { + return _eventBroadcaster; + } - /** - * @return Object which handles new update objects. Usually it's only needed for TgLongPoll, TgWebhookLocalServer and TgWebhookTcpServer objects. - */ - inline const EventHandler& getEventHandler() const { - return _eventHandler; - } + /** + * @return Object which handles new update objects. Usually it's only needed for TgLongPoll, TgWebhookLocalServer and TgWebhookTcpServer objects. + */ + inline const EventHandler& getEventHandler() const { + return _eventHandler; + } private: - const std::string _token; - const Api _api; - EventBroadcaster _eventBroadcaster; - const EventHandler _eventHandler; + const std::string _token; + const Api _api; + EventBroadcaster _eventBroadcaster; + const EventHandler _eventHandler; }; } diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h index 03d7df1..3ec8865 100644 --- a/include/tgbot/EventBroadcaster.h +++ b/include/tgbot/EventBroadcaster.h @@ -43,73 +43,73 @@ class EventBroadcaster { friend EventHandler; public: - typedef std::function<void (const Message::Ptr&)> MessageListener; - - /** - * Registers listener which receives all messages which the bot can ever receive. - * @param listener Listener. - */ - inline void onAnyMessage(const MessageListener& listener) { - _onAnyMessageListeners.push_back(listener); - } - - /** - * Registers listener which receives all messages with commands (messages with leading '/' char). - * @param commandName Command name which listener can handle. - * @param listener Listener. - */ - inline void onCommand(const std::string& commandName, const MessageListener& listener) { - _onCommandListeners[commandName] = listener; - } - - /** - * Registers listener which receives all messages with commands (messages with leading '/' char) which haven't been handled by other listeners. - * @param listener Listener. - */ - inline void onUnknownCommand(const MessageListener& listener) { - _onUnknownCommandListeners.push_back(listener); - } - - /** - * Registers listener which receives all messages without commands (messages with no leading '/' char) - * @param listener Listener. - */ - inline void onNonCommandMessage(const MessageListener& listener) { - _onNonCommandMessageListeners.push_back(listener); - } + typedef std::function<void (const Message::Ptr&)> MessageListener; + + /** + * Registers listener which receives all messages which the bot can ever receive. + * @param listener Listener. + */ + inline void onAnyMessage(const MessageListener& listener) { + _onAnyMessageListeners.push_back(listener); + } + + /** + * Registers listener which receives all messages with commands (messages with leading '/' char). + * @param commandName Command name which listener can handle. + * @param listener Listener. + */ + inline void onCommand(const std::string& commandName, const MessageListener& listener) { + _onCommandListeners[commandName] = listener; + } + + /** + * Registers listener which receives all messages with commands (messages with leading '/' char) which haven't been handled by other listeners. + * @param listener Listener. + */ + inline void onUnknownCommand(const MessageListener& listener) { + _onUnknownCommandListeners.push_back(listener); + } + + /** + * Registers listener which receives all messages without commands (messages with no leading '/' char) + * @param listener Listener. + */ + inline void onNonCommandMessage(const MessageListener& listener) { + _onNonCommandMessageListeners.push_back(listener); + } private: - inline void broadcastAnyMessage(const Message::Ptr& message) const { - for (const MessageListener& item : _onAnyMessageListeners) { - item(message); - } - } - - inline bool broadcastCommand(const std::string command, const Message::Ptr& message) const { - std::map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command); - if (iter == _onCommandListeners.end()) { - return false; - } - iter->second(message); - return true; - } - - inline void broadcastUnknownCommand(const Message::Ptr& message) const { - for (const MessageListener& item : _onUnknownCommandListeners) { - item(message); - } - } - - inline void broadcastNonCommandMessage(const Message::Ptr& message) const { - for (const MessageListener& item : _onNonCommandMessageListeners) { - item(message); - } - } - - std::vector<MessageListener> _onAnyMessageListeners; - std::map<std::string, MessageListener> _onCommandListeners; - std::vector<MessageListener> _onUnknownCommandListeners; - std::vector<MessageListener> _onNonCommandMessageListeners; + inline void broadcastAnyMessage(const Message::Ptr& message) const { + for (const MessageListener& item : _onAnyMessageListeners) { + item(message); + } + } + + inline bool broadcastCommand(const std::string command, const Message::Ptr& message) const { + std::map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command); + if (iter == _onCommandListeners.end()) { + return false; + } + iter->second(message); + return true; + } + + inline void broadcastUnknownCommand(const Message::Ptr& message) const { + for (const MessageListener& item : _onUnknownCommandListeners) { + item(message); + } + } + + inline void broadcastNonCommandMessage(const Message::Ptr& message) const { + for (const MessageListener& item : _onNonCommandMessageListeners) { + item(message); + } + } + + std::vector<MessageListener> _onAnyMessageListeners; + std::map<std::string, MessageListener> _onCommandListeners; + std::vector<MessageListener> _onUnknownCommandListeners; + std::vector<MessageListener> _onNonCommandMessageListeners; }; } diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index abcf925..1ec2cbe 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -32,23 +32,23 @@ namespace TgBot { class EventHandler { public: - explicit EventHandler(const EventBroadcaster* broadcaster) : _broadcaster(broadcaster) { - } - - inline void handleUpdate(const Update::Ptr& update) const { - _broadcaster->broadcastAnyMessage(update->message); - if (StringTools::startsWith(update->message->text, "/")) { - std::string command = update->message->text.substr(1, update->message->text.find(' ') - 2); - if (!_broadcaster->broadcastCommand(command, update->message)) { - _broadcaster->broadcastUnknownCommand(update->message); - } - } else { - _broadcaster->broadcastNonCommandMessage(update->message); - } - } + explicit EventHandler(const EventBroadcaster* broadcaster) : _broadcaster(broadcaster) { + } + + inline void handleUpdate(const Update::Ptr& update) const { + _broadcaster->broadcastAnyMessage(update->message); + if (StringTools::startsWith(update->message->text, "/")) { + std::string command = update->message->text.substr(1, update->message->text.find(' ') - 2); + if (!_broadcaster->broadcastCommand(command, update->message)) { + _broadcaster->broadcastUnknownCommand(update->message); + } + } else { + _broadcaster->broadcastNonCommandMessage(update->message); + } + } private: - const EventBroadcaster* _broadcaster; + const EventBroadcaster* _broadcaster; }; } diff --git a/include/tgbot/TgException.h b/include/tgbot/TgException.h index 6f01fd3..1a3e172 100644 --- a/include/tgbot/TgException.h +++ b/include/tgbot/TgException.h @@ -35,7 +35,7 @@ namespace TgBot { class TgException : public std::runtime_error { public: - explicit TgException(const std::string description); + explicit TgException(const std::string description); }; } diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 0571c25..759dc2f 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -50,129 +50,135 @@ namespace TgBot { class TgTypeParser { public: - static TgTypeParser& getInstance(); - - User::Ptr parseUser(const boost::property_tree::ptree& data) const; - std::string parseUser(const User::Ptr& object) const; - GroupChat::Ptr parseGroupChat(const boost::property_tree::ptree& data) const; - std::string parseGroupChat(const GroupChat::Ptr& object) const; - Message::Ptr parseMessage(const boost::property_tree::ptree& data) const; - std::string parseMessage(const Message::Ptr& object) const; - PhotoSize::Ptr parsePhotoSize(const boost::property_tree::ptree& data) const; - std::string parsePhotoSize(const PhotoSize::Ptr& object) const; - Audio::Ptr parseAudio(const boost::property_tree::ptree& data) const; - std::string parseAudio(const Audio::Ptr& object) const; - Document::Ptr parseDocument(const boost::property_tree::ptree& data) const; - std::string parseDocument(const Document::Ptr& object) const; - Sticker::Ptr parseSticker(const boost::property_tree::ptree& data) const; - std::string parseSticker(const Sticker::Ptr& object) const; - Video::Ptr parseVideo(const boost::property_tree::ptree& data) const; - std::string parseVideo(const Video::Ptr& object) const; - Contact::Ptr parseContact(const boost::property_tree::ptree& data) const; - std::string parseContact(const Contact::Ptr& object) const; - Location::Ptr parseLocation(const boost::property_tree::ptree& data) const; - std::string parseLocation(const Location::Ptr& object) const; - Update::Ptr parseUpdate(const boost::property_tree::ptree& data) const; - std::string parseUpdate(const Update::Ptr& object) const; - UserProfilePhotos::Ptr parseUserProfilePhotos(const boost::property_tree::ptree& data) const; - std::string parseUserProfilePhotos(const UserProfilePhotos::Ptr& object) const; - ReplyKeyboardMarkup::Ptr parseReplyKeyboardMarkup(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const; - ReplyKeyboardHide::Ptr parseReplyKeyboardHide(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const; - ForceReply::Ptr parseForceReply(const boost::property_tree::ptree& data) const; - std::string parseForceReply(const ForceReply::Ptr& object) const; - GenericChat::Ptr parseGenericChat(const boost::property_tree::ptree& data) const; - std::string parseGenericChat(const GenericChat::Ptr& object) const; - GenericReply::Ptr parseGenericReply(const boost::property_tree::ptree& data) const; - std::string parseGenericReply(const GenericReply::Ptr& object) const; - - inline boost::property_tree::ptree parseJson(const std::string& json) const { - boost::property_tree::ptree tree; - std::istringstream input(json); - boost::property_tree::read_json(input, tree); - return tree; - } - - template<typename T> - std::shared_ptr<T> tryParse(std::shared_ptr<T> (TgTypeParser::*const parseFunc)(const boost::property_tree::ptree&) const, const boost::property_tree::ptree& data, const std::string& keyName) const { - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return std::shared_ptr<T>(); - } - return (this->*parseFunc)(treeItem->second); - } - - template<typename T> - std::vector<std::shared_ptr<T>> parseArray(std::shared_ptr<T> (TgTypeParser::*const parseFunc)(const boost::property_tree::ptree&) const, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector<std::shared_ptr<T>> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { - result.push_back((this->*parseFunc)(innerTreeItem.second)); - } - return result; - } - - template<typename T> - std::vector<std::vector<std::shared_ptr<T>>> parse2DArray(std::shared_ptr<T> (TgTypeParser::*const parseFunc)(const boost::property_tree::ptree&) const, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector<std::vector<std::shared_ptr<T>>> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { - std::vector<std::shared_ptr<T>> innerResult; - for (const std::pair<const std::string, boost::property_tree::ptree>& innerInnerTreeItem : innerTreeItem.second) { - innerResult.push_back((this->*parseFunc)(innerInnerTreeItem.second)); - } - result.push_back(innerResult); - } - return result; - } - - template<typename T> - std::string parseArray(std::string (TgTypeParser::*const parseFunc)(const std::shared_ptr<T>&) const, const std::vector<std::shared_ptr<T>>& objects) const { - std::string result; - result += '['; - for (const std::shared_ptr<T>& item : objects) { - result += (this->*parseFunc)(item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; - } - - template<typename T> - std::string parse2DArray(std::string (TgTypeParser::*const parseFunc)(const std::shared_ptr<T>&) const, const std::vector<std::vector<std::shared_ptr<T>>>& objects) const { - std::string result; - result += '['; - for (const std::vector<std::shared_ptr<T>>& item : objects) { - result += parseArray(parseFunc, item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; - } + template<typename T> + using JsonToTgTypeFunc = std::shared_ptr<T> (TgTypeParser::*)(const boost::property_tree::ptree&) const; + + template<typename T> + using TgTypeToJsonFunc = std::string (TgTypeParser::*)(const std::shared_ptr<T>&) const; + + static TgTypeParser& getInstance(); + + User::Ptr parseJsonAndGetUser(const boost::property_tree::ptree& data) const; + std::string parseUser(const User::Ptr& object) const; + GroupChat::Ptr parseJsonAndGetGroupChat(const boost::property_tree::ptree& data) const; + std::string parseGroupChat(const GroupChat::Ptr& object) 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; + std::string parsePhotoSize(const PhotoSize::Ptr& object) const; + Audio::Ptr parseJsonAndGetAudio(const boost::property_tree::ptree& data) const; + std::string parseAudio(const Audio::Ptr& object) const; + Document::Ptr parseJsonAndGetDocument(const boost::property_tree::ptree& data) const; + std::string parseDocument(const Document::Ptr& object) const; + Sticker::Ptr parseJsonAndGetSticker(const boost::property_tree::ptree& data) const; + std::string parseSticker(const Sticker::Ptr& object) const; + Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const; + std::string parseVideo(const Video::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; + std::string parseLocation(const Location::Ptr& object) const; + Update::Ptr parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const; + std::string parseUpdate(const Update::Ptr& object) const; + UserProfilePhotos::Ptr parseJsonAndGetUserProfilePhotos(const boost::property_tree::ptree& data) const; + std::string parseUserProfilePhotos(const UserProfilePhotos::Ptr& object) const; + ReplyKeyboardMarkup::Ptr parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const; + std::string parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const; + ReplyKeyboardHide::Ptr parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const; + std::string parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const; + ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const; + std::string parseForceReply(const ForceReply::Ptr& object) const; + GenericChat::Ptr parseJsonAndGetGenericChat(const boost::property_tree::ptree& data) const; + std::string parseGenericChat(const GenericChat::Ptr& object) const; + GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const; + std::string parseGenericReply(const GenericReply::Ptr& object) const; + + inline boost::property_tree::ptree parseJson(const std::string& json) const { + boost::property_tree::ptree tree; + std::istringstream input(json); + boost::property_tree::read_json(input, tree); + return tree; + } + + template<typename T> + std::shared_ptr<T> tryParseJson(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { + return std::shared_ptr<T>(); + } + return (this->*parseFunc)(treeItem->second); + } + + template<typename T> + std::vector<std::shared_ptr<T>> parseJsonAndGetArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + std::vector<std::shared_ptr<T>> result; + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { + return result; + } + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { + result.push_back((this->*parseFunc)(innerTreeItem.second)); + } + return result; + } + + template<typename T> + std::vector<std::vector<std::shared_ptr<T>>> parseJsonAndGet2DArray(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { + std::vector<std::vector<std::shared_ptr<T>>> result; + auto treeItem = data.find(keyName); + if (treeItem == data.not_found()) { + return result; + } + for (const std::pair<const std::string, boost::property_tree::ptree>& innerTreeItem : treeItem->second) { + std::vector<std::shared_ptr<T>> innerResult; + for (const std::pair<const std::string, boost::property_tree::ptree>& innerInnerTreeItem : innerTreeItem.second) { + innerResult.push_back((this->*parseFunc)(innerInnerTreeItem.second)); + } + result.push_back(innerResult); + } + return result; + } + + template<typename T> + std::string parseArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::shared_ptr<T>>& objects) const { + std::string result; + result += '['; + for (const std::shared_ptr<T>& item : objects) { + result += (this->*parseFunc)(item); + result += ','; + } + result.erase(result.length() - 1); + result += ']'; + return result; + } + + template<typename T> + std::string parse2DArray(TgTypeToJsonFunc<T> parseFunc, const std::vector<std::vector<std::shared_ptr<T>>>& objects) const { + std::string result; + result += '['; + for (const std::vector<std::shared_ptr<T>>& item : objects) { + result += parseArray(parseFunc, item); + result += ','; + } + result.erase(result.length() - 1); + result += ']'; + return result; + } private: - template<typename T> - void appendToJson(std::string& json, const std::string& varName, const T& value) const { - if (value == 0) { - return; - } - json += '"'; - json += varName; - json += "\":"; - json += value; - json += ','; - } - - void appendToJson(std::string& json, const std::string& varName, const std::string& value) const; + template<typename T> + void appendToJson(std::string& json, const std::string& varName, const T& value) const { + if (value == 0) { + return; + } + json += '"'; + json += varName; + json += "\":"; + json += value; + json += ','; + } + + void appendToJson(std::string& json, const std::string& varName, const std::string& value) const; }; } diff --git a/include/tgbot/doxygenMain.h b/include/tgbot/doxygenMain.h index 0d25e61..d77efa4 100644 --- a/include/tgbot/doxygenMain.h +++ b/include/tgbot/doxygenMain.h @@ -36,7 +36,7 @@ * Firstly you need to install some dependencies. You have to have boost library at the runtime and cmake at the compilation step to be able to use this library. * On Debian-based distibutives you can do it with these commands: * @code{.sh} - * sudo apt-get install cmake libboost-dev + * sudo apt-get install g++ make binutils cmake libssl-dev libboost-system-dev libboost-iostreams-dev libboost-test-dev * @endcode * * To compile the library execute this commands: diff --git a/include/tgbot/net/HttpClient.h b/include/tgbot/net/HttpClient.h index d39e108..e695398 100644 --- a/include/tgbot/net/HttpClient.h +++ b/include/tgbot/net/HttpClient.h @@ -43,17 +43,17 @@ public: /** * Returns instance which lives during all application lifetime. */ - static HttpClient& getInstance(); + static HttpClient& getInstance(); - /** - * Sends a request to the url. - * If there's no args specified, a GET request will be sent, otherwise a POST request will be sent. - * If at least 1 arg is marked as file, the content type of a request will be multipart/form-data, otherwise it will be application/x-www-form-urlencoded. - */ - std::string makeRequest(const Url& url, const std::vector<HttpReqArg>& args); + /** + * Sends a request to the url. + * If there's no args specified, a GET request will be sent, otherwise a POST request will be sent. + * If at least 1 arg is marked as file, the content type of a request will be multipart/form-data, otherwise it will be application/x-www-form-urlencoded. + */ + std::string makeRequest(const Url& url, const std::vector<HttpReqArg>& args); private: - boost::asio::io_service _ioService; + boost::asio::io_service _ioService; }; } diff --git a/include/tgbot/net/HttpParser.h b/include/tgbot/net/HttpParser.h index dcb857b..83068fb 100644 --- a/include/tgbot/net/HttpParser.h +++ b/include/tgbot/net/HttpParser.h @@ -34,33 +34,33 @@ namespace TgBot { class HttpParser { public: - static HttpParser& getInstance(); + static HttpParser& getInstance(); - std::string generateRequest(const Url& url, const std::vector<HttpReqArg>& args, bool isKeepAlive = false); - std::string generateMultipartFormData(const std::vector<HttpReqArg>& args, const std::string& bondary); - std::string generateMultipartBoundary(const std::vector<HttpReqArg>& args); - std::string generateWwwFormUrlencoded(const std::vector<HttpReqArg>& args); - std::string generateResponse(const std::string& data, const std::string& mimeType = "text/plain", short unsigned statusCode = 200, const std::string& statusStr = "OK", bool isKeepAlive = false); + std::string generateRequest(const Url& url, const std::vector<HttpReqArg>& args, bool isKeepAlive = false); + std::string generateMultipartFormData(const std::vector<HttpReqArg>& args, const std::string& bondary); + std::string generateMultipartBoundary(const std::vector<HttpReqArg>& args); + std::string generateWwwFormUrlencoded(const std::vector<HttpReqArg>& args); + std::string generateResponse(const std::string& data, const std::string& mimeType = "text/plain", short unsigned statusCode = 200, const std::string& statusStr = "OK", bool isKeepAlive = false); - inline std::string parseRequest(const std::string& data, std::map<std::string, std::string>& headers) { - return parseHttp(true, data, headers); - } + inline std::string parseRequest(const std::string& data, std::map<std::string, std::string>& headers) { + return parseHttp(true, data, headers); + } - inline std::string parseRequest(const std::string& data) { - return parseHttp(true, data); - } + inline std::string parseRequest(const std::string& data) { + return parseHttp(true, data); + } - inline std::string parseResponse(const std::string& data, std::map<std::string, std::string>& headers) { - return parseHttp(false, data, headers); - } + inline std::string parseResponse(const std::string& data, std::map<std::string, std::string>& headers) { + return parseHttp(false, data, headers); + } - inline std::string parseResponse(const std::string& data) { - return parseHttp(false, data); - } + inline std::string parseResponse(const std::string& data) { + return parseHttp(false, data); + } private: - std::string parseHttp(bool isRequest, const std::string& data, std::map<std::string, std::string>& headers); - std::string parseHttp(bool isRequest, const std::string& data); + std::string parseHttp(bool isRequest, const std::string& data, std::map<std::string, std::string>& headers); + std::string parseHttp(bool isRequest, const std::string& data); }; } diff --git a/include/tgbot/net/HttpReqArg.h b/include/tgbot/net/HttpReqArg.h index d70e8b5..65f4f52 100644 --- a/include/tgbot/net/HttpReqArg.h +++ b/include/tgbot/net/HttpReqArg.h @@ -36,31 +36,31 @@ namespace TgBot { class HttpReqArg { public: - template<typename T> - HttpReqArg(const std::string& name, const T& value, bool isFile = false, const std::string& mimeType = "text/plain") : - name(name), value(boost::lexical_cast<std::string>(value)), isFile(isFile), mimeType(mimeType) - { - } + template<typename T> + HttpReqArg(const std::string& name, const T& value, bool isFile = false, const std::string& mimeType = "text/plain") : + name(name), value(boost::lexical_cast<std::string>(value)), isFile(isFile), mimeType(mimeType) + { + } - /** - * Name of an argument. - */ - std::string name; + /** + * Name of an argument. + */ + std::string name; - /** - * Value of an argument. - */ - std::string value; + /** + * Value of an argument. + */ + std::string value; - /** - * Should be true if an argument value hold some file contents - */ - bool isFile = false; + /** + * Should be true if an argument value hold some file contents + */ + bool isFile = false; - /** - * Mime type of an argument value. This field makes sense only if isFile is true. - */ - std::string mimeType = "text/plain"; + /** + * Mime type of an argument value. This field makes sense only if isFile is true. + */ + std::string mimeType = "text/plain"; }; } diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h index 0a66900..bac7382 100644 --- a/include/tgbot/net/HttpServer.h +++ b/include/tgbot/net/HttpServer.h @@ -39,63 +39,63 @@ template<typename Protocol> class HttpServer { private: - class Connection; + class Connection; public: - typedef std::function<std::string (const std::string&, const std::map<std::string, std::string>)> ServerHandler; - - HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) { - } - - /** - * Starts receiving new connections. - */ - void start() { - std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(acceptor->get_io_service())); - std::shared_ptr<Connection<Protocol>> connection(new Connection<Protocol>(socket, _handler)); - acceptor->async_accept(*connection->socket, [this, connection]() { - connection->start(); - start(); - }); - _ioService.run(); - } - - /** - * Stops receiving new connections. - */ - void stop() { - _ioService.stop(); - } + typedef std::function<std::string (const std::string&, const std::map<std::string, std::string>)> ServerHandler; + + HttpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) : _acceptor(acceptor), _handler(handler) { + } + + /** + * Starts receiving new connections. + */ + void start() { + std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(acceptor->get_io_service())); + std::shared_ptr<Connection<Protocol>> connection(new Connection<Protocol>(socket, _handler)); + acceptor->async_accept(*connection->socket, [this, connection]() { + connection->start(); + start(); + }); + _ioService.run(); + } + + /** + * Stops receiving new connections. + */ + void stop() { + _ioService.stop(); + } private: - template<typename Protocol> - class Connection { - - public: - Connection(std::shared_ptr<boost::asio::basic_stream_socket<Protocol>>& socket, const ServerHandler& handler) : socket(socket), _handler(handler) { - boost::asio::socket_base::keep_alive option(true); - socket.set_option(option); - } - - void start() { - data.reserve(10240); - socket->async_receive(data, [this]() { - std::map<std::string, std::string> headers; - std::string body = HttpParser::parseResponse(data, headers); - socket->async_send(_handler(body, headers)); - }); - } - - std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket; - std::string data; - - private: - const ServerHandler _handler; - }; - - boost::asio::io_service _ioService; - std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> _acceptor; - const ServerHandler _handler; + template<typename Protocol> + class Connection { + + public: + Connection(std::shared_ptr<boost::asio::basic_stream_socket<Protocol>>& socket, const ServerHandler& handler) : socket(socket), _handler(handler) { + boost::asio::socket_base::keep_alive option(true); + socket.set_option(option); + } + + void start() { + data.reserve(10240); + socket->async_receive(data, [this]() { + std::map<std::string, std::string> headers; + std::string body = HttpParser::parseResponse(data, headers); + socket->async_send(_handler(body, headers)); + }); + } + + std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket; + std::string data; + + private: + const ServerHandler _handler; + }; + + boost::asio::io_service _ioService; + std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>> _acceptor; + const ServerHandler _handler; }; } diff --git a/include/tgbot/net/TgLongPoll.h b/include/tgbot/net/TgLongPoll.h index 932fc6d..949a2a4 100644 --- a/include/tgbot/net/TgLongPoll.h +++ b/include/tgbot/net/TgLongPoll.h @@ -36,18 +36,18 @@ namespace TgBot { class TgLongPoll { public: - TgLongPoll(const Api* api, const EventHandler* eventHandler); - TgLongPoll(const Bot& bot); + TgLongPoll(const Api* api, const EventHandler* eventHandler); + TgLongPoll(const Bot& bot); - /** - * Starts long poll. After new update will come, this method will parse it and send to EventHandler which invokes your listeners. Designed to be executed in a loop. - */ - void start(); + /** + * Starts long poll. After new update will come, this method will parse it and send to EventHandler which invokes your listeners. Designed to be executed in a loop. + */ + void start(); private: - int32_t _lastUpdateId = 0; - const Api* _api; - const EventHandler* _eventHandler; + int32_t _lastUpdateId = 0; + const Api* _api; + const EventHandler* _eventHandler; }; } diff --git a/include/tgbot/net/TgWebhookLocalServer.h b/include/tgbot/net/TgWebhookLocalServer.h index 7835f28..8faf61d 100644 --- a/include/tgbot/net/TgWebhookLocalServer.h +++ b/include/tgbot/net/TgWebhookLocalServer.h @@ -34,16 +34,16 @@ namespace TgBot { class TgWebhookLocalServer : public TgWebhookServer<boost::asio::local::stream_protocol> { public: - TgWebhookLocalServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>& acceptor, const std::string& path, EventHandler* eventHandler) = delete; + TgWebhookLocalServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>& acceptor, const std::string& path, EventHandler* eventHandler) = delete; - TgWebhookLocalServer(const std::string& path, const EventHandler* eventHandler) : - TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>(new boost::asio::local::stream_protocol::acceptor(_ioService, boost::asio::local::stream_protocol::endpoint(path))), path, eventHandler) - { - } + TgWebhookLocalServer(const std::string& path, const EventHandler* eventHandler) : + TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>(new boost::asio::local::stream_protocol::acceptor(_ioService, boost::asio::local::stream_protocol::endpoint(path))), path, eventHandler) + { + } - TgWebhookLocalServer(const std::string& path, const Bot& bot) : TgWebhookLocalServer(path, &bot.getEventHandler()) { + TgWebhookLocalServer(const std::string& path, const Bot& bot) : TgWebhookLocalServer(path, &bot.getEventHandler()) { - } + } }; } diff --git a/include/tgbot/net/TgWebhookServer.h b/include/tgbot/net/TgWebhookServer.h index a8155ff..f583093 100644 --- a/include/tgbot/net/TgWebhookServer.h +++ b/include/tgbot/net/TgWebhookServer.h @@ -34,22 +34,22 @@ template<typename Protocol> class TgWebhookServer : public HttpServer<Protocol> { public: - TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) = delete; - - TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const std::string& path, const EventHandler* eventHandler) : - HttpServer(acceptor, [this, eventHandler, &path](const std::string& data, const std::map<std::string, std::string>& headers) -> std::string { - if (headers["method"] == "POST" && headers["path"] == path) { - eventHandler->handleUpdate(TgTypeParser::getInstance().parseUpdate(TgTypeParser::getInstance().parseJson(data))); - } - return HttpParser::generateResponse(""); - }) - { - } - - TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const std::string& path, const Bot& bot) : - TgWebhookServer(acceptor, path, &bot.getEventHandler()) - { - } + TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const ServerHandler& handler) = delete; + + TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const std::string& path, const EventHandler* eventHandler) : + HttpServer(acceptor, [this, eventHandler, &path](const std::string& data, const std::map<std::string, std::string>& headers) -> std::string { + if (headers["method"] == "POST" && headers["path"] == path) { + eventHandler->handleUpdate(TgTypeParser::getInstance().parseUpdate(TgTypeParser::getInstance().parseJson(data))); + } + return HttpParser::generateResponse(""); + }) + { + } + + TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<Protocol>>& acceptor, const std::string& path, const Bot& bot) : + TgWebhookServer(acceptor, path, &bot.getEventHandler()) + { + } }; } diff --git a/include/tgbot/net/TgWebhookTcpServer.h b/include/tgbot/net/TgWebhookTcpServer.h index cac2638..417b162 100644 --- a/include/tgbot/net/TgWebhookTcpServer.h +++ b/include/tgbot/net/TgWebhookTcpServer.h @@ -34,15 +34,15 @@ namespace TgBot { class TgWebhookTcpServer : public TgWebhookServer<boost::asio::ip::tcp> { public: - TgWebhookTcpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>>& acceptor, const std::string& path, EventHandler* eventHandler) = delete; + TgWebhookTcpServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>>& acceptor, const std::string& path, EventHandler* eventHandler) = delete; - TgWebhookTcpServer(unsigned short port, const std::string& path, const EventHandler* eventHandler) : - TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>>(new boost::asio::ip::tcp::acceptor(_ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))), path, eventHandler) - { - } + TgWebhookTcpServer(unsigned short port, const std::string& path, const EventHandler* eventHandler) : + TgWebhookServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>>(new boost::asio::ip::tcp::acceptor(_ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))), path, eventHandler) + { + } - TgWebhookTcpServer(const std::string& path, const Bot& bot) : TgWebhookTcpServer(path, &bot.getEventHandler()) { - } + TgWebhookTcpServer(const std::string& path, const Bot& bot) : TgWebhookTcpServer(path, &bot.getEventHandler()) { + } }; } diff --git a/include/tgbot/net/Url.h b/include/tgbot/net/Url.h index 818e934..56f502a 100644 --- a/include/tgbot/net/Url.h +++ b/include/tgbot/net/Url.h @@ -34,32 +34,32 @@ namespace TgBot { class Url { public: - Url(const std::string& url); + Url(const std::string& url); /** * Protocol part of an url. Example: https:// */ - std::string protocol; + std::string protocol; /** * Host part of an url. Example: www.example.com */ - std::string host; + std::string host; /** * Path part of an url including preceding '/' char. Example: /index.html */ - std::string path; + std::string path; /** * Query part of an url without '?' char. Example: a=1&b=2&c=3 */ - std::string query; + std::string query; /** * Fragment part of an url without '#' char. Example: section1 */ - std::string fragment; + std::string fragment; }; } diff --git a/include/tgbot/tools/StringTools.h b/include/tgbot/tools/StringTools.h index 6c01575..8df7434 100644 --- a/include/tgbot/tools/StringTools.h +++ b/include/tgbot/tools/StringTools.h @@ -82,9 +82,9 @@ std::string urlDecode(const std::string& value); * @return Array of substrings */ inline std::vector<std::string> split(const std::string& str, char delimiter) { - std::vector<std::string> result; - split(str, delimiter, result); - return result; + std::vector<std::string> result; + split(str, delimiter, result); + return result; } } diff --git a/include/tgbot/types/Audio.h b/include/tgbot/types/Audio.h index 8e255fe..e39eb00 100644 --- a/include/tgbot/types/Audio.h +++ b/include/tgbot/types/Audio.h @@ -35,27 +35,27 @@ namespace TgBot { class Audio { public: - typedef std::shared_ptr<Audio> Ptr; + typedef std::shared_ptr<Audio> Ptr; /** * Unique identifier for this file. */ - std::string fileId; + std::string fileId; /** * Duration of the audio in seconds as defined by sender. */ - int32_t duration; + int32_t duration; /** * Optional. MIME type of the file as defined by sender. */ - std::string mimeType; + std::string mimeType; /** * Optional. File size. */ - int32_t fileSize; + int32_t fileSize; }; } diff --git a/include/tgbot/types/Contact.h b/include/tgbot/types/Contact.h index dcd90b0..db2929d 100644 --- a/include/tgbot/types/Contact.h +++ b/include/tgbot/types/Contact.h @@ -35,27 +35,27 @@ namespace TgBot { class Contact { public: - typedef std::shared_ptr<Contact> Ptr; - - /** - * Contact's phone number. - */ - std::string phoneNumber; - - /** - * Contact's first name. - */ - std::string firstName; - - /** - * Optional. Contact's last name. - */ - std::string lastName; - - /** - * Optional. Contact's user identifier in Telegram. - */ - std::string userId; + typedef std::shared_ptr<Contact> Ptr; + + /** + * Contact's phone number. + */ + std::string phoneNumber; + + /** + * Contact's first name. + */ + std::string firstName; + + /** + * Optional. Contact's last name. + */ + std::string lastName; + + /** + * Optional. Contact's user identifier in Telegram. + */ + std::string userId; }; } diff --git a/include/tgbot/types/Document.h b/include/tgbot/types/Document.h index 1fd0522..88613cb 100644 --- a/include/tgbot/types/Document.h +++ b/include/tgbot/types/Document.h @@ -37,32 +37,32 @@ namespace TgBot { class Document { public: - typedef std::shared_ptr<Document> Ptr; + typedef std::shared_ptr<Document> Ptr; /** * Unique file identifier. */ - std::string fileId; + std::string fileId; /** * Optional. Document thumbnail as defined by sender. */ - PhotoSize::Ptr thumb; + PhotoSize::Ptr thumb; /** * Optional. Original filename as defined by sender. */ - std::string fileName; + std::string fileName; /** * Optional. MIME type of the file as defined by sender. */ - std::string mimeType; + std::string mimeType; /** * Optional. File size. */ - int32_t fileSize; + int32_t fileSize; }; } diff --git a/include/tgbot/types/ForceReply.h b/include/tgbot/types/ForceReply.h index 237967e..f46197a 100644 --- a/include/tgbot/types/ForceReply.h +++ b/include/tgbot/types/ForceReply.h @@ -40,17 +40,17 @@ namespace TgBot { class ForceReply : public GenericReply { public: - typedef std::shared_ptr<ForceReply> Ptr; + typedef std::shared_ptr<ForceReply> Ptr; - /** - * Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply' - */ - const bool forceReply = true; + /** + * Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply' + */ + const bool forceReply = true; - /** - * Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. - */ - bool selective; + /** + * Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + */ + bool selective; }; } diff --git a/include/tgbot/types/GenericChat.h b/include/tgbot/types/GenericChat.h index b590312..f1fe6a1 100644 --- a/include/tgbot/types/GenericChat.h +++ b/include/tgbot/types/GenericChat.h @@ -34,14 +34,14 @@ namespace TgBot { class GenericChat { public: - typedef std::shared_ptr<GenericChat> Ptr; + typedef std::shared_ptr<GenericChat> Ptr; - virtual ~GenericChat() { } + virtual ~GenericChat() { } - /** - * Unique identifier for this user, bot or group chat - */ - int32_t id; + /** + * Unique identifier for this user, bot or group chat + */ + int32_t id; }; } diff --git a/include/tgbot/types/GenericReply.h b/include/tgbot/types/GenericReply.h index 124c83a..64e6b6c 100644 --- a/include/tgbot/types/GenericReply.h +++ b/include/tgbot/types/GenericReply.h @@ -34,9 +34,9 @@ namespace TgBot { class GenericReply { public: - typedef std::shared_ptr<GenericReply> Ptr; + typedef std::shared_ptr<GenericReply> Ptr; - virtual ~GenericReply() { } + virtual ~GenericReply() { } }; } diff --git a/include/tgbot/types/GroupChat.h b/include/tgbot/types/GroupChat.h index 5704051..fedb7f0 100644 --- a/include/tgbot/types/GroupChat.h +++ b/include/tgbot/types/GroupChat.h @@ -37,12 +37,12 @@ namespace TgBot { class GroupChat : public GenericChat { public: - typedef std::shared_ptr<GroupChat> Ptr; + typedef std::shared_ptr<GroupChat> Ptr; - /** - * Group name. - */ - std::string title; + /** + * Group name. + */ + std::string title; }; } diff --git a/include/tgbot/types/InputFile.h b/include/tgbot/types/InputFile.h index 900838d..825e677 100644 --- a/include/tgbot/types/InputFile.h +++ b/include/tgbot/types/InputFile.h @@ -36,17 +36,17 @@ namespace TgBot { class InputFile { public: - typedef std::shared_ptr<InputFile> Ptr; + typedef std::shared_ptr<InputFile> Ptr; - /** - * Contents of a file. - */ - std::string data; + /** + * Contents of a file. + */ + std::string data; - /** - * Mime type of a file. - */ - std::string mimeType; + /** + * Mime type of a file. + */ + std::string mimeType; }; } diff --git a/include/tgbot/types/Location.h b/include/tgbot/types/Location.h index b35fdd7..9d9ef72 100644 --- a/include/tgbot/types/Location.h +++ b/include/tgbot/types/Location.h @@ -34,17 +34,17 @@ namespace TgBot { class Location { public: - typedef std::shared_ptr<Location> Ptr; + typedef std::shared_ptr<Location> Ptr; - /** - * Longitude as defined by sender. - */ - float longitude; + /** + * Longitude as defined by sender. + */ + float longitude; - /** - * Latitude as defined by sender. - */ - float latitude; + /** + * Latitude as defined by sender. + */ + float latitude; }; } diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index de07563..b8dfcc6 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -47,117 +47,117 @@ namespace TgBot { class Message { public: - typedef std::shared_ptr<Message> Ptr; - - /** - * Unique message identifier. - */ - int32_t messageId; - - /** - * Sender. - */ - User::Ptr from; - - /** - * Date the message was sent in Unix time. - */ - int32_t date; - - /** - * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group. - */ - GenericChat::Ptr chat; - - /** - * Optional. For forwarded messages, sender of the original message. - */ - User::Ptr forwardFrom; - - /** - * Optional. For forwarded messages, date the original message was sent in Unix time. - */ - int32_t forwardDate; - - /** - * Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. - */ - Message::Ptr replyToMessage; - - /** - * Optional. For text messages, the actual UTF-8 text of the message. - */ - std::string text; - - /** - * Optional. Message is an audio file, information about the file. - */ - Audio::Ptr audio; - - /** - * Optional. Message is a general file, information about the file. - */ - Document::Ptr document; - - /** - * Optional. Message is a photo, available sizes of the photo. - */ - std::vector<PhotoSize::Ptr> photo; - - /** - * Optional. Message is a sticker, information about the sticker. - */ - Sticker::Ptr sticker; - - /** - * Optional. Message is a video, information about the video. - */ - Video::Ptr video; - - /** - * Optional. Message is a shared contact, information about the contact. - */ - Contact::Ptr contact; - - /** - * Optional. Message is a shared location, information about the location. - */ - Location::Ptr location; - - /** - * Optional. A new member was added to the group, information about them (this member may be bot itself). - */ - User::Ptr newChatParticipant; - - /** - * Optional. A member was removed from the group, information about them (this member may be bot itself). - */ - User::Ptr leftChatParticipant; - - /** - * Optional. A group title was changed to this value. - */ - std::string newChatTitle; - - /** - * Optional. A group photo was change to this value. - */ - std::vector<PhotoSize::Ptr> newChatPhoto; - - /** - * Optional. Informs that the group photo was deleted. - */ - bool deleteChatPhoto; - - /** - * Optional. Informs that the group has been created. - */ - bool groupChatCreated; - - /** - * Optional. Text description of the photo or the video. - */ - std::string caption; + typedef std::shared_ptr<Message> Ptr; + + /** + * Unique message identifier. + */ + int32_t messageId; + + /** + * Sender. + */ + User::Ptr from; + + /** + * Date the message was sent in Unix time. + */ + int32_t date; + + /** + * Conversation the message belongs to — user in case of a private message, GroupChat in case of a group. + */ + GenericChat::Ptr chat; + + /** + * Optional. For forwarded messages, sender of the original message. + */ + User::Ptr forwardFrom; + + /** + * Optional. For forwarded messages, date the original message was sent in Unix time. + */ + int32_t forwardDate; + + /** + * Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. + */ + Message::Ptr replyToMessage; + + /** + * Optional. For text messages, the actual UTF-8 text of the message. + */ + std::string text; + + /** + * Optional. Message is an audio file, information about the file. + */ + Audio::Ptr audio; + + /** + * Optional. Message is a general file, information about the file. + */ + Document::Ptr document; + + /** + * Optional. Message is a photo, available sizes of the photo. + */ + std::vector<PhotoSize::Ptr> photo; + + /** + * Optional. Message is a sticker, information about the sticker. + */ + Sticker::Ptr sticker; + + /** + * Optional. Message is a video, information about the video. + */ + Video::Ptr video; + + /** + * Optional. Message is a shared contact, information about the contact. + */ + Contact::Ptr contact; + + /** + * Optional. Message is a shared location, information about the location. + */ + Location::Ptr location; + + /** + * Optional. A new member was added to the group, information about them (this member may be bot itself). + */ + User::Ptr newChatParticipant; + + /** + * Optional. A member was removed from the group, information about them (this member may be bot itself). + */ + User::Ptr leftChatParticipant; + + /** + * Optional. A group title was changed to this value. + */ + std::string newChatTitle; + + /** + * Optional. A group photo was change to this value. + */ + std::vector<PhotoSize::Ptr> newChatPhoto; + + /** + * Optional. Informs that the group photo was deleted. + */ + bool deleteChatPhoto; + + /** + * Optional. Informs that the group has been created. + */ + bool groupChatCreated; + + /** + * Optional. Text description of the photo or the video. + */ + std::string caption; }; } diff --git a/include/tgbot/types/PhotoSize.h b/include/tgbot/types/PhotoSize.h index c616423..0ccea49 100644 --- a/include/tgbot/types/PhotoSize.h +++ b/include/tgbot/types/PhotoSize.h @@ -35,27 +35,27 @@ namespace TgBot { class PhotoSize { public: - typedef std::shared_ptr<PhotoSize> Ptr; + typedef std::shared_ptr<PhotoSize> Ptr; /** * Unique identifier for this file. */ - std::string fileId; + std::string fileId; /** * Photo width. */ - int32_t width; + int32_t width; /** * Photo height. */ - int32_t height; + int32_t height; /** * Optional. File size. */ - int32_t fileSize; + int32_t fileSize; }; } diff --git a/include/tgbot/types/ReplyKeyboardHide.h b/include/tgbot/types/ReplyKeyboardHide.h index 18aa101..e4c4b20 100644 --- a/include/tgbot/types/ReplyKeyboardHide.h +++ b/include/tgbot/types/ReplyKeyboardHide.h @@ -36,18 +36,18 @@ namespace TgBot { class ReplyKeyboardHide : public GenericReply { public: - typedef std::shared_ptr<ReplyKeyboardHide> Ptr; + typedef std::shared_ptr<ReplyKeyboardHide> Ptr; /** * Requests clients to hide the custom keyboard. */ - const bool hideKeyboard = true; + const bool hideKeyboard = true; /** * Optional. Use this parameter if you want to hide keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. * Example: A user votes in a poll, bot returns confirmation message in reply to the vote and hides keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. */ - bool selective; + bool selective; }; } diff --git a/include/tgbot/types/ReplyKeyboardMarkup.h b/include/tgbot/types/ReplyKeyboardMarkup.h index 0f9ce0d..92d850e 100644 --- a/include/tgbot/types/ReplyKeyboardMarkup.h +++ b/include/tgbot/types/ReplyKeyboardMarkup.h @@ -38,28 +38,28 @@ namespace TgBot { class ReplyKeyboardMarkup : public GenericReply { public: - typedef std::shared_ptr<ReplyKeyboardMarkup> Ptr; + typedef std::shared_ptr<ReplyKeyboardMarkup> Ptr; - /** - * Array of button rows, each represented by an Array of Strings. - */ - std::vector<std::vector<std::string>> keyboard; + /** + * Array of button rows, each represented by an Array of Strings. + */ + std::vector<std::vector<std::string>> keyboard; - /** - * Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. - */ - bool resizeKeyboard; + /** + * Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. + */ + bool resizeKeyboard; - /** - * Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. - */ - bool oneTimeKeyboard; + /** + * Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. + */ + bool oneTimeKeyboard; - /** - * Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. - * Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard. - */ - bool selective; + /** + * Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard. + */ + bool selective; }; } diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h index c223081..252fb41 100644 --- a/include/tgbot/types/Sticker.h +++ b/include/tgbot/types/Sticker.h @@ -37,32 +37,32 @@ namespace TgBot { class Sticker { public: - typedef std::shared_ptr<Sticker> Ptr; + typedef std::shared_ptr<Sticker> Ptr; /** * Unique file identifier. */ - std::string fileId; + std::string fileId; /** * Optional. Sticker width. */ - int32_t width; + int32_t width; /** * Optional. Sticker height. */ - int32_t height; + int32_t height; /** * Optional. Optional. Sticker thumbnail in .webp or .jpg format. */ - PhotoSize::Ptr thumb; + PhotoSize::Ptr thumb; /** * Optional. File size. */ - int32_t fileSize; + int32_t fileSize; }; } diff --git a/include/tgbot/types/Update.h b/include/tgbot/types/Update.h index a4d41a4..9bf3a19 100644 --- a/include/tgbot/types/Update.h +++ b/include/tgbot/types/Update.h @@ -36,17 +36,17 @@ namespace TgBot { class Update { public: - typedef std::shared_ptr<Update> Ptr; + typedef std::shared_ptr<Update> Ptr; /** * The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. */ - int32_t updateId; + int32_t updateId; /** * Optional. New incoming message of any kind — text, photo, sticker, etc. */ - Message::Ptr message; + Message::Ptr message; }; } diff --git a/include/tgbot/types/User.h b/include/tgbot/types/User.h index 048d20a..99c7d12 100644 --- a/include/tgbot/types/User.h +++ b/include/tgbot/types/User.h @@ -37,22 +37,22 @@ namespace TgBot { class User : public GenericChat { public: - typedef std::shared_ptr<User> Ptr; + typedef std::shared_ptr<User> Ptr; /** * User‘s or bot’s first name. */ - std::string firstName; + std::string firstName; /** * Optional. User‘s or bot’s last name. */ - std::string lastName; + std::string lastName; /** * Optional. User‘s or bot’s username. */ - std::string username; + std::string username; }; } diff --git a/include/tgbot/types/UserProfilePhotos.h b/include/tgbot/types/UserProfilePhotos.h index 0079d37..7c5781d 100644 --- a/include/tgbot/types/UserProfilePhotos.h +++ b/include/tgbot/types/UserProfilePhotos.h @@ -37,17 +37,17 @@ namespace TgBot { class UserProfilePhotos { public: - typedef std::shared_ptr<UserProfilePhotos> Ptr; + typedef std::shared_ptr<UserProfilePhotos> Ptr; - /** - * Total number of profile pictures the target user has. - */ - int32_t totalCount; + /** + * Total number of profile pictures the target user has. + */ + int32_t totalCount; - /** - * Requested profile pictures (in up to 4 sizes each). - */ - std::vector<std::vector<PhotoSize::Ptr>> photos; + /** + * Requested profile pictures (in up to 4 sizes each). + */ + std::vector<std::vector<PhotoSize::Ptr>> photos; }; } diff --git a/include/tgbot/types/Video.h b/include/tgbot/types/Video.h index 368f3e1..b20d914 100644 --- a/include/tgbot/types/Video.h +++ b/include/tgbot/types/Video.h @@ -37,42 +37,42 @@ namespace TgBot { class Video { public: - typedef std::shared_ptr<Video> Ptr; + typedef std::shared_ptr<Video> Ptr; - /** - * Unique identifier for this file. - */ - std::string fileId; + /** + * Unique identifier for this file. + */ + std::string fileId; - /** - * Video width as defined by sender. - */ - int32_t width; + /** + * Video width as defined by sender. + */ + int32_t width; /** * Video height as defined by sender. */ - int32_t height; + int32_t height; /** * Duration of the video in seconds as defined by sender. */ - int32_t duration; + int32_t duration; /** * Optional. Video thumbnail. */ - PhotoSize::Ptr thumb; + PhotoSize::Ptr thumb; /** * Optional. Mime type of a file as defined by sender */ - std::string mimeType; + std::string mimeType; /** * Optional. File size. */ - int32_t fileSize; + int32_t fileSize; }; } |