Last active
May 7, 2017 20:04
-
-
Save ignu/00b5a85471fb95ed5688dd1b45382e49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Twit = require('twit'); | |
const R = require('ramda'); | |
const usersReplied = [] | |
var bot = new Twit(donaldjtrumpisprod) | |
const replies = [ | |
// #'Trump thinks temps are at record lows. https://twitter.com/realDonaldTrump/status/418542137899491328?ref_src=twsrc%5Etfw', | |
'https://twitter.com/justinjm1/status/860637529325883394', | |
'https://twitter.com/ddiamond/status/861244303020044288', | |
'https://corrupt.af/', | |
'https://twitter.com/braddjaffy/status/860179201785298944', | |
'http://www.politico.com/story/2017/04/28/corey-lewandowski-trump-meetings-237725', | |
'http://www.rollingstone.com/politics/news/taibbi-trump-named-craig-phillips-to-fix-wall-street-w479332', | |
'https://twitter.com/ABC/status/859831878550904833', | |
'http://www.cnn.com/2017/04/27/politics/michael-flynn-foreign-payments-investigation/index.html', | |
'https://www.washingtonpost.com/politics/2016/live-updates/general-election/real-time-fact-checking-and-analysis-of-the-first-presidential-debate/fact-check-yes-trump-did-oppose-the-iraq-war/?utm_term=.6ce812461532', | |
'http://www.washingtontimes.com/news/2016/mar/3/donald-trump-says-hed-force-us-military-commit-war/', | |
'http://rebrn.com/re/after-promising-not-to-play-much-golf-trump-takes-golf-trips-in-3252864/', | |
'https://twitter.com/davidenrich/status/859386306287337474', | |
// #'Trump claimed the unemployment rate could be 42% http://www.politifact.com/truth-o-meter/statements/2015/sep/30/donald-trump/donald-trump-says-unemployment-rate-may-be-42-perc/', | |
'http://www.motherjones.com/politics/2016/05/the-trump-files-asbestos-mob-conspiracy', | |
'Investigate Cruz\'s data for killing JFK! http://www.politico.com/blogs/2016-gop-primary-live-updates-and-results/2016/05/trump-ted-cruz-father-222730', | |
'https://apnews.com/b109774705594ae887a86b337c444e6b/Trump-transition-raised-flags-about-Flynn-Russia-contacts', | |
'https://twitter.com/realdonaldtrump/status/265895292191248385?lang=en', | |
'https://twitter.com/ABCPolitics/status/860959573225746432', | |
'http://nymag.com/daily/intelligencer/2017/05/trump-isnt-a-pragmatist-he-doesnt-understand-ideology.html', | |
//'https://twitter.com/JesseLehrich/status/860587656606076928' | |
] | |
const randomArrayReply = (items) => { | |
const index = Math.floor(Math.random()*items.length) | |
return items[index] | |
} | |
const isTrumpSupporter = (tweet) => { | |
const {user, text} = tweet | |
const match = (string, regex) => !!string.match(regex) | |
const negativeRegex = /NeverTrump|Never\sTrump|TrumpIsNotMyPresident/ | |
const nameRegex = /MAGA|14(.)+88|๐ธ|Build[(\s)]?The[(\s)]?Wal|Conservat|Deplor|tard|RedPill|Red\sPill|Trump|kek|pepe|The_Donald/i | |
const textRegex = /TrumpTrain|ForTrump|TCOT|LiberalTears/i | |
if (match(user.description, negativeRegex) || match(user.name, negativeRegex)) { | |
return false | |
} | |
return match(user.screen_name, nameRegex) || | |
match(user.name, nameRegex) || | |
match(user.description, nameRegex) || | |
match(text, textRegex) | |
} | |
const hasntReplied = (tweet) => { | |
const {user} = tweet | |
console.log("Checking for user in:", usersReplied) | |
return !R.contains(user.id, usersReplied) | |
} | |
const shouldReply = (tweet) => { | |
return isTrumpSupporter(tweet) && hasntReplied(tweet) | |
} | |
const getStatus = (tweet) => { | |
const addAts = R.map((name) => `@${name}`) | |
const mentions = R.path(['entities', 'user_mentions'])(tweet) | |
let users = R.pluck('screen_name', mentions) | |
users.push(tweet.user.screen_name) | |
users = addAts(users) | |
users = R.uniq(users).join(" ") | |
const text = randomArrayReply(replies) | |
return `${users} ${text}` | |
} | |
const reply = (tweet) => { | |
const in_reply_to_status_id = tweet.id_str | |
const status = getStatus(tweet) | |
const logger = () => { | |
const url = `http://twitter.com/${tweet.user.screen_name}/status/${in_reply_to_status_id}` | |
console.log('๐ @' + tweet.user.screen_name, tweet.user.name, tweet.user.description) | |
console.info(tweet.text) | |
console.warn(url) | |
console.log('๐' + status) | |
console.log('-------------') | |
} | |
bot.post('statuses/update', { | |
status, | |
in_reply_to_status_id | |
}, logger) | |
} | |
const MAX_SECONDS = 390 | |
const run = () => { | |
bot.get('search/tweets', { q: 'trump maga', count: 8}, function(err, data, response) { | |
let nextReply = 1 | |
data.statuses.forEach((tweet) => { | |
if(shouldReply(tweet)) { | |
usersReplied.push(tweet.user.id) | |
setTimeout(() => reply(tweet), nextReply) | |
nextReply = nextReply + Math.random() * 8000 | |
} | |
}) | |
}); | |
setTimeout(run, Math.random() * MAX_SECONDS * 1000) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment