From 46e71e2f509eb38166fafcc69931117f0f9b7798 Mon Sep 17 00:00:00 2001 From: Robby Date: Fri, 20 Apr 2018 16:28:28 +0200 Subject: Optionally do not notify users if their messages are blocked by certain modules (#1134). Closes #711. --- docs/conf/modules.conf.example | 19 ++++++++++++++----- src/modules/m_chanfilter.cpp | 10 +++++++++- src/modules/m_filter.cpp | 27 ++++++++++++++++++++------- src/modules/m_muteban.cpp | 7 +++++++ 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index d4b254134..da72775e9 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -402,7 +402,10 @@ # his/her message is blocked. # # If maxlen is set then it defines the maximum length of a filter entry. -# +# +# If notifyuser is set to no, the user will not be notified when +# his/her message is blocked. +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Channel history module: Displays the last 'X' lines of chat to a user @@ -785,14 +788,16 @@ # stdlib - stdlib regexps, provided via regex_stdlib, see comment # # at the tag for info on availability. # # # -# # +# If notifyuser is set to no, the user will not be notified when # +# his/her message is blocked. # +# +# # +# Your choice of regex engine must match on all servers network-wide. # # # -# Your choice of regex engine must match on all servers network-wide. -# # To learn more about the configuration of this module, read # # examples/filter.conf.example, which covers the various types of # # filters and shows how to add exemptions. # -# +# # #-#-#-#-#-#-#-#-#-#-#- FILTER CONFIGURATION -#-#-#-#-#-#-#-#-#-#-#-# # # # Optional - If you specify to use the filter module, then # @@ -1536,6 +1541,10 @@ # Muteban: Implements extended ban 'm', which stops anyone matching # a mask like +b m:nick!user@host from speaking on channel. # +# +# If notifyuser is set to no, the user will not be notified when +# his/her message is blocked. +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Random quote module: Provides a random quote on connect. diff --git a/src/modules/m_chanfilter.cpp b/src/modules/m_chanfilter.cpp index ce2387004..55b6d3d2f 100644 --- a/src/modules/m_chanfilter.cpp +++ b/src/modules/m_chanfilter.cpp @@ -46,7 +46,7 @@ class ChanFilter : public ListModeBase bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE { - if (word.length() > maxlen) + if (word.length() > maxlen) { user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Word is too long for the spamfilter list")); return false; @@ -76,6 +76,7 @@ class ModuleChanFilter : public Module CheckExemption::EventProvider exemptionprov; ChanFilter cf; bool hidemask; + bool notifyuser; public: @@ -90,6 +91,7 @@ class ModuleChanFilter : public Module ConfigTag* tag = ServerInstance->Config->ConfValue("chanfilter"); hidemask = tag->getBool("hidemask"); cf.maxlen = tag->getUInt("maxlen", 35, 10, 100); + notifyuser = tag->getBool("notifyuser", true); cf.DoRehash(); } @@ -112,6 +114,12 @@ class ModuleChanFilter : public Module { if (InspIRCd::Match(details.text, i->mask)) { + if (!notifyuser) + { + details.echooriginal = true; + return MOD_RES_DENY; + } + if (hidemask) user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word)"); else diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index d3d3ef218..0d0b7ae60 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -166,6 +166,7 @@ class ModuleFilter : public Module, public ServerEventListener, public Stats::Ev typedef insp::flat_set ExemptTargetSet; bool initing; + bool notifyuser; RegexFactory* factory; void FreeFilters(); @@ -356,17 +357,27 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar if (f->action == FA_BLOCK) { ServerInstance->SNO->WriteGlobalSno('a', "FILTER: "+user->nick+" had their message filtered, target was "+target+": "+f->reason); - if (msgtarget.type == MessageTarget::TYPE_CHANNEL) - user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked and opers notified (%s)", f->reason.c_str())); + if (notifyuser) + { + if (msgtarget.type == MessageTarget::TYPE_CHANNEL) + user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked and opers notified (%s)", f->reason.c_str())); + else + user->WriteNotice("Your message to "+target+" was blocked and opers notified: "+f->reason); + } else - user->WriteNotice("Your message to "+target+" was blocked and opers notified: "+f->reason); + details.echooriginal = true; } else if (f->action == FA_SILENT) { - if (msgtarget.type == MessageTarget::TYPE_CHANNEL) - user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked (%s)", f->reason.c_str())); + if (notifyuser) + { + if (msgtarget.type == MessageTarget::TYPE_CHANNEL) + user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked (%s)", f->reason.c_str())); + else + user->WriteNotice("Your message to "+target+" was blocked: "+f->reason); + } else - user->WriteNotice("Your message to "+target+" was blocked: "+f->reason); + details.echooriginal = true; } else if (f->action == FA_KILL) { @@ -508,7 +519,9 @@ void ModuleFilter::ReadConfig(ConfigStatus& status) } } - std::string newrxengine = ServerInstance->Config->ConfValue("filteropts")->getString("engine"); + ConfigTag* tag = ServerInstance->Config->ConfValue("filteropts"); + std::string newrxengine = tag->getString("engine"); + notifyuser = tag->getBool("notifyuser", true); factory = RegexEngine ? (RegexEngine.operator->()) : NULL; diff --git a/src/modules/m_muteban.cpp b/src/modules/m_muteban.cpp index 045666f89..aebc00462 100644 --- a/src/modules/m_muteban.cpp +++ b/src/modules/m_muteban.cpp @@ -36,6 +36,13 @@ class ModuleQuietBan : public Module Channel* chan = target.Get(); if (chan->GetExtBanStatus(user, 'm') == MOD_RES_DENY && chan->GetPrefixValue(user) < VOICE_VALUE) { + bool notifyuser = ServerInstance->Config->ConfValue("muteban")->getBool("notifyuser", true); + if (!notifyuser) + { + details.echooriginal = true; + return MOD_RES_DENY; + } + user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're muted)"); return MOD_RES_DENY; } -- cgit v1.2.3