diff options
author | Oleg Morozenkov <m@oleg.rocks> | 2018-07-23 02:35:50 +0300 |
---|---|---|
committer | Oleg Morozenkov <m@oleg.rocks> | 2018-07-23 02:35:50 +0300 |
commit | 98b8b7e4338b71ee46c4301b0bf2ae667be9a99d (patch) | |
tree | 32f8b0d32048b2d83b57773c0efa3db9600b8701 /src/EventHandler.cpp | |
parent | 1dd3affe306793d2129f121c11e43c45ae8690da (diff) | |
parent | 167e3e7607e43a0f06c7f87ced94f481e6525b0e (diff) |
Merge branch 'master' into nicholascw-master
Diffstat (limited to 'src/EventHandler.cpp')
-rw-r--r-- | src/EventHandler.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index ba0ce54..d85e0c3 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -5,47 +5,49 @@ #include "tgbot/EventHandler.h" #include <algorithm> +using namespace std; + namespace TgBot { -void EventHandler::handleUpdate(const Update::Ptr update) const { +void EventHandler::handleUpdate(Update::Ptr update) const { if (update->inlineQuery != nullptr) { - _broadcaster->broadcastInlineQuery(update->inlineQuery); + _broadcaster.broadcastInlineQuery(update->inlineQuery); } if (update->chosenInlineResult != nullptr) { - _broadcaster->broadcastChosenInlineResult(update->chosenInlineResult); + _broadcaster.broadcastChosenInlineResult(update->chosenInlineResult); } if (update->callbackQuery != nullptr) { - _broadcaster->broadcastCallbackQuery(update->callbackQuery); + _broadcaster.broadcastCallbackQuery(update->callbackQuery); } if (update->message != nullptr) { handleMessage(update->message); } } -void EventHandler::handleMessage(const Message::Ptr message) const { - _broadcaster->broadcastAnyMessage(message); +void EventHandler::handleMessage(Message::Ptr message) const { + _broadcaster.broadcastAnyMessage(message); if (StringTools::startsWith(message->text, "/")) { - uint16_t splitPosition; - uint16_t spacePosition = message->text.find(' '); - uint16_t atSymbolPosition = message->text.find('@'); - if (spacePosition == message->text.npos) { - if (atSymbolPosition == message->text.npos) { + size_t splitPosition; + size_t spacePosition = message->text.find(' '); + size_t atSymbolPosition = message->text.find('@'); + if (spacePosition == string::npos) { + if (atSymbolPosition == string::npos) { splitPosition = message->text.size(); } else { splitPosition = atSymbolPosition; } - } else if (atSymbolPosition == message->text.npos) { + } else if (atSymbolPosition == string::npos) { splitPosition = spacePosition; } else { splitPosition = std::min(spacePosition, atSymbolPosition); } std::string command = message->text.substr(1, splitPosition - 1); - if (!_broadcaster->broadcastCommand(command, message)) { - _broadcaster->broadcastUnknownCommand(message); + if (!_broadcaster.broadcastCommand(command, message)) { + _broadcaster.broadcastUnknownCommand(message); } } else { - _broadcaster->broadcastNonCommandMessage(message); + _broadcaster.broadcastNonCommandMessage(message); } } |