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 inline void onCommand(
const std::initializer_list<std::string>& commandsList,
const MessageListener& listener) {
77 for (
const auto& command : commandsList)
79 _onCommandListeners[command] = listener;
88 _onUnknownCommandListeners.push_back(listener);
96 _onNonCommandMessageListeners.push_back(listener);
104 _onInlineQueryListeners.push_back(listener);
112 _onChosenInlineResultListeners.push_back(listener);
116 _onCallbackQueryListeners.push_back(listener);
120 template<
typename ListenerType,
typename ObjectType>
121 inline void broadcast(
const std::vector<ListenerType>& listeners,
const ObjectType
object)
const {
125 for (
const ListenerType& item : listeners) {
130 inline void broadcastAnyMessage(
const Message::Ptr message)
const {
131 broadcast<MessageListener, Message::Ptr>(_onAnyMessageListeners, message);
134 inline bool broadcastCommand(
const std::string command,
const Message::Ptr message)
const {
135 std::map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command);
136 if (iter == _onCommandListeners.end()) {
139 iter->second(message);
143 inline void broadcastUnknownCommand(
const Message::Ptr message)
const {
144 broadcast<MessageListener, Message::Ptr>(_onUnknownCommandListeners, message);
147 inline void broadcastNonCommandMessage(
const Message::Ptr message)
const {
148 broadcast<MessageListener, Message::Ptr>(_onNonCommandMessageListeners, message);
152 broadcast<InlineQueryListener, InlineQuery::Ptr>(_onInlineQueryListeners, query);
156 broadcast<ChosenInlineResultListener, ChosenInlineResult::Ptr>(_onChosenInlineResultListeners, result);
160 broadcast<CallbackQueryListener, CallbackQuery::Ptr>(_onCallbackQueryListeners, result);
163 std::vector<MessageListener> _onAnyMessageListeners;
164 std::map<std::string, MessageListener> _onCommandListeners;
165 std::vector<MessageListener> _onUnknownCommandListeners;
166 std::vector<MessageListener> _onNonCommandMessageListeners;
167 std::vector<InlineQueryListener> _onInlineQueryListeners;
168 std::vector<ChosenInlineResultListener> _onChosenInlineResultListeners;
169 std::vector<CallbackQueryListener> _onCallbackQueryListeners;
174 #endif //TGBOT_EVENTBROADCASTER_H void onAnyMessage(const MessageListener &listener)
std::shared_ptr< CallbackQuery > Ptr
std::function< void(const CallbackQuery::Ptr)> CallbackQueryListener
std::shared_ptr< Message > Ptr
std::shared_ptr< ChosenInlineResult > Ptr
void onInlineQuery(const InlineQueryListener &listener)
void onCallbackQuery(const CallbackQueryListener &listener)
std::function< void(const ChosenInlineResult::Ptr)> ChosenInlineResultListener
void onUnknownCommand(const MessageListener &listener)
void onCommand(const std::string &commandName, const MessageListener &listener)
std::function< void(const InlineQuery::Ptr)> InlineQueryListener
void onCommand(const std::initializer_list< std::string > &commandsList, const MessageListener &listener)
void onNonCommandMessage(const MessageListener &listener)
void onChosenInlineResult(const ChosenInlineResultListener &listener)
std::shared_ptr< InlineQuery > Ptr
std::function< void(const Message::Ptr)> MessageListener