Forked from lfcipriani/gist:c35524da6d4712ce2c64
Last active
August 29, 2015 14:12
-
-
Save afucher/f4efa5904123df0caa5e to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
var path = require("path"); | |
var fs = require("fs"); | |
var Twit = require('twit'); | |
var rateLimiter = {}; | |
var luckyNumber = Math.round(Math.random()*60); | |
var re = /\d+/; | |
var oauth = JSON.parse(fs.readFileSync("./config/twitter_credentials.js", "UTF8")); | |
var keywords = ['sorteiotwitterbr']; | |
var client = new Twit(oauth); | |
var stream = client.stream('statuses/filter', { track: keywords }) | |
stream.on('tweet', function(tweet) { | |
var result = tweet.text.match(/\d+/); | |
var user = tweet.user.screen_name; | |
console.log(tweet.user.screen_name + "->" + tweet.text); | |
if (!!rateLimiter[user]) { | |
rateLimiter[user]++; | |
if (rateLimiter[user] >= 10) { | |
console.log("banido"); | |
return; | |
} | |
} else { | |
rateLimiter[user] = 1; | |
} | |
if (!result || result[0] != luckyNumber) { return; } | |
stream.stop(); | |
console.log("Ganhou! "+ user + " com o numero " + result[0]); | |
client.post('statuses/update', { status: "@" + user + ' Parabens, vc ganhou com o numero '+ luckyNumber, in_reply_to_status_id: tweet.id_str }, function(err, data, response) { | |
if (err) throw err; | |
}); | |
}); | |
process.on("SIGINT", function(){ | |
console.log(luckyNumber); | |
stream.stop(); | |
process.exit(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment