diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2016-04-03 00:09:06 +0400 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2016-04-03 00:09:06 +0400 |
commit | b6fd8d8ff899240580c5973bd75d74c5167b8d3d (patch) | |
tree | b24d43cd2a13ba923de495961bf9a5e613ae683a /include/tgbot/EventHandler.h | |
parent | 2195ce0768fa8903633164c0c45060c412cd5670 (diff) | |
parent | b937e88dd43a7708f40af6a3c333046e3121a77a (diff) |
Merge pull request #19 from aadeg/master
Implementing inline mode BIS
Diffstat (limited to 'include/tgbot/EventHandler.h')
-rw-r--r-- | include/tgbot/EventHandler.h | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h index bb277a8..64f74cd 100644 --- a/include/tgbot/EventHandler.h +++ b/include/tgbot/EventHandler.h @@ -31,34 +31,44 @@ namespace TgBot { class EventHandler { -public: - explicit EventHandler(const EventBroadcaster* broadcaster) : _broadcaster(broadcaster) { - } + void handleMessage(const Message::Ptr& message) const { + _broadcaster->broadcastAnyMessage(message); - inline void handleUpdate(const Update::Ptr& update) const { - _broadcaster->broadcastAnyMessage(update->message); - if (StringTools::startsWith(update->message->text, "/")) { + if (StringTools::startsWith(message->text, "/")) { unsigned long splitPosition; - unsigned long spacePosition = update->message->text.find(' '); - unsigned long atSymbolPosition = update->message->text.find('@'); - if (spacePosition == update->message->text.npos) { - if (atSymbolPosition == update->message->text.npos) { - splitPosition = update->message->text.size(); + unsigned long spacePosition = message->text.find(' '); + unsigned long atSymbolPosition = message->text.find('@'); + if (spacePosition == message->text.npos) { + if (atSymbolPosition == message->text.npos) { + splitPosition = message->text.size(); } else { splitPosition = atSymbolPosition; } - } else if (atSymbolPosition == update->message->text.npos) { + } else if (atSymbolPosition == message->text.npos) { splitPosition = spacePosition; } else { 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); + std::string command = message->text.substr(1, splitPosition - 1); + if (!_broadcaster->broadcastCommand(command, message)) { + _broadcaster->broadcastUnknownCommand(message); } } else { - _broadcaster->broadcastNonCommandMessage(update->message); + _broadcaster->broadcastNonCommandMessage(message); } + }; + +public: + explicit EventHandler(const EventBroadcaster* broadcaster) : _broadcaster(broadcaster) { + } + + inline void handleUpdate(const Update::Ptr& update) const { + if (update->inlineQuery != NULL) + _broadcaster->broadcastInlineQuery(update->inlineQuery); + if (update->chosenInlineResult != NULL) + _broadcaster->broadcastChosenInlineResult(update->chosenInlineResult); + if (update->message != NULL) + handleMessage(update->message); } private: |