1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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 * ---------------------------------------------------
19 // Message and notice filtering using glob patterns
20 // a module based on the original work done by Craig Edwards in 2003
21 // for the chatspike network.
31 /* $ModDesc: An advanced spam filtering module */
32 /* $ModDep: m_filter.h */
34 typedef std::map<std::string,FilterResult*> filter_t;
36 class ModuleFilter : public FilterBase
42 ModuleFilter(InspIRCd* Me)
43 : FilterBase::FilterBase(Me)
45 // read the configuration file on startup.
46 // it is perfectly valid to set <filter file> to the value of the
47 // main config file, then append your <keyword> tags to the bottom
48 // of the main config... but rather messy. That's why the capability
49 // of using a seperate config file is provided.
53 virtual ~ModuleFilter()
57 virtual FilterResult* FilterMatch(const std::string &text)
59 std::string text2 = text+" ";
60 for (filter_t::iterator index = filters.begin(); index != filters.end(); index++)
62 if ((ServerInstance->MatchText(text2,index->first)) || (ServerInstance->MatchText(text,index->first)))
70 virtual void OnRehash(const std::string ¶meter)
72 // this automatically re-reads the configuration file into the class
73 ConfigReader* MyConf = new ConfigReader(ServerInstance);
74 for (filter_t::iterator n = filters.begin(); n != filters.end(); n++)
79 for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
81 std::string pattern = MyConf->ReadValue("keyword","pattern",index);
82 std::string reason = MyConf->ReadValue("keyword","reason",index);
83 std::string do_action = MyConf->ReadValue("keyword","action",index);
86 FilterResult* x = new FilterResult;
88 x->action = do_action;
95 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
97 class ModuleFilterFactory : public ModuleFactory
100 ModuleFilterFactory()
104 ~ModuleFilterFactory()
108 virtual Module * CreateModule(InspIRCd* Me)
110 return new ModuleFilter(Me);
116 extern "C" void * init_module( void )
118 return new ModuleFilterFactory;