From 16f28cb04a1681f430cac34750c6a8f9ea6c373f Mon Sep 17 00:00:00 2001 From: John Reese Date: Tue, 18 Jan 2011 11:12:35 -0500 Subject: [PATCH] Implemented nick_blacklist condition Space-separated list of nicks. Applies to both channel mentions and query windows. Notifications will only be sent for messages from nicks that are not present in this list, using a case-insensitive comparison. Note that wildcard patterns can be used to match multiple nicks with a single blacklist entry. For example, `set nick_blacklist *bot` will not send notifications from nicks like "channelbot", "FooBot", or "Robot". Care must be used to not accidentally blacklist legitimate nicks with wildcards. --- README.md | 13 +++++++++++-- notifo.cpp | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2d961f4..3c51a6a 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,17 @@ Configuration query window separately, so a recent PM from Joe will not affect a notification sent from channel #foo. +* `nick_blacklist = ""` + + Space-separated list of nicks. Applies to both channel mentions and query windows. + Notifications will only be sent for messages from nicks that are not present in this + list, using a case-insensitive comparison. + + Note that wildcard patterns can be used to match multiple nicks with a single blacklist + entry. For example, `set nick_blacklist *bot` will not send notifications from nicks + like "channelbot", "FooBot", or "Robot". Care must be used to not accidentally + blacklist legitimate nicks with wildcards. + ### Notifications @@ -129,8 +140,6 @@ Roadmap * Highlights: Strings to trigger a channel notification, in addition to the default highlight when your nick is mentioned. -* Nick blacklist: List of nicks to never send notifications from, e.g. channel bots. - ### Settings * Customizable notification titles and message formats. diff --git a/notifo.cpp b/notifo.cpp index 42fabab..dbbc2a5 100644 --- a/notifo.cpp +++ b/notifo.cpp @@ -70,6 +70,7 @@ class CNotifoMod : public CModule // Notification conditions defaults["away_only"] = "no"; + defaults["nick_blacklist"] = ""; defaults["client_count_less_than"] = "0"; defaults["last_notification"] = "300"; @@ -216,6 +217,30 @@ class CNotifoMod : public CModule || last_notification_time[context] + value < now; } + /** + * Check if the nick_blacklist condition is met. + * + * @param nick Nick that sent the message + * @return True if nick is not in the blacklist + */ + bool nick_blacklist(const CNick& nick) + { + VCString blacklist; + options["nick_blacklist"].Split(" ", blacklist, false); + + CString name = nick.GetNick().AsLower(); + + for (VCString::iterator i = blacklist.begin(); i != blacklist.end(); i++) + { + if (name.WildCmp(i->AsLower())) + { + return false; + } + } + + return true; + } + /** * Determine when to notify the user of a channel message. * @@ -229,7 +254,9 @@ class CNotifoMod : public CModule return away_only() && client_count_less_than() && highlight(message) - && last_notification(channel.GetName()); + && last_notification(channel.GetName()) + && nick_blacklist(nick) + && true; } /** @@ -241,7 +268,9 @@ class CNotifoMod : public CModule bool notify_pm(const CNick& nick) { return away_only() - && last_notification(nick.GetNick()); + && last_notification(nick.GetNick()) + && nick_blacklist(nick) + && true; } protected: