Created
May 13, 2014 12:12
-
-
Save cobyism/becdea9e9f9cb6a7d433 to your computer and use it in GitHub Desktop.
hubot remote me example.
This file contains hidden or 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
# make this URL an endpoint that returns something like the users.json file in this gist. | |
baseUrl = "…" | |
robot.respond /remote me/i, (msg) -> | |
if Math.random() < 0.01 | |
msg.send "https://f.cloud.github.com/assets/1476/552951/f1a15572-c370-11e2-8ddd-db568c36d27a.jpg" | |
return | |
msg.finish() | |
msg.http(baseUrl) | |
.headers(headers) | |
.get() (err, res, body) -> | |
if err | |
console.log(err) | |
else | |
try | |
users = JSON.parse(body).users | |
catch e | |
console.log(body) | |
# This box defines a rectangle considered to be "local". | |
# In our case it’s roughly SF + Oakland or thereabouts. | |
theBox = | |
lats: [ 37.237, 38.050 ], | |
longs: [ -122.657, -121.671 ] | |
@remote_people = [] | |
for user in users | |
if user.last_known_location | |
local = theBox.lats[0] <= user.last_known_location.lat <= theBox.lats[1] && | |
theBox.longs[0] <= user.last_known_location.long <= theBox.longs[1] | |
@remote_people.push(user.login.toLowerCase()) unless local | |
names = @remote_people.sort() | |
names = names.join(', ') | |
msg.send "Whoa, " + @remote_people.length + "/" + users.length + " meatbags are remote (#{Math.floor(@remote_people.length / users.length * 1000)/10}%)" | |
msg.send "Remote meatbags: #{names}" |
This file contains hidden or 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
// Have your endpoint return something like this structure. | |
{ | |
"users": [ | |
{ | |
"login": "…", | |
"last_known_location": { | |
"lat": …, | |
"long": … | |
} | |
}, | |
… | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment