Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created December 10, 2011 03:52
Show Gist options
  • Save max-mapper/1454545 to your computer and use it in GitHub Desktop.
Save max-mapper/1454545 to your computer and use it in GitHub Desktop.
foursquare irc bridge thingy
var crypto = require('crypto'),
fs = require("fs"),
https = require('https'),
http = require("http"),
sys = require('sys'),
request = require('request'),
url = require('url'),
querystring = require('querystring'),
tako = require('./tako'),
qs = require('querystring'),
irc = require('./IRC/lib/irc');
var bot = new irc({ server: 'irc.freenode.net'});
bot.connect(function () {
bot.nick('nerdtracker5000');
bot.join('#nerdtracker');
});
var options = {
baseURL: "https://outmapp.in",
ca: fs.readFileSync('sub.class1.server.ca.pem'),
key: fs.readFileSync('ssl.key'),
cert: fs.readFileSync('ssl.crt'),
"fsqID": "",
"fsqSecret": ""
};
var t = tako()
t.middle('json')
t.route('/', function(req, resp) {
resp.end('go to /nerdtracker/login to register')
})
t.route('/nerdtracker/push', function(req, resp) {
req.on('data', function (data) {
var checkin = JSON.parse(qs.parse(data.toString()).checkin)
var msg = checkin.user.firstName + ' just checked in at ' + checkin.venue.name
if (checkin.venue && checkin.venue.location && checkin.venue.location.address) msg = msg + ' (' + checkin.venue.location.address + ')'
if (checkin.shout) msg = msg + ': ' + checkin.shout
bot.privmsg('#nerdtracker', msg)
})
req.on('end', function() {
resp.end('thanks foursquare')
})
})
t
.route('/nerdtracker/login', function (req, resp) {
var u = 'https://foursquare.com/oauth2/authenticate'
+ '?client_id=' + options.fsqID
+ '&response_type=code'
+ '&redirect_uri=' + options.baseURL + '/nerdtracker/callback'
;
resp.statusCode = 302
resp.setHeader('location', u)
resp.end()
})
t
.route('/nerdtracker/callback', function (req, resp) {
var u = 'https://foursquare.com/oauth2/access_token'
+ '?client_id=' + options.fsqID
+ '&client_secret=' + options.fsqSecret
+ '&grant_type=authorization_code'
+ '&redirect_uri=' + options.baseURL + '/nerdtracker/callback'
+ '&code=' + req.qs.code
;
request.get({url:u}, function (e, r, body) {
resp.statusCode = 200
var dataz = JSON.parse(body)
dataz.registration_success = true
dataz.all_done = true
bot.privmsg('#nerdtracker', 'a new person just registered!')
resp.end(JSON.stringify(dataz))
})
})
t.listen(function(handler) {
return https.createServer(options, handler)
}, 443)
@takempf
Copy link

takempf commented Jun 3, 2013

Which IRC lib is this using? irc = require('./IRC/lib/irc');

@max-mapper
Copy link
Author

it's and old version of https://github.com/gf3/IRC-js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment