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:
John Reese 2011-01-18 12:59:46 -05:00
parent 16f28cb04a
commit c9cac29c0e
2 changed files with 60 additions and 6 deletions

View File

@ -90,6 +90,16 @@ Configuration
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.
* `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`
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
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
highlight when your nick is mentioned.

View File

@ -43,6 +43,9 @@ class CNotifoMod : public CModule
// Time last notification was sent
map <CString, unsigned int> last_notification_time;
// Time of last activity by user
map <CString, unsigned int> last_active_time;
// User object
CUser *user;
@ -70,9 +73,10 @@ class CNotifoMod : public CModule
// Notification conditions
defaults["away_only"] = "no";
defaults["nick_blacklist"] = "";
defaults["client_count_less_than"] = "0";
defaults["last_active"] = "180";
defaults["last_notification"] = "300";
defaults["nick_blacklist"] = "";
// Notification settings
defaults["message_length"] = "100";
@ -202,6 +206,21 @@ class CNotifoMod : public CModule
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.
*
@ -251,10 +270,12 @@ class CNotifoMod : public CModule
*/
bool notify_channel(const CNick& nick, const CChan& channel, const CString& message)
{
CString context = channel.GetName();
return away_only()
&& client_count_less_than()
&& highlight(message)
&& last_notification(channel.GetName())
&& last_active(context)
&& last_notification(context)
&& nick_blacklist(nick)
&& true;
}
@ -267,8 +288,10 @@ class CNotifoMod : public CModule
*/
bool notify_pm(const CNick& nick)
{
CString context = nick.GetNick();
return away_only()
&& last_notification(nick.GetNick())
&& last_active(context)
&& last_notification(context)
&& nick_blacklist(nick)
&& true;
}
@ -385,6 +408,30 @@ class CNotifoMod : public CModule
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.
*