Last active
September 5, 2016 08:08
-
-
Save ifandswitch/7059dc48cf421feb44d3912f0e4f6996 to your computer and use it in GitHub Desktop.
Listen for keywords on Twitter and post them to IRC. npm install twitter irc irc-colors - add a twitterConfig.json with twitter api credentials in same directory.
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
// Twitter IRC relay | |
var irc = require('irc'); | |
var c = require('irc-colors'); | |
var twitter = require('twitter'); | |
var twitterConfig = require('./twitterConfig.json'); | |
var twitterClient = new twitter(twitterConfig); | |
// set it up | |
var config = { | |
network: 'irc.freenode.net', | |
channelName: '#monero-tweets', | |
botName: 'XMRTWEETS', | |
captureDuration: 60 * 1000 // 60 seconds in milis | |
} | |
var keywords = ['monero', 'Monero', 'XMR', 'xmr', '#XMR', 'moonero', | |
'fluffypony', '@MoneroAlert', '@monerocurrency', '@StackMonero', | |
'@MyMonero']; | |
var accountBlacklist = ['InvestAltCoins', 'censorednewsnow']; | |
twitterClient.stream('statuses/filter', {track: keywords.join(',') }, function(stream) { | |
setTimeout(function() { | |
stream.on('data', receiveTweet); | |
}, 15000); | |
stream.on('error', receiveError); | |
}); | |
// // configure irc client | |
var client = new irc.Client(config.network, config.botName, { | |
userName: config.botName, | |
realName: 'Twitter IRC Relay', | |
port: 6667, | |
debug: false, | |
autoRejoin: true, | |
channels: [config.channelName] | |
}); | |
function receiveError(error) { | |
console.log(error); | |
} | |
function receiveTweet(tweet) { | |
var user = '@' + tweet.user.screen_name; | |
if(tweet.in_reply_to_screen_name !== null) { | |
user += ' (reply to ' + tweet.in_reply_to_screen_name + ')'; | |
} | |
var url = 'https://twitter.com/statuses/' + tweet.id_str; | |
if(!isAccountInBlackList(tweet.user.screen_name)) { | |
client.say(config.channelName, '-> ' + c.bold(user) + ': ' + tweet.text + '\n^ ' + url); | |
} | |
} | |
function isAccountInBlackList(name) { | |
var isBlackListed = false; | |
accountBlacklist.forEach(function(account) { | |
if(account === name) { | |
isBlackListed = true; | |
} | |
}); | |
return isBlackListed; | |
} | |
client.addListener('error', function(message) { | |
console.log('error: ', message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment