23 #ifndef TGBOT_EVENTBROADCASTER_H 24 #define TGBOT_EVENTBROADCASTER_H 59 _onAnyMessageListeners.push_back(listener);
67 inline void onCommand(
const std::string& commandName,
const MessageListener& listener) {
68 _onCommandListeners[commandName] = listener;
76 _onUnknownCommandListeners.push_back(listener);
84 _onNonCommandMessageListeners.push_back(listener);
92 _onInlineQueryListeners.push_back(listener);
100 _onChosenInlineResultListeners.push_back(listener);
104 _onCallbackQueryListeners.push_back(listener);
108 template<
typename ListenerType,
typename ObjectType>
109 inline void broadcast(
const std::vector<ListenerType>& listeners,
const ObjectType&
object)
const {
113 for (
const ListenerType& item : listeners) {
118 inline void broadcastAnyMessage(
const Message::Ptr& message)
const {
119 broadcast<MessageListener, Message::Ptr>(_onAnyMessageListeners, message);
122 inline bool broadcastCommand(
const std::string command,
const Message::Ptr& message)
const {
123 std::map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command);
124 if (iter == _onCommandListeners.end()) {
127 iter->second(message);
131 inline void broadcastUnknownCommand(
const Message::Ptr& message)
const {
132 broadcast<MessageListener, Message::Ptr>(_onUnknownCommandListeners, message);
135 inline void broadcastNonCommandMessage(
const Message::Ptr& message)
const {
136 broadcast<MessageListener, Message::Ptr>(_onNonCommandMessageListeners, message);
140 broadcast<InlineQueryListener, InlineQuery::Ptr>(_onInlineQueryListeners, query);
144 broadcast<ChosenInlineResultListener, ChosenInlineResult::Ptr>(_onChosenInlineResultListeners, result);
148 broadcast<CallbackQueryListener, CallbackQuery::Ptr>(_onCallbackQueryListeners, result);
151 std::vector<MessageListener> _onAnyMessageListeners;
152 std::map<std::string, MessageListener> _onCommandListeners;
153 std::vector<MessageListener> _onUnknownCommandListeners;
154 std::vector<MessageListener> _onNonCommandMessageListeners;
155 std::vector<InlineQueryListener> _onInlineQueryListeners;
156 std::vector<ChosenInlineResultListener> _onChosenInlineResultListeners;
157 std::vector<CallbackQueryListener> _onCallbackQueryListeners;
162 #endif //TGBOT_EVENTBROADCASTER_H void onAnyMessage(const MessageListener &listener)
std::function< void(const Message::Ptr &)> MessageListener
std::shared_ptr< CallbackQuery > Ptr
std::shared_ptr< Message > Ptr
std::function< void(const CallbackQuery::Ptr &)> CallbackQueryListener
std::shared_ptr< ChosenInlineResult > Ptr
void onInlineQuery(const InlineQueryListener &listener)
std::function< void(const ChosenInlineResult::Ptr &)> ChosenInlineResultListener
void onCallbackQuery(const CallbackQueryListener &listener)
void onUnknownCommand(const MessageListener &listener)
std::function< void(const InlineQuery::Ptr &)> InlineQueryListener
void onCommand(const std::string &commandName, const MessageListener &listener)
void onNonCommandMessage(const MessageListener &listener)
void onChosenInlineResult(const ChosenInlineResultListener &listener)
std::shared_ptr< InlineQuery > Ptr