Last active
May 18, 2016 11:52
-
-
Save neuling/44b6b0b2847c991070cb319f2d3d6eb7 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 client = new Twit({ | |
consumer_key: process.env.CONSUMER_KEY, | |
consumer_secret: process.env.CONSUMER_SECRET, | |
access_token: process.env.ACCESS_TOKEN, | |
access_token_secret: process.env.ACCESS_TOKEN_SECRET | |
}); | |
Array.prototype.random = function() { return this[Math.floor(this.length * Math.random())]; }; | |
const stream = client.stream('statuses/filter', { track: ['@askjollife'] }); | |
const answers = { | |
yes: ['Yes!', 'yes!', 'Yessss!', 'yep!', 'Positive!'], | |
no: ['No!', 'NO!', 'hmmm ... NO!', 'Negative!'] | |
}; | |
stream.on('tweet', (tweet) => { | |
if (tweet.user.screen_name === 'askjollife' || tweet.text.indexOf('@askjollife') !== 0) { return null; } | |
const isFather = ['jollife', 'neuling2k', 'i_am_fabs'].indexOf(tweet.user.screen_name) !== -1; | |
const answer = isFather ? answers.yes.random() : answers.no.random(); | |
const answerTimeout = 2000 + (Math.random() * 5000); | |
setTimeout(() => { | |
client.post('statuses/update', { status: `@${tweet.user.screen_name} ${answer}`, in_reply_to_status_id: tweet.id }); | |
}, answerTimeout); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment