Last active
December 20, 2015 21:29
-
-
Save donpdonp/6198061 to your computer and use it in GitHub Desktop.
neurontab 'where is' foursquare checkin
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
function(msg){ | |
if (msg.type == "foursquare") { | |
db.set('whereisdonpdonp', JSON.stringify(msg['checkin'])) | |
} | |
if (msg.type == "emessage") { | |
var override = /where is donpdonp/.test(msg.message) | |
if(override || msg.to_nick == 'donpdonp'){ | |
var checkin = db.get('whereisdonpdonp') | |
var text = "" | |
if(!checkin) { | |
text = "null island" | |
} else { | |
checkin = JSON.parse(checkin) | |
venue = checkin.venue | |
var time = new Date(checkin.createdAt*1000) | |
var time_diff = (new Date()) - time | |
var diff_minutes = time_diff / 1000 / 60 | |
var categories = venue.categories.map(function(e){ | |
if(e.parents.length > 0) { | |
return e.parents[0] | |
} else { | |
return e.name | |
} | |
}) | |
if(diff_minutes < 45 || override) { | |
if(msg.nick) { | |
text += msg.nick+": donpdonp is " | |
} | |
if(categories.indexOf('Food') > -1) { | |
text += "eating " | |
} | |
text += "at "+venue.name+" ("+diff_minutes.toFixed(0)+" mins ago)" | |
} | |
} | |
return text | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment