<commit_before>/**
 * Twitter bot that follows+mutes+lists random people 
 * who follow certain users or who tweet about certain topics
 * and unfollows random followers from those lists
 * who don't follow back
 */

const Twit = require('twit');
const config = process.env || require('./config');

const twit = new Twit(config);
const screen_names = config.screen_names.split(',');
const search_terms = config.search_terms.split(',');

const seconds = 65;
const otherList = 'web-development-datavis';

// Do something random on interval:
setInterval(() => {
  var randomList = getRandom(search_terms);
  var randomUser = getRandom(screen_names);
  switch (getRandom([1,2,3])) {
    case 1:
      findUserByFollowers(randomUser).then( follow(otherList) );
    case 2:
      findUserByTopic(randomList).then( follow(randomList) );
    case 3:
      unfollow( getRandom([randomList, otherList]) );
  }
}, seconds * 1000);


// Choose a random follower of someone on the list:
function findUserByFollowers(screenName) {
  console.log(`Finding a user who follows @${screenName}...`);
  return twit.get('followers/list', { screen_name: screenName })
    .then(({ data }) => data.users.map(user => user.screen_name))
    .then(getRandom)
    .catch(console.error);
}


// Choose a random user tweeting about a topic:
function findUserByTopic(list) {
  console.log(`Finding a user tweeting about ${list}...`);
  return twit.get('search/tweets', {
      q: `${list} -${config.username}`,
      count: 100
    })
    .then((resp) => resp.data.statuses
      .map((status) => status.user.screen_name)
      .filter(unique)
    )
    .then(getRandom)
    .catch(console.error);
}


// Follow a user, mute them, and add them to a list:
function follow(list) {
  return (user) => twit.post('friendships/create', { screen_name: user })
    .then(({ data }) => twit.post('mutes/users/create', {
      screen_name: data.screen_name
    }))
    .then(({ data }) => {
      console.log(`Followed @${data.screen_name} and added them to list ${list}.`);
      return twit.post('lists/members/create', {
        slug: list,
        owner_screen_name: config.username,
        screen_name: data.screen_name<commit_msg>Don't select users you already follow.<commit_after>/**
 * Twitter bot that follows+mutes+lists random people 
 * who follow certain users or who tweet about certain topics
 * and unfollows random followers from those lists
 * who don't follow back
 */

const Twit = require('twit');
const config = process.env || require('./config');

const twit = new Twit(config);
const screen_names = config.screen_names.split(',');
const search_terms = config.search_terms.split(',');

const seconds = 65;
const otherList = 'web-development-datavis';

// Do something random on interval:
setInterval(() => {
  var randomList = getRandom(search_terms);
  var randomUser = getRandom(screen_names);
  switch (getRandom([1,2,3])) {
    case 1:
      findUserByFollowers(randomUser).then( follow(otherList) );
    case 2:
      findUserByTopic(randomList).then( follow(randomList) );
    case 3:
      unfollow( getRandom([randomList, otherList]) );
  }
}, seconds * 1000);


// Choose a random follower of someone on the list:
function findUserByFollowers(screenName) {
  console.log(`Finding a user who follows @${screenName}...`);
  return twit.get('followers/list', { screen_name: screenName })
    .then(({ data }) => data.users
      .filter((user) => !user.following)
      .map((user) => user.screen_name)
    )
    .then(getRandom)
    .catch(console.error);
}


// Choose a random user tweeting about a topic:
function findUserByTopic(list) {
  console.log(`Finding a user tweeting about ${list}...`);
  return twit.get('search/tweets', {
      q: `${list} -${config.username}`,
      count: 100
    })
    .then((resp) => resp.data.statuses
      .filter((status) => !status.user.following)
      .map((status) => status.user.screen_name)
      .filter(unique)
    )
    .then(getRandom)
    .catch(console.error);
}


// Follow a user, mute them, and add them to a list:
function follow(list) {
  return (user) => twit.post('friendships/create', { screen_name: user })
    .then(({ data }) => twit.post('mutes/users/create', {
      screen_name: data.screen_name
    }))
    .then(({ data }) => {
      console.log(`Followed @${data.screen_name} and added them to list ${list}.`);
      return twit.post('lists/members/create', {
        slug: list,
        owner_screen_name: config.username,
        screen_name: data.screen_name
{'fraction_non_alphanumeric': 0.1497125165855816, 'fraction_numerical': 0.006634232640424591, 'mean_word_length': 3.577935222672065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3530278', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1404, 'n_words': 365}