diff options
author | Egor Pugin <egor.pugin@gmail.com> | 2020-03-14 17:34:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-14 17:34:07 +0300 |
commit | b3e84e58d471412b9d26e173b77c757d93d57b19 (patch) | |
tree | 5ad991beda3975e8d8237562724e20f30d169d40 /include | |
parent | 9afa9c4e97faa9a6d7e6089ec1f822047738fdec (diff) | |
parent | 64174491dac84c559db5c48ed850177fa3eb4da0 (diff) |
Merge pull request #133 from JellyBrick/master
Fix #127, #128 & Code quality improvements
Diffstat (limited to 'include')
-rw-r--r-- | include/tgbot/Api.h | 65 | ||||
-rw-r--r-- | include/tgbot/EventBroadcaster.h | 16 | ||||
-rw-r--r-- | include/tgbot/EventHandler.h | 4 | ||||
-rw-r--r-- | include/tgbot/TgException.h | 2 | ||||
-rw-r--r-- | include/tgbot/net/HttpParser.h | 2 | ||||
-rw-r--r-- | include/tgbot/net/TgLongPoll.h | 4 | ||||
-rw-r--r-- | include/tgbot/types/Poll.h | 6 | ||||
-rw-r--r-- | include/tgbot/types/PollOption.h | 2 |
8 files changed, 49 insertions, 52 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 9738596..ac37231 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -87,7 +87,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendPhoto(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> photo, const std::string& caption = "", std::int32_t replyToMessageId = 0, + Message::Ptr sendPhoto(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> photo, const std::string& caption = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -105,8 +105,8 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendAudio(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> audio, const std::string &caption = "", std::int32_t duration = 0, - const std::string& performer = "", const std::string& title = "", const boost::variant<InputFile::Ptr, std::string> thumb = "", std::int32_t replyToMessageId = 0, + Message::Ptr sendAudio(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> audio, const std::string &caption = "", std::int32_t duration = 0, + const std::string& performer = "", const std::string& title = "", boost::variant<InputFile::Ptr, std::string> thumb = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -121,7 +121,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendDocument(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> document, const boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string &caption = "", std::int32_t replyToMessageId = 0, + Message::Ptr sendDocument(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> document, boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string &caption = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -194,7 +194,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendSticker(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> sticker, std::int32_t replyToMessageId = 0, + Message::Ptr sendSticker(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> sticker, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** @@ -270,7 +270,7 @@ public: * @return On success, the sent message is returned. */ - Message::Ptr sendVideo(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming = false, std::int32_t duration = 0, std::int32_t width = 0, std::int32_t height = 0, const boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string& caption = "", + Message::Ptr sendVideo(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming = false, std::int32_t duration = 0, std::int32_t width = 0, std::int32_t height = 0, boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string& caption = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -291,7 +291,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent Message is returned. */ - Message::Ptr sendAnimation(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> animation, std::int32_t duration = 0, std::int32_t width = 0, std::int32_t height = 0, const boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string &caption = "", + Message::Ptr sendAnimation(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> animation, std::int32_t duration = 0, std::int32_t width = 0, std::int32_t height = 0, boost::variant<InputFile::Ptr, std::string> thumb = "", const std::string &caption = "", std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** * @brief Use this method to send video messages. On success, the sent Message is returned. @@ -305,8 +305,8 @@ public: * @param replyMarkup Additional interface options. A object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. * @return On success, the sent Message is returned. */ - Message::Ptr sendVideoNote(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> videoNote, std::int64_t replyToMessageId = 0, bool disableNotification = false, - std::int32_t duration = 0, std::int32_t length = 0, const boost::variant<InputFile::Ptr, std::string> thumb = "", GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; + Message::Ptr sendVideoNote(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> videoNote, std::int64_t replyToMessageId = 0, bool disableNotification = false, + std::int32_t duration = 0, std::int32_t length = 0, boost::variant<InputFile::Ptr, std::string> thumb = "", GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * @brief Use this method to send a group of photos or videos as an album. @@ -331,7 +331,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendVoice(std::int64_t chatId, const boost::variant<InputFile::Ptr, std::string> voice, const std::string& caption = "", int duration = 0, std::int32_t replyToMessageId = 0, + Message::Ptr sendVoice(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> voice, const std::string& caption = "", int duration = 0, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** @@ -560,7 +560,7 @@ public: * @return Message object on success, otherwise nullptr */ Message::Ptr editMessageReplyMarkup(std::int64_t chatId = 0, std::int32_t messageId = 0, const std::string& inlineMessageId = "", - const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; + GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * @brief Use this method to delete messages sent by bot (or by other users if bot is admin). @@ -787,29 +787,26 @@ public: std::string downloadFile(const std::string& filePath, const std::vector<HttpReqArg>& args = std::vector<HttpReqArg>()) const; /** - * @brief Use this method to send a poll. - * @param chatId Unique identifier for the target chat or username of the target channel. - * @param question Poll question, 1-255 characters. - * @param options List of answer options, 2-10 strings 1-100 characters each. - * @param disable_notification Optional. Sends the message silenty. - * @param reply_to_message_id Optional. If the message is a reply, ID of the original message. - * @param reply_markup 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 sendPoll(std::int64_t chatId, std::string question, std::vector<std::string> options, bool disable_notification=false, std::int32_t reply_to_message_id=0,GenericReply::Ptr reply_markup = std::make_shared<GenericReply>()) const; - - /** - * @brief Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.. - * @param chatId Unique identifier for the target chat or username of the target channel. - * @param question Poll question, 1-255 characters. - * @param options List of answer options, 2-10 strings 1-100 characters each. - * @param disable_notification Optional. Sends the message silenty. - * @param reply_to_message_id Optional. If the message is a reply, ID of the original message. - * @param reply_markup 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. - */ + * @brief Use this method to send a poll. + * @param chatId Unique identifier for the target chat or username of the target channel. + * @param question Poll question, 1-255 characters. + * @param options List of answer options, 2-10 strings 1-100 characters each. + * @param disableNotification Optional. Sends the message silenty. + * @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. + */ + Message::Ptr sendPoll(std::int64_t chatId, const std::string& question, const std::vector<std::string>& options, bool disableNotification = false, std::int32_t replyToMessageId = 0, GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; + + /** + * @brief Use this method to stop a poll which was sent by the bot. + * @param chatId Unique identifier for the target chat or username of the target channel. + * @param messageId Identifier of the original message with the poll. + * @param replyMarkup Optional. A JSON-serialized object for a new message inline keyboard. + * + * @return On success, the stopped Poll with the final results is returned. + */ Poll::Ptr stopPoll(std::int64_t chatId, std::int64_t messageId, InlineKeyboardMarkup::Ptr replyMarkup = std::make_shared<InlineKeyboardMarkup>()) const; diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h index 38d5be6..978a6fe 100644 --- a/include/tgbot/EventBroadcaster.h +++ b/include/tgbot/EventBroadcaster.h @@ -107,12 +107,12 @@ private: } } - inline void broadcastAnyMessage(const Message::Ptr message) const { + inline void broadcastAnyMessage(const Message::Ptr& message) const { broadcast<MessageListener, Message::Ptr>(_onAnyMessageListeners, message); } - inline bool broadcastCommand(const std::string command, const Message::Ptr message) const { - std::unordered_map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command); + inline bool broadcastCommand(const std::string& command, const Message::Ptr& message) const { + auto iter = _onCommandListeners.find(command); if (iter == _onCommandListeners.end()) { return false; } @@ -120,23 +120,23 @@ private: return true; } - inline void broadcastUnknownCommand(const Message::Ptr message) const { + inline void broadcastUnknownCommand(const Message::Ptr& message) const { broadcast<MessageListener, Message::Ptr>(_onUnknownCommandListeners, message); } - inline void broadcastNonCommandMessage(const Message::Ptr message) const { + inline void broadcastNonCommandMessage(const Message::Ptr& message) const { broadcast<MessageListener, Message::Ptr>(_onNonCommandMessageListeners, message); } - inline void broadcastInlineQuery(const InlineQuery::Ptr query) const { + inline void broadcastInlineQuery(const InlineQuery::Ptr& query) const { broadcast<InlineQueryListener, InlineQuery::Ptr>(_onInlineQueryListeners, query); } - inline void broadcastChosenInlineResult(const ChosenInlineResult::Ptr result) const { + inline void broadcastChosenInlineResult(const ChosenInlineResult::Ptr& result) const { broadcast<ChosenInlineResultListener, ChosenInlineResult::Ptr>(_onChosenInlineResultListeners, result); } - inline void broadcastCallbackQuery(const CallbackQuery::Ptr result) const { + inline void broadcastCallbackQuery(const CallbackQuery::Ptr& result) const { broadcast<CallbackQueryListener, CallbackQuery::Ptr>(_onCallbackQueryListeners, result); } diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index 4e77e33..3f92ca2 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -13,12 +13,12 @@ public: explicit EventHandler(const EventBroadcaster& broadcaster) : _broadcaster(broadcaster) { } - void handleUpdate(Update::Ptr update) const; + void handleUpdate(const Update::Ptr& update) const; private: const EventBroadcaster& _broadcaster; - void handleMessage(Message::Ptr message) const; + void handleMessage(const Message::Ptr& message) const; }; } diff --git a/include/tgbot/TgException.h b/include/tgbot/TgException.h index 47b11f2..e80711c 100644 --- a/include/tgbot/TgException.h +++ b/include/tgbot/TgException.h @@ -16,7 +16,7 @@ namespace TgBot { class TGBOT_API TgException : public std::runtime_error { public: - explicit TgException(const std::string description); + explicit TgException(const std::string& description); }; } diff --git a/include/tgbot/net/HttpParser.h b/include/tgbot/net/HttpParser.h index 3f1095b..fabeacf 100644 --- a/include/tgbot/net/HttpParser.h +++ b/include/tgbot/net/HttpParser.h @@ -14,7 +14,7 @@ class TGBOT_API HttpParser { public: std::string generateRequest(const Url& url, const std::vector<HttpReqArg>& args, bool isKeepAlive = false) const; - std::string generateMultipartFormData(const std::vector<HttpReqArg>& args, const std::string& bondary) const; + std::string generateMultipartFormData(const std::vector<HttpReqArg>& args, const std::string& boundary) const; std::string generateMultipartBoundary(const std::vector<HttpReqArg>& args) const; std::string generateWwwFormUrlencoded(const std::vector<HttpReqArg>& args) const; std::string generateResponse(const std::string& data, const std::string& mimeType, unsigned short statusCode, const std::string& statusStr, bool isKeepAlive) const; diff --git a/include/tgbot/net/TgLongPoll.h b/include/tgbot/net/TgLongPoll.h index b55338c..017c012 100644 --- a/include/tgbot/net/TgLongPoll.h +++ b/include/tgbot/net/TgLongPoll.h @@ -17,7 +17,7 @@ namespace TgBot { class TGBOT_API TgLongPoll { public: - TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t, std::int32_t, const std::shared_ptr<std::vector<std::string>>&); + TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t, std::int32_t, std::shared_ptr<std::vector<std::string>>); TgLongPoll(const Bot& bot, std::int32_t = 100, std::int32_t = 10, const std::shared_ptr<std::vector<std::string>>& = nullptr); /** @@ -31,7 +31,7 @@ private: std::int32_t _lastUpdateId = 0; std::int32_t _limit; std::int32_t _timeout; - std::shared_ptr<std::vector<std::string>> _allowupdates; + std::shared_ptr<std::vector<std::string>> _allowUpdates; }; } diff --git a/include/tgbot/types/Poll.h b/include/tgbot/types/Poll.h index e3b0bd9..c4781a8 100644 --- a/include/tgbot/types/Poll.h +++ b/include/tgbot/types/Poll.h @@ -25,17 +25,17 @@ namespace TgBot { /** * @brief Poll question, 1-255 characters. */ - std::string question; + std::string question; /** * @brief List of poll options. */ - PollOption::Ptr options; + std::vector<PollOption::Ptr> options; /** * @brief True, if the poll is closed. */ - bool is_closed; + bool isClosed; }; } diff --git a/include/tgbot/types/PollOption.h b/include/tgbot/types/PollOption.h index b487b35..864aaf5 100644 --- a/include/tgbot/types/PollOption.h +++ b/include/tgbot/types/PollOption.h @@ -21,7 +21,7 @@ public: /** * @brief Number of users that voted for this option. */ - std::int64_t voter_count; + std::int64_t voterCount; }; } |