Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Last active December 20, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donpdonp/6198061 to your computer and use it in GitHub Desktop.
Save donpdonp/6198061 to your computer and use it in GitHub Desktop.
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