m_filter Allow exemption of messages sent to nicks specified in <exemptfromfilter> tags

Issue #655
This commit is contained in:
Attila Molnar 2014-04-11 15:25:54 +02:00
parent 1453b889ef
commit 557c02839b
2 changed files with 28 additions and 1 deletions

View File

@ -59,3 +59,12 @@
# You may specify specific channels that are exempt from being filtered:
#<exemptfromfilter target="#opers">
#<exemptfromfilter target="#help">
# You can also exempt messages from being filtered if they are sent to
# specific nicks.
# Example that exempts all messages sent *to* NickServ:
#<exemptfromfilter target="NickServ">
# Note that messages *from* services are never subject to filtering;
# <exemptfromfilter> tags are only for exempting messages sent *to* the
# configured targets.

View File

@ -172,6 +172,9 @@ class ModuleFilter : public Module
// List of channel names excluded from filtering.
ExemptTargetSet exemptedchans;
// List of target nicknames excluded from filtering.
ExemptTargetSet exemptednicks;
ModuleFilter();
CullResult cull();
ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
@ -322,6 +325,10 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type
if (target_type == TYPE_USER)
{
User* t = (User*)dest;
// Check if the target nick is exempted, if yes, ignore this message
if (exemptednicks.count(t->nick))
return MOD_RES_PASSTHRU;
target = t->nick;
}
else if (target_type == TYPE_CHANNEL)
@ -444,6 +451,8 @@ void ModuleFilter::ReadConfig(ConfigStatus& status)
{
ConfigTagList tags = ServerInstance->Config->ConfTags("exemptfromfilter");
exemptedchans.clear();
exemptednicks.clear();
for (ConfigIter i = tags.first; i != tags.second; ++i)
{
ConfigTag* tag = i->second;
@ -451,7 +460,12 @@ void ModuleFilter::ReadConfig(ConfigStatus& status)
// If "target" is not found, try the old "channel" key to keep compatibility with 2.0 configs
const std::string target = tag->getString("target", tag->getString("channel"));
if (!target.empty())
exemptedchans.insert(target);
{
if (target[0] == '#')
exemptedchans.insert(target);
else
exemptednicks.insert(target);
}
}
std::string newrxengine = ServerInstance->Config->ConfValue("filteropts")->getString("engine");
@ -691,6 +705,10 @@ ModResult ModuleFilter::OnStats(char symbol, User* user, string_list &results)
{
results.push_back("223 "+user->nick+" :EXEMPT "+(*i));
}
for (ExemptTargetSet::const_iterator i = exemptednicks.begin(); i != exemptednicks.end(); ++i)
{
results.push_back("223 "+user->nick+" :EXEMPT "+(*i));
}
}
return MOD_RES_PASSTHRU;
}