mirror of https://github.com/SeanOMik/znc-push.git
Implemented last_active condition
Time in seconds since the last message sent by the user on that channel or query window. Notifications will only be sent if the elapsed time is greater than this value. A value of 0 (zero) will disable this condition. Note that this condition keeps track of the last message sent to each channel and query window separately, so a recent PM to Joe will not affect a notification sent from channel #foo.
This commit is contained in:
parent
16f28cb04a
commit
c9cac29c0e
13
README.md
13
README.md
|
@ -90,6 +90,16 @@ Configuration
|
||||||
Notifications will only be sent if the number of connected IRC clients is less than this
|
Notifications will only be sent if the number of connected IRC clients is less than this
|
||||||
value. A value of 0 (zero) will disable this condition.
|
value. A value of 0 (zero) will disable this condition.
|
||||||
|
|
||||||
|
* `last_active = 180`
|
||||||
|
|
||||||
|
Time in seconds since the last message sent by the user on that channel or query window.
|
||||||
|
Notifications will only be sent if the elapsed time is greater than this value. A value
|
||||||
|
of 0 (zero) will disable this condition.
|
||||||
|
|
||||||
|
Note that this condition keeps track of the last message sent to each channel and query
|
||||||
|
window separately, so a recent PM to Joe will not affect a notification sent from
|
||||||
|
channel #foo.
|
||||||
|
|
||||||
* `last_notification = 300`
|
* `last_notification = 300`
|
||||||
|
|
||||||
Time in seconds since the last notification sent from that channel or query window.
|
Time in seconds since the last notification sent from that channel or query window.
|
||||||
|
@ -134,9 +144,6 @@ Roadmap
|
||||||
* User inactivity: How long, in seconds, since the last action made by user, in any
|
* User inactivity: How long, in seconds, since the last action made by user, in any
|
||||||
channel or query window.
|
channel or query window.
|
||||||
|
|
||||||
* Channel inactivity: How long, in seconds, since the last action made by the user in
|
|
||||||
the same channel or query window.
|
|
||||||
|
|
||||||
* Highlights: Strings to trigger a channel notification, in addition to the default
|
* Highlights: Strings to trigger a channel notification, in addition to the default
|
||||||
highlight when your nick is mentioned.
|
highlight when your nick is mentioned.
|
||||||
|
|
||||||
|
|
53
notifo.cpp
53
notifo.cpp
|
@ -43,6 +43,9 @@ class CNotifoMod : public CModule
|
||||||
// Time last notification was sent
|
// Time last notification was sent
|
||||||
map <CString, unsigned int> last_notification_time;
|
map <CString, unsigned int> last_notification_time;
|
||||||
|
|
||||||
|
// Time of last activity by user
|
||||||
|
map <CString, unsigned int> last_active_time;
|
||||||
|
|
||||||
// User object
|
// User object
|
||||||
CUser *user;
|
CUser *user;
|
||||||
|
|
||||||
|
@ -70,9 +73,10 @@ class CNotifoMod : public CModule
|
||||||
|
|
||||||
// Notification conditions
|
// Notification conditions
|
||||||
defaults["away_only"] = "no";
|
defaults["away_only"] = "no";
|
||||||
defaults["nick_blacklist"] = "";
|
|
||||||
defaults["client_count_less_than"] = "0";
|
defaults["client_count_less_than"] = "0";
|
||||||
|
defaults["last_active"] = "180";
|
||||||
defaults["last_notification"] = "300";
|
defaults["last_notification"] = "300";
|
||||||
|
defaults["nick_blacklist"] = "";
|
||||||
|
|
||||||
// Notification settings
|
// Notification settings
|
||||||
defaults["message_length"] = "100";
|
defaults["message_length"] = "100";
|
||||||
|
@ -202,6 +206,21 @@ class CNotifoMod : public CModule
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the last_active condition is met.
|
||||||
|
*
|
||||||
|
* @param context Channel or nick context
|
||||||
|
* @return True if last_active is zero or elapsed time is greater than last_active
|
||||||
|
*/
|
||||||
|
bool last_active(const CString& context)
|
||||||
|
{
|
||||||
|
unsigned int value = options["last_active"].ToUInt();
|
||||||
|
unsigned int now = time(NULL);
|
||||||
|
return value == 0
|
||||||
|
|| last_active_time.count(context) < 1
|
||||||
|
|| last_active_time[context] + value < now;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the last_notification condition is met.
|
* Check if the last_notification condition is met.
|
||||||
*
|
*
|
||||||
|
@ -251,10 +270,12 @@ class CNotifoMod : public CModule
|
||||||
*/
|
*/
|
||||||
bool notify_channel(const CNick& nick, const CChan& channel, const CString& message)
|
bool notify_channel(const CNick& nick, const CChan& channel, const CString& message)
|
||||||
{
|
{
|
||||||
|
CString context = channel.GetName();
|
||||||
return away_only()
|
return away_only()
|
||||||
&& client_count_less_than()
|
&& client_count_less_than()
|
||||||
&& highlight(message)
|
&& highlight(message)
|
||||||
&& last_notification(channel.GetName())
|
&& last_active(context)
|
||||||
|
&& last_notification(context)
|
||||||
&& nick_blacklist(nick)
|
&& nick_blacklist(nick)
|
||||||
&& true;
|
&& true;
|
||||||
}
|
}
|
||||||
|
@ -267,8 +288,10 @@ class CNotifoMod : public CModule
|
||||||
*/
|
*/
|
||||||
bool notify_pm(const CNick& nick)
|
bool notify_pm(const CNick& nick)
|
||||||
{
|
{
|
||||||
|
CString context = nick.GetNick();
|
||||||
return away_only()
|
return away_only()
|
||||||
&& last_notification(nick.GetNick())
|
&& last_active(context)
|
||||||
|
&& last_notification(context)
|
||||||
&& nick_blacklist(nick)
|
&& nick_blacklist(nick)
|
||||||
&& true;
|
&& true;
|
||||||
}
|
}
|
||||||
|
@ -385,6 +408,30 @@ class CNotifoMod : public CModule
|
||||||
return CONTINUE;
|
return CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a message sent by the user.
|
||||||
|
*
|
||||||
|
* @param target Target channel or nick
|
||||||
|
* @param message Message contents
|
||||||
|
*/
|
||||||
|
EModRet OnUserMsg(CString& target, CString& message)
|
||||||
|
{
|
||||||
|
last_active_time[target] = time(NULL);
|
||||||
|
return CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an action sent by the user.
|
||||||
|
*
|
||||||
|
* @param target Target channel or nick
|
||||||
|
* @param message Message contents
|
||||||
|
*/
|
||||||
|
EModRet OnUserAction(CString& target, CString& message)
|
||||||
|
{
|
||||||
|
last_active_time[target] = time(NULL);
|
||||||
|
return CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle direct commands to the *notifo virtual user.
|
* Handle direct commands to the *notifo virtual user.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue