diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-11-16 19:56:39 +0300 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-11-16 19:56:39 +0300 |
commit | c0ecf548e9643102ae80e44d3cff59b0ed2a539b (patch) | |
tree | e65011de5d63766d9320fedfa6a5b3f1a00330c5 | |
parent | 91574f7b7f28e5c7c03c2af5507d7dff4fa31fed (diff) | |
parent | 14a6f4867ec74fbacdd93e888fb13c28aa637419 (diff) |
Merge pull request #7 from flode/master
Fix hide keyboard and command parsing
-rw-r--r-- | include/tgbot/EventHandler.h | 16 | ||||
-rw-r--r-- | include/tgbot/types/ForceReply.h | 2 | ||||
-rw-r--r-- | include/tgbot/types/ReplyKeyboardHide.h | 2 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 2 |
4 files changed, 16 insertions, 6 deletions
diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index e4fac7a..bb277a8 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -38,13 +38,21 @@ public: inline void handleUpdate(const Update::Ptr& update) const { _broadcaster->broadcastAnyMessage(update->message); if (StringTools::startsWith(update->message->text, "/")) { + unsigned long splitPosition; unsigned long spacePosition = update->message->text.find(' '); - std::string command; - if (spacePosition != update->message->text.npos) { - command = update->message->text.substr(1, spacePosition - 1); + unsigned long atSymbolPosition = update->message->text.find('@'); + if (spacePosition == update->message->text.npos) { + if (atSymbolPosition == update->message->text.npos) { + splitPosition = update->message->text.size(); + } else { + splitPosition = atSymbolPosition; + } + } else if (atSymbolPosition == update->message->text.npos) { + splitPosition = spacePosition; } else { - command = update->message->text.substr(1, update->message->text.size() - 1); + splitPosition = std::min(spacePosition, atSymbolPosition); } + std::string command = update->message->text.substr(1, splitPosition - 1); if (!_broadcaster->broadcastCommand(command, update->message)) { _broadcaster->broadcastUnknownCommand(update->message); } diff --git a/include/tgbot/types/ForceReply.h b/include/tgbot/types/ForceReply.h index f46197a..8a946f8 100644 --- a/include/tgbot/types/ForceReply.h +++ b/include/tgbot/types/ForceReply.h @@ -50,7 +50,7 @@ public: /** * 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; + bool selective = false; }; } diff --git a/include/tgbot/types/ReplyKeyboardHide.h b/include/tgbot/types/ReplyKeyboardHide.h index e4c4b20..acb0e5c 100644 --- a/include/tgbot/types/ReplyKeyboardHide.h +++ b/include/tgbot/types/ReplyKeyboardHide.h @@ -47,7 +47,7 @@ public: * 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 = false; }; } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 141aebd..6586ec6 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -404,6 +404,7 @@ std::string TgTypeParser::parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& o } string result; result += '{'; + appendToJson(result, "hide_keyboard", object->hideKeyboard); appendToJson(result, "selective", object->selective); result.erase(result.length() - 1); result += '}'; @@ -422,6 +423,7 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const { } string result; result += '{'; + appendToJson(result, "force_reply", object->forceReply); appendToJson(result, "selective", object->selective); result.erase(result.length() - 1); result += '}'; |