summaryrefslogtreecommitdiff
path: root/include/tgbot/EventBroadcaster.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/EventBroadcaster.h
parent67a543eb596b68a166d7f790ea27d5d4e70e10b7 (diff)
Add new types and new event broadcaster for support the inline mode.
Diffstat (limited to 'include/tgbot/EventBroadcaster.h')
-rw-r--r--include/tgbot/EventBroadcaster.h44
1 files changed, 35 insertions, 9 deletions
diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h
index 3ec8865..d97dbbb 100644
--- a/include/tgbot/EventBroadcaster.h
+++ b/include/tgbot/EventBroadcaster.h
@@ -29,6 +29,8 @@
#include <map>
#include "tgbot/types/Message.h"
+#include "tgbot/types/InlineQuery.h"
+#include "tgbot/types/ChosenInlineResult.h"
namespace TgBot {
@@ -44,6 +46,8 @@ friend EventHandler;
public:
typedef std::function<void (const Message::Ptr&)> MessageListener;
+ typedef std::function<void (const InlineQuery::Ptr&)> InlineQueryListener;
+ typedef std::function<void (const ChosenInlineResult::Ptr&)> ChosenInlineResultListener;
/**
* Registers listener which receives all messages which the bot can ever receive.
@@ -78,13 +82,29 @@ public:
_onNonCommandMessageListeners.push_back(listener);
}
+ inline void onInlineQuery(const InlineQueryListener& listener) {
+ _onInlineQueryListeners.push_back(listener);
+ }
+
+ inline void onChosenInlineResult(const ChosenInlineResultListener& listener){
+ _onChosenInlineResultListeners.push_back(listener);
+ }
+
private:
- inline void broadcastAnyMessage(const Message::Ptr& message) const {
- for (const MessageListener& item : _onAnyMessageListeners) {
- item(message);
+ template<typename ListenerType, typename ObjectType>
+ inline void broadcast(const std::vector<ListenerType>& listeners, const ObjectType& object) const {
+ if (!object)
+ return;
+
+ for (const ListenerType& item : listeners) {
+ item(object);
}
}
+ inline void broadcastAnyMessage(const Message::Ptr& message) const {
+ broadcast<MessageListener, Message::Ptr>(_onAnyMessageListeners, message);
+ }
+
inline bool broadcastCommand(const std::string command, const Message::Ptr& message) const {
std::map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command);
if (iter == _onCommandListeners.end()) {
@@ -95,21 +115,27 @@ private:
}
inline void broadcastUnknownCommand(const Message::Ptr& message) const {
- for (const MessageListener& item : _onUnknownCommandListeners) {
- item(message);
- }
+ broadcast<MessageListener, Message::Ptr>(_onUnknownCommandListeners, message);
}
inline void broadcastNonCommandMessage(const Message::Ptr& message) const {
- for (const MessageListener& item : _onNonCommandMessageListeners) {
- item(message);
- }
+ broadcast<MessageListener, Message::Ptr>(_onNonCommandMessageListeners, message);
+ }
+
+ inline void broadcastInlineQuery(const InlineQuery::Ptr& query) const {
+ broadcast<InlineQueryListener, InlineQuery::Ptr>(_onInlineQueryListeners, query);
+ }
+
+ inline void broadcastChosenInlineResult(const ChosenInlineResult::Ptr& result) const {
+ broadcast<ChosenInlineResultListener, ChosenInlineResult::Ptr>(_onChosenInlineResultListeners, result);
}
std::vector<MessageListener> _onAnyMessageListeners;
std::map<std::string, MessageListener> _onCommandListeners;
std::vector<MessageListener> _onUnknownCommandListeners;
std::vector<MessageListener> _onNonCommandMessageListeners;
+ std::vector<InlineQueryListener> _onInlineQueryListeners;
+ std::vector<ChosenInlineResultListener> _onChosenInlineResultListeners;
};
}