2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9 * Copyright (C) 2005 Craig McLure <craig@chatspike.net>
10 * Copyright (C) 2005 Craig Edwards <craigedwards@brainbox.cc>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "modules/exemption.h"
33 ERR_ALREADYCHANFILTERED = 937,
34 ERR_NOSUCHCHANFILTER = 938,
35 ERR_CHANFILTERFULL = 939
38 /** Handles channel mode +g
40 class ChanFilter : public ListModeBase
45 ChanFilter(Module* Creator) : ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", 941, 940, false, "chanfilter") { }
47 bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
49 if (word.length() > maxlen)
51 user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Word is too long for the spamfilter list"));
58 void TellListTooLong(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
60 user->WriteNumeric(ERR_CHANFILTERFULL, chan->name, word, "Channel spamfilter list is full");
63 void TellAlreadyOnList(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
65 user->WriteNumeric(ERR_ALREADYCHANFILTERED, chan->name, InspIRCd::Format("The word %s is already on the spamfilter list", word.c_str()));
68 void TellNotSet(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
70 user->WriteNumeric(ERR_NOSUCHCHANFILTER, chan->name, "No such spamfilter word is set");
74 class ModuleChanFilter : public Module
76 CheckExemption::EventProvider exemptionprov;
89 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
91 ConfigTag* tag = ServerInstance->Config->ConfValue("chanfilter");
92 hidemask = tag->getBool("hidemask");
93 cf.maxlen = tag->getUInt("maxlen", 35, 10, 100);
94 notifyuser = tag->getBool("notifyuser", true);
98 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
100 if (target.type != MessageTarget::TYPE_CHANNEL)
101 return MOD_RES_PASSTHRU;
103 Channel* chan = target.Get<Channel>();
104 ModResult res = CheckExemption::Call(exemptionprov, user, chan, "filter");
106 if (!IS_LOCAL(user) || res == MOD_RES_ALLOW)
107 return MOD_RES_PASSTHRU;
109 ListModeBase::ModeList* list = cf.GetList(chan);
113 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); i++)
115 if (InspIRCd::Match(details.text, i->mask))
119 details.echo_original = true;
124 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word)");
126 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word: " + i->mask + ")");
132 return MOD_RES_PASSTHRU;
135 Version GetVersion() CXX11_OVERRIDE
137 // We don't send any link data if the length is 35 for compatibility with the 2.0 branch.
138 std::string maxfilterlen;
140 maxfilterlen.assign(ConvToStr(cf.maxlen));
142 return Version("Provides channel-specific censor lists (like mode +G but varies from channel to channel)", VF_VENDOR, maxfilterlen);
146 MODULE_INIT(ModuleChanFilter)