summaryrefslogtreecommitdiff
path: root/include/tgbot/EventHandler.h
diff options
context:
space:
mode:
authorAndrea Giove <andreagiove@outlook.com>2016-03-27 11:16:28 +0200
committerAndrea Giove <andreagiove@outlook.com>2016-03-27 11:16:28 +0200
commitf889903cd7132ce39e81da15d2f335ac511b2e1f (patch)
tree8de30b3f819da6343effd80f9018028d784c6a40 /include/tgbot/EventHandler.h
parent67a543eb596b68a166d7f790ea27d5d4e70e10b7 (diff)
Add new types and new event broadcaster for support the inline mode.
Diffstat (limited to 'include/tgbot/EventHandler.h')
-rw-r--r--include/tgbot/EventHandler.h42
1 files changed, 26 insertions, 16 deletions
diff --git a/include/tgbot/EventHandler.h b/include/tgbot/EventHandler.h
index bb277a8..aee230a 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) {
- }
-
- inline void handleUpdate(const Update::Ptr& update) const {
+ inline void handleMessage(const Message::Ptr& message){
_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)
+ handleMessag(update->message);
}
private: