]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_censor.cpp
Get rid of irc::sockets::satoap().
[user/henk/code/inspircd.git] / src / modules / m_censor.cpp
index 209d61d4a0ac2ecdf4fb419c7dc0216099b35432..56639b2984f4352c8678000fc8704c887e4e0860 100644 (file)
@@ -21,8 +21,9 @@
 
 
 #include "inspircd.h"
+#include "modules/exemption.h"
 
-typedef std::map<irc::string,irc::string> censor_t;
+typedef insp::flat_map<irc::string, irc::string> censor_t;
 
 /** Handles usermode +G
  */
@@ -42,12 +43,18 @@ class CensorChannel : public SimpleChannelModeHandler
 
 class ModuleCensor : public Module
 {
+       CheckExemption::EventProvider exemptionprov;
        censor_t censors;
        CensorUser cu;
        CensorChannel cc;
 
  public:
-       ModuleCensor() : cu(this), cc(this) { }
+       ModuleCensor()
+               : exemptionprov(this)
+               , cu(this)
+               , cc(this)
+       {
+       }
 
        // format of a config entry is <badword text="shit" replace="poo">
        ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
@@ -63,7 +70,8 @@ class ModuleCensor : public Module
                {
                        Channel* c = (Channel*)dest;
                        active = c->IsModeSet(cc);
-                       ModResult res = ServerInstance->OnCheckExemption(user,c,"censor");
+                       ModResult res;
+                       FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, c, "censor"));
 
                        if (res == MOD_RES_ALLOW)
                                return MOD_RES_PASSTHRU;
@@ -79,11 +87,11 @@ class ModuleCensor : public Module
                        {
                                if (index->second.empty())
                                {
-                                       user->WriteNumeric(ERR_WORDFILTERED, "%s %s :Your message contained a censored word, and was blocked", ((Channel*)dest)->name.c_str(), index->first.c_str());
+                                       user->WriteNumeric(ERR_WORDFILTERED, ((target_type == TYPE_CHANNEL) ? ((Channel*)dest)->name : ((User*)dest)->nick), index->first.c_str(), "Your message contained a censored word, and was blocked");
                                        return MOD_RES_DENY;
                                }
 
-                               SearchAndReplace(text2, index->first, index->second);
+                               stdalgo::string::replace_all(text2, index->first, index->second);
                        }
                }
                text = text2.c_str();