Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

spammer mitigation - A mod to Flagging Plugin that auto-deletes a comment based on:

peregrineperegrine MVP
edited October 2014 in Vanilla 2.0 - 2.8

if the comment is flagged 5 times and if the body of the message contains specific words or phrases.

so, if

  • flagged more than 5 times
  • the comment contains a phrase most likely from a spammer or is pretty much always offensive.

then the comment is auto-deleted without admin intervention.

put your words or phrases in line 12 array
e.g. $Patterns = Array("Bad Word", "Offensive", "I Just wanted to Say Hello ");

you could modify it to check discussions as well if you want to. And also check for discussion titles as well, I decided just to do it just for comments and the body of comment.

https://github.com/vanilla/vanilla/blob/2.1/plugins/Flagging/class.flagging.plugin.php#L357

     $Sender->InformMessage(T('FlagSent', "Your complaint has been registered."));

to

        $FlagCount = Gdn::SQL()
               ->Select('DiscussionID')
               ->From('Flag fl')
               ->Where('ForeignType', $Context)
               ->Where('ForeignID', $ElementID)
               ->GetCount();

       // change flagcount from 5 to whatever number you want
       if (($FlagCount > 5) && ($Context == "comment")) {

         //  modify your patterns of words here - only the patterns below will be auto-deleted
         $Patterns = Array("Bad Word", "Offensive", "I Just wanted to Say Hello ");
            $Patterns  = array_map('strtolower',$Patterns);
            $CommentModel = new CommentModel();
            $Result = $CommentModel->GetID($ElementID);
            $ComBody = strtolower($Result->Body);
            $WordFound = false;
             $ComBody = str_replace(array('/','.', '[', ']', '{', '}'), 'X', $ComBody);
             foreach ($Patterns as $Pattern) {
                  if(preg_match("/" . $Pattern . "/", $ComBody)){
                      $WordFound = true;
                      //  $Sender->InformMessage($Pattern);

          }
         }

              if($WordFound) {
              $CommentModel->Delete($ElementID);
              Gdn::SQL()->Delete('Flag',array('ForeignID' => $ElementID));
              $Sender->InformMessage(T("comment removed"));
              }


        }


         $Sender->InformMessage(T('FlagSent', "Your complaint has been registered."));

I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.