Optionally do not notify users if their messages are blocked by certain modules (#1134).

Closes #711.
This commit is contained in:
Robby 2018-04-20 16:28:28 +02:00 committed by Peter Powell
parent 49c35af6af
commit 46e71e2f50
4 changed files with 50 additions and 13 deletions

View File

@ -402,7 +402,10 @@
# his/her message is blocked. # his/her message is blocked.
# #
# If maxlen is set then it defines the maximum length of a filter entry. # If maxlen is set then it defines the maximum length of a filter entry.
#<chanfilter hidemask="yes" maxlen="50"> #
# If notifyuser is set to no, the user will not be notified when
# his/her message is blocked.
#<chanfilter hidemask="yes" maxlen="50" notifyuser="yes">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Channel history module: Displays the last 'X' lines of chat to a user # 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 # # stdlib - stdlib regexps, provided via regex_stdlib, see comment #
# at the <module> tag for info on availability. # # at the <module> tag for info on availability. #
# # # #
#<filteropts engine="glob"> # # If notifyuser is set to no, the user will not be notified when #
# his/her message is blocked. #
#<filteropts engine="glob" notifyuser="yes">
# #
# 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 # # To learn more about the configuration of this module, read #
# examples/filter.conf.example, which covers the various types of # # examples/filter.conf.example, which covers the various types of #
# filters and shows how to add exemptions. # # filters and shows how to add exemptions. #
# # #
#-#-#-#-#-#-#-#-#-#-#- FILTER CONFIGURATION -#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#- FILTER CONFIGURATION -#-#-#-#-#-#-#-#-#-#-#-#
# # # #
# Optional - If you specify to use the filter module, then # # Optional - If you specify to use the filter module, then #
@ -1536,6 +1541,10 @@
# Muteban: Implements extended ban 'm', which stops anyone matching # Muteban: Implements extended ban 'm', which stops anyone matching
# a mask like +b m:nick!user@host from speaking on channel. # a mask like +b m:nick!user@host from speaking on channel.
#<module name="muteban"> #<module name="muteban">
#
# If notifyuser is set to no, the user will not be notified when
# his/her message is blocked.
#<muteban notifyuser="yes">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Random quote module: Provides a random quote on connect. # Random quote module: Provides a random quote on connect.

View File

@ -46,7 +46,7 @@ class ChanFilter : public ListModeBase
bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE 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")); user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Word is too long for the spamfilter list"));
return false; return false;
@ -76,6 +76,7 @@ class ModuleChanFilter : public Module
CheckExemption::EventProvider exemptionprov; CheckExemption::EventProvider exemptionprov;
ChanFilter cf; ChanFilter cf;
bool hidemask; bool hidemask;
bool notifyuser;
public: public:
@ -90,6 +91,7 @@ class ModuleChanFilter : public Module
ConfigTag* tag = ServerInstance->Config->ConfValue("chanfilter"); ConfigTag* tag = ServerInstance->Config->ConfValue("chanfilter");
hidemask = tag->getBool("hidemask"); hidemask = tag->getBool("hidemask");
cf.maxlen = tag->getUInt("maxlen", 35, 10, 100); cf.maxlen = tag->getUInt("maxlen", 35, 10, 100);
notifyuser = tag->getBool("notifyuser", true);
cf.DoRehash(); cf.DoRehash();
} }
@ -112,6 +114,12 @@ class ModuleChanFilter : public Module
{ {
if (InspIRCd::Match(details.text, i->mask)) if (InspIRCd::Match(details.text, i->mask))
{ {
if (!notifyuser)
{
details.echooriginal = true;
return MOD_RES_DENY;
}
if (hidemask) if (hidemask)
user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word)"); user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word)");
else else

View File

@ -166,6 +166,7 @@ class ModuleFilter : public Module, public ServerEventListener, public Stats::Ev
typedef insp::flat_set<std::string, irc::insensitive_swo> ExemptTargetSet; typedef insp::flat_set<std::string, irc::insensitive_swo> ExemptTargetSet;
bool initing; bool initing;
bool notifyuser;
RegexFactory* factory; RegexFactory* factory;
void FreeFilters(); void FreeFilters();
@ -356,17 +357,27 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar
if (f->action == FA_BLOCK) if (f->action == FA_BLOCK)
{ {
ServerInstance->SNO->WriteGlobalSno('a', "FILTER: "+user->nick+" had their message filtered, target was "+target+": "+f->reason); ServerInstance->SNO->WriteGlobalSno('a', "FILTER: "+user->nick+" had their message filtered, target was "+target+": "+f->reason);
if (msgtarget.type == MessageTarget::TYPE_CHANNEL) if (notifyuser)
user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked and opers notified (%s)", f->reason.c_str())); {
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 else
user->WriteNotice("Your message to "+target+" was blocked and opers notified: "+f->reason); details.echooriginal = true;
} }
else if (f->action == FA_SILENT) else if (f->action == FA_SILENT)
{ {
if (msgtarget.type == MessageTarget::TYPE_CHANNEL) if (notifyuser)
user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked (%s)", f->reason.c_str())); {
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 else
user->WriteNotice("Your message to "+target+" was blocked: "+f->reason); details.echooriginal = true;
} }
else if (f->action == FA_KILL) 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; factory = RegexEngine ? (RegexEngine.operator->()) : NULL;

View File

@ -36,6 +36,13 @@ class ModuleQuietBan : public Module
Channel* chan = target.Get<Channel>(); Channel* chan = target.Get<Channel>();
if (chan->GetExtBanStatus(user, 'm') == MOD_RES_DENY && chan->GetPrefixValue(user) < VOICE_VALUE) 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)"); user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're muted)");
return MOD_RES_DENY; return MOD_RES_DENY;
} }