1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
24 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
26 typedef std::vector<std::string> SpamList;
28 class ModuleChanFilter : public Module
39 Conf = new ConfigReader;
40 Srv->AddExtendedListMode('g');
41 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
44 virtual void On005Numeric(std::string &output)
46 std::stringstream line(output);
47 std::string temp1, temp2;
51 if (temp1.substr(0,10) == "CHANMODES=")
53 // append the chanmode to the end
54 temp1 = temp1.substr(10,temp1.length());
55 temp1 = "CHANMODES=g" + temp1;
57 temp2 = temp2 + temp1 + " ";
60 output = temp2.substr(0,temp2.length()-1);
63 virtual void OnUserPart(userrec* user, chanrec* channel)
65 // when the last user parts, delete the list
66 if (Srv->CountUsers(channel) == 1)
68 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
71 channel->Shrink("spam_list");
77 virtual void OnRehash()
80 Conf = new ConfigReader;
81 // re-read our config options on a rehash
82 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
85 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
87 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
90 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
92 if (strcasestr(text.c_str(),i->c_str()))
94 WriteServ(user->fd,"936 %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name);
102 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
104 if (target_type == TYPE_CHANNEL)
106 return ProcessMessages(user,(chanrec*)dest,text);
111 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
113 if (target_type == TYPE_CHANNEL)
115 return ProcessMessages(user,(chanrec*)dest,text);
120 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
122 if ((modechar == 'g') && (type == MT_CHANNEL))
124 chanrec* chan = (chanrec*)target;
125 std::string param = params[0];
129 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
132 spamlist = new SpamList;
133 chan->Extend("spam_list",(char*)spamlist);
135 if (spamlist->size() < MaxEntries)
137 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
141 WriteServ(user->fd,"937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,params[0].c_str());
145 spamlist->push_back(params[0]);
148 WriteServ(user->fd,"939 %s %s :Channel spamfilter list is full",user->nick, chan->name);
153 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
156 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
165 WriteServ(user->fd,"938 %s %s :No such spamfilter word is set",user->nick, chan->name);
173 virtual void OnSendList(userrec* user, chanrec* channel, char mode)
177 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
180 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
182 WriteServ(user->fd,"941 %s %s %s",user->nick, channel->name,i->c_str());
185 WriteServ(user->fd,"940 %s %s :End of channel spamfilter list",user->nick, channel->name);
189 virtual ~ModuleChanFilter()
195 virtual Version GetVersion()
197 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
200 virtual string_list OnChannelSync(chanrec* chan)
202 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
203 string_list commands;
206 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
208 commands.push_back("M "+std::string(chan->name)+" +g "+*i);
217 class ModuleChanFilterFactory : public ModuleFactory
220 ModuleChanFilterFactory()
224 ~ModuleChanFilterFactory()
228 virtual Module * CreateModule()
230 return new ModuleChanFilter;
236 extern "C" void * init_module( void )
238 return new ModuleChanFilterFactory;