summaryrefslogtreecommitdiff
path: root/include/tgbot
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-20 16:47:03 +0200
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-20 16:47:03 +0200
commit39f1085f078865a6d3bc48a05b6ab923eb9ebcae (patch)
tree4f141d94537bebae60b0efbb7b21513086cb9087 /include/tgbot
parentf9e16bde59f57c3b6990c47e5082e3edeb527e4d (diff)
Add support for removing command listeners
Diffstat (limited to 'include/tgbot')
-rw-r--r--include/tgbot/EventBroadcaster.h25
1 files changed, 19 insertions, 6 deletions
diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h
index 44cad96..ebecf3b 100644
--- a/include/tgbot/EventBroadcaster.h
+++ b/include/tgbot/EventBroadcaster.h
@@ -43,21 +43,30 @@ public:
/**
* @brief Registers listener which receives all messages with commands (messages with leading '/' char).
* @param commandName Command name which listener can handle.
- * @param listener Listener.
+ * @param listener Listener. Pass nullptr to remove listener of command
*/
inline void onCommand(const std::string& commandName, const MessageListener& listener) {
- _onCommandListeners[commandName] = listener;
+ if (listener) {
+ _onCommandListeners[commandName] = listener;
+ } else {
+ _onCommandListeners.erase(commandName);
+ }
}
/**
* @brief Registers listener which receives all messages with commands (messages with leading '/' char).
* @param commandsList Commands names which listener can handle.
- * @param listener Listener.
+ * @param listener Listener. Pass nullptr to remove listener of commands
*/
inline void onCommand(const std::initializer_list<std::string>& commandsList, const MessageListener& listener) {
- for (const auto& command : commandsList)
- {
- _onCommandListeners[command] = listener;
+ if (listener) {
+ for (const auto& command : commandsList) {
+ _onCommandListeners[command] = listener;
+ }
+ } else {
+ for (const auto& command : commandsList) {
+ _onCommandListeners.erase(command);
+ }
}
}
@@ -93,6 +102,10 @@ public:
_onChosenInlineResultListeners.push_back(listener);
}
+ /**
+ * @brief Registers listener which receives all the callback query.
+ * @param listener Listener.
+ */
inline void onCallbackQuery(const CallbackQueryListener& listener){
_onCallbackQueryListeners.push_back(listener);
}