Skip to content

Instantly share code, notes, and snippets.

@bcks
Created October 7, 2015 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcks/23945ab3979fa098d58c to your computer and use it in GitHub Desktop.
Save bcks/23945ab3979fa098d58c to your computer and use it in GitHub Desktop.
FISAbot is a bot for expedited processing of FISA warrant requests via Twitter. Not officially affiliated with the US Foreign Intelligence Surveillance Court.
var Twitter = require('node-twitter');
function getVerdict() {
// http://en.wikipedia.org/wiki/United_States_Foreign_Intelligence_Surveillance_Court
var caseNumber = Math.floor(Math.random() * 33942) + 1;
if (caseNumber <= 11) { return 'Application denied. Please submit appeal to the Court of Review.'; }
else if ((caseNumber > 11) && (caseNumber <= 504 + 515)) { return 'Please modify your request and resubmit.'; }
else { return 'I authorize this request.'; }
}
var searchTerms = ['@FISAbot','FISA court','FISA judge','FISA warrant']
var twitterRestClient = new Twitter.RestClient(
'CONSUMER_KEY',
'CONSUMER_SECRET',
'TOKEN',
'TOKEN_SECRET'
);
var twitterStreamClient = new Twitter.StreamClient(
'CONSUMER_KEY',
'CONSUMER_SECRET',
'TOKEN',
'TOKEN_SECRET'
);
twitterStreamClient.start(searchTerms);
function tweetReply(tweet) {
twitterRestClient.statusesUpdate(
{
'in_reply_to_status_id': tweet.id_str,
'status': '@' + tweet.user.screen_name + ': ' + getVerdict() + ' https://twitter.com/' + tweet.user.screen_name + '/status/' + tweet.id_str
},
function(error, result) {
if (error) {
console.log('Twitter Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
console.log(tweet);
// put into queue to try again?
}
}
);
}
twitterStreamClient.on('close', function() {
console.log('Connection closed. Restarting.');
twitterStreamClient.start(searchTerms);
});
twitterStreamClient.on('end', function() {
console.log('End of Line. Restarting.');
twitterStreamClient.start(searchTerms);
});
twitterStreamClient.on('error', function(error) {
console.log('twitterStreamClient Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
});
twitterStreamClient.on('tweet', function(tweet) {
// console.log(tweet);
var count = (tweet.text.match(/@/g) || []).length;
// console.log('count ', count);
// console.log('tweet.user.screen_name ', tweet.user.screen_name);
if ( (count > 6) || (tweet.user.screen_name == 'FISAbot') ) {
// too many @'s. This looks like spam.
} else {
// console.log('tweet!');
tweetReply(tweet);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment