Implemented replied condition, defaulted to yes

If set to "yes", notifications will only be sent if you have replied to the
channel or query window more recently than the last time a notification was
sent for that context.
This commit is contained in:
John Reese 2011-01-26 13:09:55 -05:00
parent e913ed4558
commit 5c5c198ab7
2 changed files with 29 additions and 2 deletions

View File

@ -177,6 +177,11 @@ Configuration
like "channelbot", "FooBot", or "Robot". Care must be used to not accidentally like "channelbot", "FooBot", or "Robot". Care must be used to not accidentally
blacklist legitimate nicks with wildcards. blacklist legitimate nicks with wildcards.
* `replied = "yes"`
If set to "yes", notifications will only be sent if you have replied to the channel or
query window more recently than the last time a notification was sent for that context.
### Notifications ### Notifications

View File

@ -48,6 +48,9 @@ class CNotifoMod : public CModule
// Time last notification was sent for a given context // Time last notification was sent for a given context
map <CString, unsigned int> last_notification_time; map <CString, unsigned int> last_notification_time;
// Time of last message by user to a given context
map <CString, unsigned int> last_reply_time;
// Time of last activity by user for a given context // Time of last activity by user for a given context
map <CString, unsigned int> last_active_time; map <CString, unsigned int> last_active_time;
@ -90,6 +93,7 @@ class CNotifoMod : public CModule
defaults["last_active"] = "180"; defaults["last_active"] = "180";
defaults["last_notification"] = "300"; defaults["last_notification"] = "300";
defaults["nick_blacklist"] = ""; defaults["nick_blacklist"] = "";
defaults["replied"] = "yes";
// Notification settings // Notification settings
defaults["message_length"] = "100"; defaults["message_length"] = "100";
@ -319,6 +323,18 @@ class CNotifoMod : public CModule
return true; return true;
} }
/**
* Check if the replied condition is met.
*
* @param context Channel or nick context
* @return True if last_reply_time > last_notification_time or if replied is not "yes"
*/
bool replied(const CString& context)
{
CString value = options["replied"].AsLower();
return value != "yes" || last_notification_time[context] < last_reply_time[context];
}
/** /**
* Determine when to notify the user of a channel message. * Determine when to notify the user of a channel message.
* *
@ -337,6 +353,7 @@ class CNotifoMod : public CModule
&& last_active(context) && last_active(context)
&& last_notification(context) && last_notification(context)
&& nick_blacklist(nick) && nick_blacklist(nick)
&& replied(context)
&& true; && true;
} }
@ -354,6 +371,7 @@ class CNotifoMod : public CModule
&& last_active(context) && last_active(context)
&& last_notification(context) && last_notification(context)
&& nick_blacklist(nick) && nick_blacklist(nick)
&& replied(context)
&& true; && true;
} }
@ -477,7 +495,7 @@ class CNotifoMod : public CModule
*/ */
EModRet OnUserMsg(CString& target, CString& message) EModRet OnUserMsg(CString& target, CString& message)
{ {
last_active_time[target] = idle_time = time(NULL); last_reply_time[target] = last_active_time[target] = idle_time = time(NULL);
return CONTINUE; return CONTINUE;
} }
@ -489,7 +507,7 @@ class CNotifoMod : public CModule
*/ */
EModRet OnUserAction(CString& target, CString& message) EModRet OnUserAction(CString& target, CString& message)
{ {
last_active_time[target] = idle_time = time(NULL); last_reply_time[target] = last_active_time[target] = idle_time = time(NULL);
return CONTINUE; return CONTINUE;
} }
@ -752,6 +770,10 @@ class CNotifoMod : public CModule
ago = now - last_notification_time[context]; ago = now - last_notification_time[context];
table.SetCell("Status", CString(ago) + " seconds"); table.SetCell("Status", CString(ago) + " seconds");
} }
table.AddRow();
table.SetCell("Condition", "replied");
table.SetCell("Status", replied(context) ? "yes" : "no");
} }
PutModule(table); PutModule(table);