neuronbot icecondor whereis
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){ | |
var match = /^where is (\w+)\??$/.exec(msg.message) | |
if(msg.type == 'emessage' && match) { | |
var username = match[1] | |
if (username != "this") { | |
if (username == "zrobo") { | |
return "I live in the Internet." | |
} else { | |
return do_whereis(match[1]) | |
} | |
} | |
} | |
// send JSON as a privmsg to zrobo to query a location | |
if(msg.type == 'emessage' && msg.target == 'zrobo'){ | |
var irc_json = /^({[^{].*})$/.exec(msg.message) | |
if(irc_json) { | |
var ircj = JSON.parse(msg.message) | |
if(ircj.type == 'query'){ | |
bot.say(msg.nick, db.get('icecondor:'+ircj.username)) | |
} | |
} | |
} | |
function do_whereis(username){ | |
var data = db.get('icecondor:'+username) | |
if(data){ | |
var icecondor = JSON.parse(data) | |
var smsg = username+" " | |
var date = new Date(icecondor.date) | |
var min_old = ((new Date()) - date) / 1000 / 60 | |
smsg += "("+min_old.toFixed(1)+" min ago) " | |
// distance | |
var point = { type: 'Point', coordinates:[icecondor.longitude, icecondor.latitude ]} | |
var home_json = db.get('geojson:'+username+':home') | |
if(home_json){ | |
var home = JSON.parse(home_json) | |
var distance = gju.pointDistance(point, home ) | |
if (distance < 50) { | |
smsg += "is at home." | |
} else { | |
smsg += ""+distance.toFixed(1)+"m from home. " | |
} | |
} | |
// intersection words | |
var intersection = db.get('icecondor:'+username+':intersection') | |
smsg += "is at "+intersection+" " | |
// 4sq venue | |
var venue_json = db.get('icecondor:'+username+':venue') | |
if(venue_json) { | |
var venue = JSON.parse(venue_json) | |
var venue_date_key = 'icecondor:'+username+':vdate' | |
var old_date = new Date(db.get(venue_date_key)) | |
var duration_mins = ((new Date()) - old_date)/1000/60 | |
smsg += "near "+venue.name+" for "+duration_words(duration_mins) | |
} | |
return smsg | |
} else { | |
return "I'm not tracking "+username+"." | |
} | |
} | |
function duration_words(mins){ | |
var words = "" | |
var hours = parseInt(mins/60) | |
if(hours > 0) { words += hours+"hr" } | |
var mins = parseInt(mins % 60) | |
words += mins+"min" | |
return words | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment