function silencespammer($filter, $user, $minimum, $percent) { printfnq("Testing user %s\n", $user->nickname); $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 AND spam_score.is_spam = 1", $profile->id)); while ($ss->fetch()) { $spam_count = $ss->spam_count; } $spam_percent = $spam_count * 100.0 / $cnt; if ($spam_percent > $percent) { printfnq("Silencing user %s (%d/%d = %0.2f%% spam)\n", $user->nickname, $spam_count, $cnt, $spam_percent); try { $profile->silence(); } catch (Exception $e) { printfnq("Error: %s", $e->getMessage()); } } }
protected static function upgradeNoticeCreated() { $score = new Spam_score(); $score->whereAdd('notice_created IS NULL'); if ($score->find()) { while ($score->fetch()) { $notice = Notice::staticGet('id', $score->notice_id); if (!empty($notice)) { $orig = clone $score; $score->notice_created = $notice->created; $score->update($orig); } } } }