diff options
author | Florian Scheibner <flo.de@hotmail.de> | 2015-11-12 14:28:12 +0100 |
---|---|---|
committer | Florian Scheibner <flo.de@hotmail.de> | 2015-11-12 14:28:12 +0100 |
commit | 61cd5d3c264fd497af4df4e114d67dc7ead16a58 (patch) | |
tree | f586d2c68699a68b33410f8bd1a004e621342e5f /include | |
parent | 4c34c9623735cdd7d11c333e54ad8723abb1be8b (diff) |
Parse commands correctly
previously the last letter of a command was removed when a space was present
e.g. "/add hello" was parsed as command = "ad"
Diffstat (limited to 'include')
-rw-r--r-- | include/tgbot/EventHandler.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index 1ec2cbe..e4fac7a 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -38,7 +38,13 @@ public: 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); + unsigned long spacePosition = update->message->text.find(' '); + std::string command; + if (spacePosition != update->message->text.npos) { + command = update->message->text.substr(1, spacePosition - 1); + } else { + command = update->message->text.substr(1, update->message->text.size() - 1); + } if (!_broadcaster->broadcastCommand(command, update->message)) { _broadcaster->broadcastUnknownCommand(update->message); } |