forked from EnriqueVidal/hubot-talk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quakes.coffee
43 lines (34 loc) · 1.29 KB
/
quakes.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Description:
# Ask hubot about the recent earthquakes in the last (hour, day, week or month).
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot quakes (intensity|all|significant) (period) [limit]
#
# Author:
# EnriqueVidal
lookup_site = "http://earthquake.usgs.gov"
module.exports = (robot)->
robot.respond /quakes (([12](\.[05])?)|all|significant)? (hour|day|week|month)( \d+)?$/i, (message)->
check_for_rapture message, message.match[1], message.match[4], parseInt( message.match[5] )
check_for_rapture = (message, intensity, period, limit)->
rapture_url = [ lookup_site, "earthquakes", "feed", "geojson", intensity, period ].join '/'
message.http( rapture_url ).get() (error, response, body)->
return message.send 'Sorry, something went wrong' if error
list = JSON.parse( body ).features
count = 0
for quake in list
count++
quake = quake.properties
time = build_time quake
url = [ lookup_site, quake.url ].join ''
message.send "Magnitude: #{ quake.mag }, Location: #{ quake.place }, Time: #{ time } - #{ url }"
break if count is limit
build_time = ( object )->
time = new Date object.time * 1000
[ time.getHours(), time.getMinutes(), time.getSeconds() ].join ':'