Skip to content

Instantly share code, notes, and snippets.

@neuling
Last active May 18, 2016 11:52
Show Gist options
  • Save neuling/44b6b0b2847c991070cb319f2d3d6eb7 to your computer and use it in GitHub Desktop.
Save neuling/44b6b0b2847c991070cb319f2d3d6eb7 to your computer and use it in GitHub Desktop.
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