From 84fae4ce9719129c6b4a948ab29b15de1dc57ea6 Mon Sep 17 00:00:00 2001 From: Roland Hieber Date: Wed, 27 Jun 2012 16:15:51 +0200 Subject: [PATCH] watch module: Don't handle multiple matching patterns for each target Keep track of the targets which have already been notified of a matching message, and do not notify them again if other patterns in the same message match also. For example, consider the following match patterns: 1) <*watch> /msg *watch ADD *!*@* *highlight *%nick%* 2) <*watch> /msg *watch ADD *!*@* *highlight *testuser* 3) <*watch> /msg *watch ADD *!*@* *testhilights *test* If %nick% ist something like "testuser123", all of the these patterns match the following message: hey testuser123, look at this: ... Without this patch, the watch module would generate two notify messages for target *highlight, and one notify message for target *testhilights. This is unneccessary because patterns 1 and 2 will result in generating the same notify message twice for target *highlight. By using a std::set, the implementation in this patch keeps track of which targets have already been notified and does not notify them more than once. --- modules/watch.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/watch.cpp b/modules/watch.cpp index 36283682..c7b536e8 100644 --- a/modules/watch.cpp +++ b/modules/watch.cpp @@ -10,8 +10,10 @@ #include #include #include +#include using std::list; +using std::set; class CWatchSource { public: @@ -286,15 +288,19 @@ public: private: void Process(const CNick& Nick, const CString& sMessage, const CString& sSource) { + set sHandledTargets; + for (list::iterator it = m_lsWatchers.begin(); it != m_lsWatchers.end(); ++it) { CWatchEntry& WatchEntry = *it; - if (WatchEntry.IsMatch(Nick, sMessage, sSource, m_pNetwork)) { + if (WatchEntry.IsMatch(Nick, sMessage, sSource, m_pNetwork) && + sHandledTargets.count(WatchEntry.GetTarget()) < 1) { if (m_pNetwork->IsUserAttached()) { m_pNetwork->PutUser(":" + WatchEntry.GetTarget() + "!watch@znc.in PRIVMSG " + m_pNetwork->GetCurNick() + " :" + sMessage); } else { m_Buffer.AddLine(":" + _NAMEDFMT(WatchEntry.GetTarget()) + "!watch@znc.in PRIVMSG {target} :{text}", sMessage); } + sHandledTargets.insert(WatchEntry.GetTarget()); } } }