Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created October 30, 2012 03:15
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save max-mapper/3978118 to your computer and use it in GitHub Desktop.
Save max-mapper/3978118 to your computer and use it in GitHub Desktop.
twitter bot for @sandyaid retweets
var crypto = require('crypto')
var request = require('request')
var url = require('url')
var irc = require('./IRC/lib/irc') // https://github.com/gf3/IRC-js
var ntwitter = require('ntwitter')
var twitter = require('twitter')
var qs = require('querystring')
// separate accounts to post and search because twitter was sending me 500s
// when I tried to use the same oauth creds for both twitter() and ntwitter()
var postOauth = {
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
}
var searchOauth = {
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
}
var botName = "sandybot"
var botChannel = "#sandyaid"
var bot = new irc({ server: 'irc.freenode.net'});
bot.connect(function () {
bot.nick(botName)
bot.join(botChannel)
})
bot.addListener('privmsg', function(msg) {
// { person: { nick: 'mbalho', user: '~max'},
// command: 'PRIVMSG',
// params: [ '#sandyaid', 'sandybot: test' ] }
if (msg.params[0].indexOf(botChannel) === -1) return
if (msg.params[1].indexOf(botName + ':') !== 0) return
var tweetID = msg.params[1]
tweetID = tweetID.replace(botName + ': ', '')
tweetID = tweetID.split(' ')[0]
bot.privmsg(botChannel, 'tweeting ' + tweetID + '...' )
twitter.retweetStatus(tweetID, function(data) {
console.log('retweeted', tweetID)
})
})
var twitter = new twitter(postOauth)
var tweets = new ntwitter(searchOauth)
function startStreaming() {
tweets.stream('statuses/filter', { track: 'sandyaid, sandyvolunteer' }, function(stream) {
stream.on('data', function(tweet) {
if (tweet.text.match(/^RT/)) return
bot.privmsg('#sandyaid', 'Tweet ' + tweet.id_str + " - @" + tweet.user.screen_name + ': ' + tweet.text)
});
console.log("listening for tweets...");
stream.on('end', startStreaming)
});
}
startStreaming()
{ text: 'RT @HurricaneHackrs: Those seeking non-emergency assistance from community volunteers should tweet with hash-tag #SandyAid. We will aggr ...',
contributors: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id_str: null,
geo: null,
retweet_count: 19,
source: 'web',
retweeted: false,
entities: { user_mentions: [ [Object] ], hashtags: [ [Object] ], urls: [] },
in_reply_to_user_id: null,
in_reply_to_status_id: null,
truncated: false,
id_str: '263114448431095808',
place: null,
coordinates: null,
created_at: 'Tue Oct 30 03:05:47 +0000 2012',
retweeted_status:
{ text: 'Those seeking non-emergency assistance from community volunteers should tweet with hash-tag #SandyAid. We will aggregate requests. #Sandy',
contributors: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id_str: null,
geo: null,
retweet_count: 19,
source: 'web',
retweeted: false,
entities: { user_mentions: [], hashtags: [Object], urls: [] },
in_reply_to_user_id: null,
in_reply_to_status_id: null,
truncated: false,
id_str: '263107473068683266',
place: null,
coordinates: null,
created_at: 'Tue Oct 30 02:38:04 +0000 2012',
user:
{ notifications: null,
profile_background_image_url: 'http://a0.twimg.com/profile_background_images/697475042/37494876a19d1f50fbc907fdd51e938d.jpeg',
friends_count: 0,
is_translator: false,
default_profile: false,
profile_background_image_url_https: 'https://si0.twimg.com/profile_background_images/697475042/37494876a19d1f50fbc907fdd51e938d.jpeg',
profile_link_color: '0084B4',
followers_count: 26,
location: 'East Coast, USA',
contributors_enabled: false,
time_zone: null,
profile_background_color: 'C0DEED',
description: 'Gathering information and organizing tech+social projects related to Hurricane Sandy',
profile_background_tile: true,
profile_image_url_https: 'https://si0.twimg.com/profile_images/2782710682/f7b93879d4b28215ede518c4cc990aa9_normal.png',
screen_name: 'HurricaneHackrs',
default_profile_image: false,
follow_request_sent: null,
profile_sidebar_fill_color: 'DDEEF6',
verified: false,
favourites_count: 0,
lang: 'en',
profile_sidebar_border_color: 'fff',
protected: false,
id_str: '913676251',
created_at: 'Tue Oct 30 01:55:10 +0000 2012',
name: 'Hurricane Hackers',
statuses_count: 2,
profile_use_background_image: true,
url: 'http://bit.ly/SoCslP',
profile_image_url: 'http://a0.twimg.com/profile_images/2782710682/f7b93879d4b28215ede518c4cc990aa9_normal.png',
id: 913676251,
listed_count: 0,
following: null,
geo_enabled: false,
utc_offset: null,
profile_text_color: '333333' },
id: 263107473068683260,
in_reply_to_screen_name: null,
favorited: false },
user:
{ notifications: null,
profile_background_image_url: 'http://a0.twimg.com/images/themes/theme1/bg.png',
friends_count: 81,
is_translator: false,
default_profile: true,
profile_background_image_url_https: 'https://si0.twimg.com/images/themes/theme1/bg.png',
profile_link_color: '0084B4',
followers_count: 43,
location: '',
contributors_enabled: false,
time_zone: 'Nuku\'alofa',
profile_background_color: 'C0DEED',
description: 'One of Many',
profile_background_tile: false,
profile_image_url_https: 'https://si0.twimg.com/profile_images/2336205875/temp_normal.jpg',
screen_name: 'CheerfulKiwi',
default_profile_image: false,
follow_request_sent: null,
profile_sidebar_fill_color: 'DDEEF6',
verified: false,
favourites_count: 13,
lang: 'en',
profile_sidebar_border_color: 'C0DEED',
protected: false,
id_str: '616978859',
created_at: 'Sun Jun 24 10:06:07 +0000 2012',
name: 'Under Seal',
statuses_count: 1733,
profile_use_background_image: true,
url: null,
profile_image_url: 'http://a0.twimg.com/profile_images/2336205875/temp_normal.jpg',
id: 616978859,
listed_count: 0,
following: null,
geo_enabled: false,
utc_offset: 46800,
profile_text_color: '333333' },
id: 263114448431095800,
in_reply_to_screen_name: null,
favorited: false }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment