Skip to content

Instantly share code, notes, and snippets.

@donpdonp

donpdonp/4sq-whereis.js

Last active Dec 20, 2015
Embed
What would you like to do?
neurontab 'where is' foursquare checkin
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
You can’t perform that action at this time.