From db077ea78a5d9030f80cde3ed8761f52e03ba63e Mon Sep 17 00:00:00 2001 From: John Reese Date: Thu, 13 Jan 2011 22:00:24 -0500 Subject: [PATCH] Implemented client_count condition Config option client_count_less_than (uint) determines if notifications will be sent based on how many IRC clients are connected to ZNC. A value of zero disables this condition (always met), otherwise only sends notifications if the number of connected clients is less than the configured threshold. Personal use case is client_count_less_than = 2, in that I always have Irssi connected from my server, but if also connected from my phone, I don't want duplicate notifications. --- notifo.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/notifo.cpp b/notifo.cpp index 6dbb975..d5b8eb9 100644 --- a/notifo.cpp +++ b/notifo.cpp @@ -71,6 +71,9 @@ class CNotifoMod : public CModule // Notifo user account and secret options["username"] = ""; options["secret"] = ""; + + // Notification conditions + options["client_count_less_than"] = "0"; } virtual ~CNotifoMod() {} @@ -139,6 +142,27 @@ class CNotifoMod : public CModule #endif } + /** + * Check how many clients are connected to ZNC. + * + * @return Number of connected clients + */ + unsigned int client_count() + { + return user->GetClients().size(); + } + + /** + * Check if the client_count condition is met. + * + * @return True if client_count is less than client_count_less_than or if client_count_less_than is zero + */ + bool client_count_less_than() + { + unsigned int value = options["client_count_less_than"].ToUInt(); + return value == 0 || client_count() < value; + } + /** * Determine if the given message matches any highlight rules. * @@ -167,7 +191,17 @@ class CNotifoMod : public CModule */ bool notify_channel(const CNick& nick, const CChan& channel, const CString& message) { - return highlight(message); + if (!highlight(message)) + { + return false; + } + + if (!client_count_less_than()) + { + return false; + } + + return true; } /**