Skip to content

Instantly share code, notes, and snippets.

@jmccartie
Created April 11, 2012 16:10
Show Gist options
  • Save jmccartie/2360281 to your computer and use it in GitHub Desktop.
Save jmccartie/2360281 to your computer and use it in GitHub Desktop.
Lunchme hubot script
# Where we gonna go for lunch?
#
# lunch me <zipcode> - get a random lunch result based on your zipcode
module.exports = (robot) ->
robot.respond /lunch me( (\d+))/i, (msg) ->
zipcode = msg.match[2]
msg.http("http://lunchme.herokuapp.com/?zipcode=" + zipcode)
.get() (err, res, body) ->
if body == ""
msg.send "Uh oh. There was an error getting results."
return false
if body
picks = JSON.parse(body)
if picks.length > 0
pick = picks[Math.floor(Math.random() * picks.length)]
msg.send "#{pick.name} (#{pick.rating} stars) #{pick.url}"
location = "#{pick.address} #{zipcode}"
mapUrl = "http://maps.google.com/maps/api/staticmap?markers=" +
escape(location) +
"&size=400x400&maptype=roadmap" +
"&sensor=false" +
"&format=png" # So campfire knows it's an image
msg.send mapUrl
else
msg.send "Can't find anything :("
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment