]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/ActivitySpam/scripts/silencespammer.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / ActivitySpam / scripts / silencespammer.php
index 2eb9461e456e1af00532516866de186a73e285e2..4e710d10a7bac3735dbcef765fd442947eae4ebc 100644 (file)
@@ -31,7 +31,7 @@ Users who post a lot of spam get silenced
   -a --all      All users
 END_OF_SILENCESPAMMER_HELP;
 
-require_once INSTALLDIR.'/scripts/commandline.inc';
+require_once INSTALLDIR.'/scripts/commandline.inc.php';
 
 function testAllUsers($filter, $minimum, $percent) {
     $found = false;
@@ -64,28 +64,34 @@ function silencespammer($filter, $user, $minimum, $percent) {
 
     printfnq("Testing user %s\n", $user->nickname);
 
-    $profile = Profile::staticGet('id', $user->id);
+    $profile = Profile::getKV('id', $user->id);
 
+    if ($profile->isSilenced()) {
+       printfnq("Already silenced %s\n", $user->nickname);
+       return;
+    }
+    
     $cnt = $profile->noticeCount();
 
     if ($cnt < $minimum) {
         printfnq("Only %d notices posted (minimum %d); skipping\n", $cnt, $minimum);
-    }   
+       return;
+    }
 
     $ss = new Spam_score();
 
     $ss->query(sprintf("SELECT count(*) as spam_count ".
                        "FROM notice join spam_score on notice.id = spam_score.notice_id ".
-                       "WHERE notice.profile_id = %d", $profile->id));
+                       "WHERE notice.profile_id = %d AND spam_score.is_spam = 1", $profile->id));
 
     while ($ss->fetch()) {
         $spam_count = $ss->spam_count;
     }                 
 
-    $spam_percent = ($spam_count * 100 / $cnt);
+    $spam_percent = ($spam_count * 100.0 / $cnt);
 
     if ($spam_percent > $percent) {
-        printfnq("Silencing user %d (%0.2f%% spam)\n", $user->nickname, $spam_percent);
+        printfnq("Silencing user %s (%d/%d = %0.2f%% spam)\n", $user->nickname, $spam_count, $cnt, $spam_percent);
         try {
             $profile->silence();
         } catch(Exception $e) {