summaryrefslogtreecommitdiff
path: root/src/EventHandler.cpp
diff options
context:
space:
mode:
authorOleg Morozenkov <m@oleg.rocks>2018-07-23 01:56:42 +0300
committerOleg Morozenkov <m@oleg.rocks>2018-07-23 01:56:42 +0300
commitd47ee877be5d1175bdc36f2d87881ddaf875a8e9 (patch)
tree7fd20cdc1236fe6b832ae980de12afd7071ebab9 /src/EventHandler.cpp
parentcea20d4078f2088dea0dd589f1cc9dd7ee22461b (diff)
Refactor http clients, fix webhook server, add more samples, change tabs to 4 spaces
Diffstat (limited to 'src/EventHandler.cpp')
-rw-r--r--src/EventHandler.cpp32
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);
}
}