diff options
author | Florian Scheibner <flo.de@hotmail.de> | 2015-11-16 14:57:53 +0100 |
---|---|---|
committer | Florian Scheibner <flo.de@hotmail.de> | 2015-11-16 14:57:53 +0100 |
commit | 14a6f4867ec74fbacdd93e888fb13c28aa637419 (patch) | |
tree | e65011de5d63766d9320fedfa6a5b3f1a00330c5 | |
parent | 0f15affd95df70c74b8d9b29eb857146152d162e (diff) |
Fix command parsing with @
for example /help@bot didn't work before
-rw-r--r-- | include/tgbot/EventHandler.h | 16 |
1 files changed, 12 insertions, 4 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); } |