diff --git a/README.md b/README.md index 852a25f..05db963 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,11 @@ Configuration like "channelbot", "FooBot", or "Robot". Care must be used to not accidentally 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 diff --git a/notifo.cpp b/notifo.cpp index 818e8c2..74ae46a 100644 --- a/notifo.cpp +++ b/notifo.cpp @@ -48,6 +48,9 @@ class CNotifoMod : public CModule // Time last notification was sent for a given context map last_notification_time; + // Time of last message by user to a given context + map last_reply_time; + // Time of last activity by user for a given context map last_active_time; @@ -90,6 +93,7 @@ class CNotifoMod : public CModule defaults["last_active"] = "180"; defaults["last_notification"] = "300"; defaults["nick_blacklist"] = ""; + defaults["replied"] = "yes"; // Notification settings defaults["message_length"] = "100"; @@ -319,6 +323,18 @@ class CNotifoMod : public CModule 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. * @@ -337,6 +353,7 @@ class CNotifoMod : public CModule && last_active(context) && last_notification(context) && nick_blacklist(nick) + && replied(context) && true; } @@ -354,6 +371,7 @@ class CNotifoMod : public CModule && last_active(context) && last_notification(context) && nick_blacklist(nick) + && replied(context) && true; } @@ -477,7 +495,7 @@ class CNotifoMod : public CModule */ 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; } @@ -489,7 +507,7 @@ class CNotifoMod : public CModule */ 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; } @@ -752,6 +770,10 @@ class CNotifoMod : public CModule ago = now - last_notification_time[context]; table.SetCell("Status", CString(ago) + " seconds"); } + + table.AddRow(); + table.SetCell("Condition", "replied"); + table.SetCell("Status", replied(context) ? "yes" : "no"); } PutModule(table);