Skip to content

Commit

Permalink
Now working with github
Browse files Browse the repository at this point in the history
  • Loading branch information
sadasant committed Oct 13, 2012
1 parent 7f5f19b commit d695a79
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ bot.client = require('./irc').init(bot)

bot.twitter_interval = require('./twitter').init(bot)

bot.github_interval = require('./github').init(bot)

// Server
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type' : 'text/plain'})
Expand Down
33 changes: 31 additions & 2 deletions controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,30 @@ var spanish_help = 'OpenVE es una comunidad libre dedicada a la investigación y
, '?' : '???'
}
, twitter_search = {}
, github_feed = {}
, irc_nick_uppercased
, irc_nick_regex


exports.init = function(_bot) {
bot = _bot
irc_nick_uppercased = bot.config.irc.nick.toUpperCase()
irc_nick_regex = new RegExp('.?' + irc_nick_uppercased + '.?', 'g')
return controller
}


// Say hello to new users
controller.join = function(channel, nick) {
nick = nick.toUpperCase()
if (nick === irc_nick_uppercased) {
var nick_uppercassed = nick.toUpperCase()
if (nick_uppercassed === irc_nick_uppercased) {
bot.client.say(channel, '¡Saludos!')
} else {
bot.client.say(channel, nick + ': ' + '¡Bienvenido a OpenVE! :)')
}
}


// Answering to user's messages
controller.message = function(from, to, message) {
message = message.toUpperCase()
Expand All @@ -60,6 +64,8 @@ controller.message = function(from, to, message) {
}
}


// Announcing Twitter Updates
controller.twitterSearch = function(obj) {
var results = obj.results
, host = 'https://twitter.com/'
Expand All @@ -83,3 +89,26 @@ controller.twitterSearch = function(obj) {
}
twitter_search.started = true
}


// Announcing Github Updates
controller.githubFeed = function(obj) {
var entries = obj.feed.entry
, k
, v
if (!github_feed.updated) {
github_feed.updated = new Date(entries[0].updated)
}
for (k in entries) {
v = entries[k]
if (!github_feed[v.id]) {
github_feed[v.id] = v
if (github_feed.started
&& (github_feed.updated - new Date(v.updated)) < 0 // New update
) {
bot.client.say('#OpenVE', 'Github: "' + v.title.$t + '"\n' + v.link.href)
}
}
}
github_feed.started = true
}
4 changes: 4 additions & 0 deletions example_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ exports.irc = {
, server : 'irc.freenode.net'
, channels : ['#OpenVE']
}

exports.github = {
private_atom : 'https://github.com/organizations/OpenVE/sadasant.private.atom?token=' // Plus the token id
}
21 changes: 21 additions & 0 deletions github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var https = require('https')
, xml = require('xml2json')
, bot

exports.init = function(_bot) {
bot = _bot

setInterval(function() {
https.get(bot.config.github.private_atom, gotResults)
}, 1000 * 10 * 5) // 5 minute
}

function gotResults(res) {
var data = ''
res.on('data', function(chunk) {
data += chunk
})
res.on('end', function() {
bot.controller.githubFeed(JSON.parse(xml.toJson(data)))
})
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
, "dependencies" :
{ "irc" : "0.3.4"
, "xml2json" : "0.3.2"
}
, "engines" :
{ "node" : "0.8.5"
Expand Down
4 changes: 2 additions & 2 deletions twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ exports.init = function(_bot) {
bot = _bot

setInterval(function() {
http.get('http://search.twitter.com/search.json?q=OpenVE&rpp=5&result_type=recent', gotTwitterResults)
http.get('http://search.twitter.com/search.json?q=OpenVE&rpp=5&result_type=recent', gotResults)
}, 1000 * 60 * 1) // 1 minute
}

function gotTwitterResults(res) {
function gotResults(res) {
var data = ''
res.on('data', function(chunk) {
data += chunk
Expand Down

0 comments on commit d695a79

Please sign in to comment.