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 * ---------------------------------------------------
23 #include "helperfuncs.h"
25 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
27 typedef std::vector<std::string> SpamList;
29 class ModuleChanFilter : public Module
40 Conf = new ConfigReader;
41 Srv->AddExtendedListMode('g');
42 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
45 virtual void On005Numeric(std::string &output)
47 std::stringstream line(output);
48 std::string temp1, temp2;
52 if (temp1.substr(0,10) == "CHANMODES=")
54 // append the chanmode to the end
55 temp1 = temp1.substr(10,temp1.length());
56 temp1 = "CHANMODES=g" + temp1;
58 temp2 = temp2 + temp1 + " ";
61 output = temp2.substr(0,temp2.length()-1);
64 virtual void OnUserPart(userrec* user, chanrec* channel)
66 // when the last user parts, delete the list
67 if (Srv->CountUsers(channel) == 1)
69 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
72 channel->Shrink("spam_list");
78 virtual void OnRehash()
81 Conf = new ConfigReader;
82 // re-read our config options on a rehash
83 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
86 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
89 strlcpy(buffer,text.c_str(),MAXBUF);
90 for (int j = 0; j < strlen(buffer); j++)
91 buffer[j] = tolower(buffer[j]);
92 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
95 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
97 if (strstr(text.c_str(),i->c_str()))
99 WriteServ(user->fd,"936 %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name);
107 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
109 if (target_type == TYPE_CHANNEL)
111 return ProcessMessages(user,(chanrec*)dest,text);
116 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
118 if (target_type == TYPE_CHANNEL)
120 return ProcessMessages(user,(chanrec*)dest,text);
125 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
127 if ((modechar == 'g') && (type == MT_CHANNEL))
129 chanrec* chan = (chanrec*)target;
131 for (int j = 0; j < params[0].length(); j++)
132 params[0][j] = tolower(params[0][j]);
134 std::string param = params[0];
138 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
141 spamlist = new SpamList;
142 chan->Extend("spam_list",(char*)spamlist);
144 if (spamlist->size() < MaxEntries)
146 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
150 WriteServ(user->fd,"937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,params[0].c_str());
154 spamlist->push_back(params[0]);
157 WriteServ(user->fd,"939 %s %s :Channel spamfilter list is full",user->nick, chan->name);
162 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
165 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
174 WriteServ(user->fd,"938 %s %s :No such spamfilter word is set",user->nick, chan->name);
182 virtual void OnSendList(userrec* user, chanrec* channel, char mode)
186 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
189 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
191 WriteServ(user->fd,"941 %s %s %s",user->nick, channel->name,i->c_str());
194 WriteServ(user->fd,"940 %s %s :End of channel spamfilter list",user->nick, channel->name);
198 virtual ~ModuleChanFilter()
204 virtual Version GetVersion()
206 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
209 virtual string_list OnChannelSync(chanrec* chan)
211 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
212 string_list commands;
215 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
217 commands.push_back("M "+std::string(chan->name)+" +g "+*i);
226 class ModuleChanFilterFactory : public ModuleFactory
229 ModuleChanFilterFactory()
233 ~ModuleChanFilterFactory()
237 virtual Module * CreateModule()
239 return new ModuleChanFilter;
245 extern "C" void * init_module( void )
247 return new ModuleChanFilterFactory;