<commit_before>import { wrapVulcanAsyncScript } from './utils'
import { Vulcan } from '../vulcan-lib';
import { userIPBanAndResetLoginTokens, userDeleteContent } from '../callbacks';
import Users from '../../lib/collections/users/collection'
import moment from 'moment'

const banUser = async (user: DbUser) => {
  await Users.rawCollection().bulkWrite([{
    updateOne: {
      filter: {_id: user._id},
      update: {
        $set: {
          bio: '',
          htmlBio: '',
          banned: moment().add(12, 'months').toDate(),
          deleteContent: true,
        },
      },
    }
  }])
  void userIPBanAndResetLoginTokens(user);
  void userDeleteContent(user);
}

Vulcan.oneOffBanSpammers = wrapVulcanAsyncScript(
  'oneOffBanSpammers',
  async () => {
    const spammers = Users.find({
      // signUpReCaptchaRating: {$exists: false},
      reviewedByUserId: {$exists: false},
      createdAt: {
        $gte: moment.utc("2019-05-21").toDate(),
        $lt: moment.utc("2019-06-13").toDate(),
      },
      banned: {$exists: false},
      $or: [
        {bio: {$exists: true}},
        {commentCount: {$gt: 0}},
        {postCount: {$gt: 0}},
        {signUpReCaptchaRating: {$lt: 0.4}},
      ]
    })
    // eslint-disable-next-line no-console
    console.log('Spammer count', await spammers.count())
    for (const spammer of await spammers.fetch()) {
      await banUser(spammer)
    }
  }
)<commit_msg>Fix random migration we had lying around<commit_after>import { wrapVulcanAsyncScript } from './utils'
import { Vulcan } from '../vulcan-lib';
import { userIPBanAndResetLoginTokens, userDeleteContent } from '../callbacks';
import Users from '../../lib/collections/users/collection'
import moment from 'moment'

const banUser = async (user: DbUser, adminUser: DbUser) => {
  await Users.rawCollection().bulkWrite([{
    updateOne: {
      filter: {_id: user._id},
      update: {
        $set: {
          bio: '',
          htmlBio: '',
          banned: moment().add(12, 'months').toDate(),
          deleteContent: true,
        },
      },
    }
  }])
  void userIPBanAndResetLoginTokens(user);
  void userDeleteContent(user, adminUser);
}

Vulcan.oneOffBanSpammers = wrapVulcanAsyncScript(
  'oneOffBanSpammers',
  async (adminId) => {
    const spammers = Users.find({
      // signUpReCaptchaRating: {$exists: false},
      reviewedByUserId: {$exists: false},
      createdAt: {
        $gte: moment.utc("2019-05-21").toDate(),
        $lt: moment.utc("2019-06-13").toDate(),
      },
      banned: {$exists: false},
      $or: [
        {bio: {$exists: true}},
        {commentCount: {$gt: 0}},
        {postCount: {$gt: 0}},
        {signUpReCaptchaRating: {$lt: 0.4}},
      ]
    })
    // eslint-disable-next-line no-console
    console.log('Spammer count', await spammers.count())
    const adminUser = await Users.findOne({_id: adminId})
    for (const spammer of await spammers.fetch()) {
      await banUser(spammer, adminUser)
    }
  }
)
{'fraction_non_alphanumeric': 0.16178943827783385, 'fraction_numerical': 0.014799865455768583, 'mean_word_length': 2.708229426433915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '975906', 'n_tokens_mistral': 1013, 'n_tokens_neox': 966, 'n_words': 202}