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.
This commit is contained in:
John Reese 2011-01-18 11:12:35 -05:00
parent 6fb80cff1f
commit 16f28cb04a
2 changed files with 42 additions and 4 deletions

View File

@ -100,6 +100,17 @@ Configuration
query window separately, so a recent PM from Joe will not affect a notification sent query window separately, so a recent PM from Joe will not affect a notification sent
from channel #foo. 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 ### Notifications
@ -129,8 +140,6 @@ Roadmap
* 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.
* Nick blacklist: List of nicks to never send notifications from, e.g. channel bots.
### Settings ### Settings
* Customizable notification titles and message formats. * Customizable notification titles and message formats.

View File

@ -70,6 +70,7 @@ 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_notification"] = "300"; defaults["last_notification"] = "300";
@ -216,6 +217,30 @@ class CNotifoMod : public CModule
|| last_notification_time[context] + value < now; || 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. * Determine when to notify the user of a channel message.
* *
@ -229,7 +254,9 @@ class CNotifoMod : public CModule
return away_only() return away_only()
&& client_count_less_than() && client_count_less_than()
&& highlight(message) && 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) bool notify_pm(const CNick& nick)
{ {
return away_only() return away_only()
&& last_notification(nick.GetNick()); && last_notification(nick.GetNick())
&& nick_blacklist(nick)
&& true;
} }
protected: protected: