diff --git a/README.md b/README.md index 568e552..b35b924 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,31 @@ 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. +* `highlight = ""` + + Space-separated list of highlight strings to match against channel messages using + case-insensitive, wildcard matching. Strings will be compared in order they appear in the configuration value, and + the first string to match will end the search, meaning that earlier strings take priority + over later values. + + Individual strings may be prefixed with: + + * `-` (hypen) to negate the match, which makes the string act as a filter rather than + a search + + * `_` (underscore) to trigger a "whole-word" match, where it must be surrounded by + whitespace to match the value + + * `*` (asterisk) to match highlight strings that start with any of the above prefixes + + As an example, a highlight value of "-pinto car" will trigger notification on the + message "I like cars", but will prevent notifications for "My favorite car is the Pinto" + *and* "I like pinto beans". Conversely, a highlight value of "car -pinto" will trigger + notifications for the first two messages, and only prevent notification of the last one. + + As another example, a value of "_car" will trigger notification for the message "my car + is awesome", but will not match the message "I like cars". + * `idle = 0` Time in seconds since the last activity by the user on any channel or query window, diff --git a/notifo.cpp b/notifo.cpp index d2ba64d..818e8c2 100644 --- a/notifo.cpp +++ b/notifo.cpp @@ -85,6 +85,7 @@ class CNotifoMod : public CModule defaults["away_only"] = "no"; #endif defaults["client_count_less_than"] = "0"; + defaults["highlight"] = ""; defaults["idle"] = "0"; defaults["last_active"] = "180"; defaults["last_notification"] = "300"; @@ -212,6 +213,35 @@ class CNotifoMod : public CModule */ bool highlight(const CString& message) { + CString msg = " " + message.AsLower() + " "; + + VCString values; + options["highlight"].Split(" ", values, false); + + for (VCString::iterator i = values.begin(); i != values.end(); i++) + { + CString value = i->AsLower(); + char prefix = value[0]; + bool notify = true; + + if (prefix == '-') + { + notify = false; + value.LeftChomp(1); + } + else if (prefix == '_') + { + value = " " + value.LeftChomp_n(1) + " "; + } + + value = "*" + value + "*"; + + if (msg.WildCmp(value)) + { + return notify; + } + } + CNick nick = user->GetIRCNick(); if (message.find(nick.GetNick()) != string::npos)