Created
March 6, 2015 03:21
-
-
Save uris77/3c8688857403d3c705eb to your computer and use it in GitHub Desktop.
Twitter bot
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
var Twit = require('twit'); | |
var config = require('./config'); | |
var T = new Twit(config); | |
var stream = T.stream('statuses/filter', {track: '#ngconf'}); | |
stream.on('tweet', function(tweet) { | |
console.log('Incoming Tweet'); | |
if(!tweet.in_reply_to_user_id && tweet.user.screen_name !== 'freethejazz') { | |
if(!tweet.favorited && isLucky(1/2)) { | |
scheduleFuture(favoriteTweet, tweet); | |
if(!tweet.retweeted && isLucky(1/2)) { | |
scheduleFuture(retweetTweet, tweet); | |
} | |
} | |
if(!tweet.user.following && isLucky(1/8)) { | |
scheduleFuture(followUser, tweet.user); | |
} | |
} | |
}); | |
var scheduleFuture = function(fn, arg) { | |
setTimeout(fn, randomMsBetween(20000, 90000), arg); | |
}; | |
var randomMsBetween = function(low, high) { | |
return Math.floor(Math.random() * high - low) + low; | |
}; | |
var isLucky = function(chances) { | |
return (Math.random() < chances); | |
} | |
var favoriteTweet = function(tweet) { | |
console.log('Favoriting tweet:' + tweet.text); | |
T.post('favorites/create', { id: tweet.id_str }, cb); | |
}; | |
var retweetTweet = function(tweet) { | |
console.log('Retweeting tweet:' + tweet.text); | |
T.post('statuses/retweet/:id', { id: tweet.id_str }, cb); | |
}; | |
var followUser = function(user) { | |
console.log('Following user: ' + user.screen_name); | |
T.post('friendships/create', {screen_name: user.screen_name, follow: true}, cb); | |
} | |
var cb = function(err) { | |
if(err) { | |
console.log(err); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment