diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 93288c21a..999fead09 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -52,7 +52,11 @@ class Dmail < ApplicationRecord def initialize_attributes self.from_id ||= CurrentUser.id self.creator_ip_addr ||= CurrentUser.ip_addr - self.is_spam = spam? + if CurrentUser.is_gold? + self.is_spam = false + else + self.is_spam = spam? + end true end end diff --git a/script/fixes/049_spam_1.rb b/script/fixes/049_spam_1.rb new file mode 100644 index 000000000..b74f9c743 --- /dev/null +++ b/script/fixes/049_spam_1.rb @@ -0,0 +1,55 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')) + +CurrentUser.user = User.system +CurrentUser.ip_addr = "127.0.0.1" + +MIN_USER_ID = 528958 +MIN_DATE = "2017-09-01" +NAME_REGEXP = /^[a-z0-9]+\d{3,}$/ +BAD_TITLES = ["My collection", "hi", "My private videos", "My video", "hey", "My webcam", "My dirty fantasies", "My new video", "My hot photos", "My hot webcam", "All your desires", "My hot videos", "my profile", "record from my webcam", "my hot webcam"] + +spammers = Set.new(Dmail.where("dmails.from_id >= ? and dmails.created_at >= ? and is_spam = ?", MIN_USER_ID, MIN_DATE, true).joins("join users on users.id = dmails.from_id").where("users.name ~ '^[a-z0-9]+[0-9]{3,}$'").pluck("users.id").map(&:to_i).uniq) +new_spammers = Set.new + +User.without_timeout do + Dmail.where("created_at >= ? and is_spam = ?", MIN_DATE, false).find_each do |dmail| + from_name = dmail.from_name + if dmail.from_id >= MIN_USER_ID && from_name =~ NAME_REGEXP + dmail.update_column(:is_spam, true) + dmail.spam! + + puts "marked #{dmail.id}" + + if !spammers.include?(dmail.from_id) + new_spammers.add(dmail.from_id) + end + end + end +end + +new_new_spammers = Set.new(Dmail.where("from_id >= ? and title in (?) and from_id not in (?)", MIN_USER_ID, BAD_TITLES, (spammers + new_spammers).to_a).pluck(:from_id)) + +combined_spammers = spammers + new_spammers + new_new_spammers +User.without_timeout do + combined_spammers.each do |uid| + user = User.find(uid) + tag_change_count = PostArchive.where(updater_id: uid).count + vote_count = PostVote.where(user_id: uid).count + comment_count = Comment.where(creator_id: uid).count + dmail_count = Dmail.where(from_id: uid).count + + if tag_change_count + vote_count + comment_count > 0 + puts "#{user.name},#{uid},#{tag_change_count},#{vote_count},#{comment_count},#{dmail_count}" + end + end +end + +combined_spammers.each do |uid| + unless Ban.where(user_id: uid).exists? + Ban.create(duration: 10000, reason: "Spam (automated ref f6147ace)", user_id: uid) + puts "banned #{uid}" + sleep 1 + end +end