diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-12-06 23:39:14 +0300 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-12-06 23:39:14 +0300 |
commit | e89d523a7ac895f9bb724f3fa504f49c978aa4df (patch) | |
tree | 6506007a111068c218eb63d329a56e31519c7379 /include/tgbot | |
parent | 6fd3160feba7dc1228221ff4c8626cad48406d06 (diff) |
Some fixes. Closes #9, #10
Diffstat (limited to 'include/tgbot')
-rw-r--r-- | include/tgbot/Api.h | 38 | ||||
-rw-r--r-- | include/tgbot/TgTypeParser.h | 5 | ||||
-rw-r--r-- | include/tgbot/net/HttpParser.h | 1 | ||||
-rw-r--r-- | include/tgbot/net/HttpServer.h | 2 | ||||
-rw-r--r-- | include/tgbot/types/Chat.h | 22 | ||||
-rw-r--r-- | include/tgbot/types/GenericChat.h | 49 | ||||
-rw-r--r-- | include/tgbot/types/GroupChat.h | 50 | ||||
-rw-r--r-- | include/tgbot/types/Message.h | 7 | ||||
-rw-r--r-- | include/tgbot/types/User.h | 9 |
9 files changed, 45 insertions, 138 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 0d32252..0f3c097 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -59,7 +59,7 @@ public: /** * Use this method to send text messages. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param text Text of the message to be sent. * @param disableWebPagePreview Optional. Disables link previews for links in this message. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. @@ -70,7 +70,7 @@ public: /** * Use this method to forward messages of any kind. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param fromChatId Unique identifier for the chat where the original message was sent — User or GroupChat id. * @param messageId Unique message identifier. * @return On success, the sent message is returned. @@ -79,7 +79,7 @@ public: /** * Use this method to send photos. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param photo Photo to send. * @param caption Optional. Photo caption. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. @@ -90,8 +90,8 @@ public: /** * Use this method to send photos. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. - * @param photoId Id of the photo that is already on the Telegram servers. + * @param chatId Unique identifier for the target chat. + * @param photo Photo to send. Id of the photo that is already on the Telegram servers. * @param caption Optional. Photo caption. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -101,7 +101,7 @@ public: /** * 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). - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param audio Audio to send. * @param duration Duration of sent audio in seconds. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. @@ -112,8 +112,8 @@ public: /** * 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). - * @param chatId Unique identifier for the message recipient — User or GroupChat id. - * @param audioId Id of the audio that is already on the Telegram servers. + * @param chatId Unique identifier for the target chat. + * @param audio Id of the audio that is already on the Telegram servers. * @param duration Duration of sent audio in seconds. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -123,7 +123,7 @@ public: /** * Use this method to send general files. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param document Document to send. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -133,8 +133,8 @@ public: /** * Use this method to send general files. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. - * @param documentId Id of the document that is already on the Telegram servers. + * @param chatId Unique identifier for the target chat. + * @param document Id of the document that is already on the Telegram servers. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -143,7 +143,7 @@ public: /** * Use this method to send .webp stickers. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param sticker Sticker to send. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -153,8 +153,8 @@ public: /** * Use this method to send .webp stickers. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. - * @param stickerId Id of the sticker that is already on the Telegram servers. + * @param chatId Unique identifier for the target chat. + * @param sticker Id of the sticker that is already on the Telegram servers. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -163,7 +163,7 @@ public: /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param video Video to send. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -173,8 +173,8 @@ public: /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). - * @param chatId Unique identifier for the message recipient — User or GroupChat id. - * @param videoId Id of the video that is already on the Telegram servers. + * @param chatId Unique identifier for the target chat. + * @param video Id of the video that is already on the Telegram servers. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. * @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. @@ -183,7 +183,7 @@ public: /** * Use this method to send point on the map. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @param latitude Latitude of location. * @param longitude Longitude of location. * @param replyToMessageId Optional. If the message is a reply, ID of the original message. @@ -196,7 +196,7 @@ public: * 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). * Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot. * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. - * @param chatId Unique identifier for the message recipient — User or GroupChat id. + * @param chatId Unique identifier for the target chat. * @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; diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 2da9685..670e35e 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -30,7 +30,6 @@ #include "tgbot/types/User.h" #include "tgbot/types/Chat.h" -#include "tgbot/types/GroupChat.h" #include "tgbot/types/Message.h" #include "tgbot/types/PhotoSize.h" #include "tgbot/types/Audio.h" @@ -63,8 +62,6 @@ 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; - 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; @@ -91,8 +88,6 @@ public: 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; diff --git a/include/tgbot/net/HttpParser.h b/include/tgbot/net/HttpParser.h index 83068fb..ec4c077 100644 --- a/include/tgbot/net/HttpParser.h +++ b/include/tgbot/net/HttpParser.h @@ -25,6 +25,7 @@ #include <string> #include <map> +#include <vector> #include "tgbot/net/Url.h" #include "tgbot/net/HttpReqArg.h" diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h index 888c0a8..164bd2b 100644 --- a/include/tgbot/net/HttpServer.h +++ b/include/tgbot/net/HttpServer.h @@ -80,7 +80,7 @@ protected: data.reserve(10240); socket->async_receive(data, [this]() { std::map<std::string, std::string> headers; - std::string body = HttpParser::parseResponse(data, headers); + std::string body = HttpParser::getInstance().parseResponse(data, headers); socket->async_send(_handler(body, headers)); }); } diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h index d05155c..9a109e7 100644 --- a/include/tgbot/types/Chat.h +++ b/include/tgbot/types/Chat.h @@ -26,25 +26,33 @@ #include <string> #include <memory> -#include "tgbot/types/GenericChat.h" - namespace TgBot { /** * This object represents a Telegram Chat * @ingroup types */ -class Chat : public GenericChat { +class Chat { public: typedef std::shared_ptr<Chat> Ptr; /** - * Type of chat : can be either - * "private", "group", "supergroup, - * or "channel" + * Enum of possible types of a chat. + */ + enum class Type { + Private, Group, Supergroup, Channel + }; + + /** + * Unique identifier for this chat, not exceeding 1e13 by absolute value + */ + int64_t id; + + /** + * Type of chat: can be either "private", "group", "supergroup, or "channel". */ - std::string type; + Type type; /** * Optional. Title for channels and group chat diff --git a/include/tgbot/types/GenericChat.h b/include/tgbot/types/GenericChat.h deleted file mode 100644 index 2d91281..0000000 --- a/include/tgbot/types/GenericChat.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2015 Oleg Morozenkov - * - * 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_CPP_GENERICCHAT_H -#define TGBOT_CPP_GENERICCHAT_H - -#include <memory> - -namespace TgBot { - -/** - * This abstract class is base of everything to which you can send a message. - * @ingroup types - */ -class GenericChat { - -public: - typedef std::shared_ptr<GenericChat> Ptr; - - virtual ~GenericChat() { } - - /** - * Unique identifier for this user, bot or group chat - */ - int32_t id; -}; - -} - -#endif //TGBOT_CPP_GENERICCHAT_H diff --git a/include/tgbot/types/GroupChat.h b/include/tgbot/types/GroupChat.h deleted file mode 100644 index fedb7f0..0000000 --- a/include/tgbot/types/GroupChat.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2015 Oleg Morozenkov - * - * 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_CPP_GROUPCHAT_H -#define TGBOT_CPP_GROUPCHAT_H - -#include <string> -#include <memory> - -#include "tgbot/types/GenericChat.h" - -namespace TgBot { - -/** - * This object represents a group chat. - * @ingroup types - */ -class GroupChat : public GenericChat { - -public: - typedef std::shared_ptr<GroupChat> Ptr; - - /** - * Group name. - */ - std::string title; -}; - -} - -#endif //TGBOT_CPP_GROUPCHAT_H diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index 4185052..daedf03 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -29,7 +29,6 @@ #include "tgbot/types/Chat.h" #include "tgbot/types/User.h" -#include "tgbot/types/GenericChat.h" #include "tgbot/types/Message.h" #include "tgbot/types/Audio.h" #include "tgbot/types/Document.h" @@ -56,7 +55,7 @@ public: int32_t messageId; /** - * Sender. + * Optional. Sender, can be empty for messages sent to channels. */ User::Ptr from; @@ -66,9 +65,9 @@ public: int32_t date; /** - * Chat. + * Conversation the message belongs to. */ - Chat::Ptr chat; + Chat::Ptr chat; /** * Optional. For forwarded messages, sender of the original message. diff --git a/include/tgbot/types/User.h b/include/tgbot/types/User.h index 99c7d12..420d355 100644 --- a/include/tgbot/types/User.h +++ b/include/tgbot/types/User.h @@ -26,20 +26,23 @@ #include <string> #include <memory> -#include "tgbot/types/GenericChat.h" - namespace TgBot { /** * This object represents a Telegram user or bot. * @ingroup types */ -class User : public GenericChat { +class User { public: typedef std::shared_ptr<User> Ptr; /** + * Unique identifier for this user or bot. + */ + int32_t id; + + /** * User‘s or bot’s first name. */ std::string firstName; |