mirror of https://github.com/SeanOMik/znc-push.git
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.
This commit is contained in:
parent
7bcae40012
commit
db077ea78a
36
notifo.cpp
36
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue