-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.coffee
More file actions
80 lines (65 loc) · 2.69 KB
/
utils.coffee
File metadata and controls
80 lines (65 loc) · 2.69 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module.exports = (robot) ->
robot.respond /times$/i, (msg) ->
spawn = require('child_process').spawn
API_KEY = "g728y37tz9xdyyurnw97d8f5"
API_URI = "http://api.worldweatheronline.com/free/v1/tz.ashx?format=json&key=#{API_KEY}&q="
offices = {
TW: 'Taipei',
PHIL: 'manila',
India: 'India',
Fibernet: '84097',
LA: 'LA'
}
times = ""
msg.http(API_URI+offices['TW']).get() (err, res, body) ->
currentTime = JSON.parse(body)['data']['time_zone'][0]['localtime'].slice 5
times += "TW: #{currentTime}\n"
msg.http(API_URI+offices['PHIL']).get() (err, res, body) ->
currentTime = JSON.parse(body)['data']['time_zone'][0]['localtime'].slice 5
times += "PHIL: #{currentTime}\n"
msg.http(API_URI+offices['India']).get() (err, res, body) ->
currentTime = JSON.parse(body)['data']['time_zone'][0]['localtime'].slice 5
times += "India: #{currentTime}\n"
msg.http(API_URI+offices['Fibernet']).get() (err, res, body) ->
currentTime = JSON.parse(body)['data']['time_zone'][0]['localtime'].slice 5
times += "Fibernet: #{currentTime}\n"
msg.http(API_URI+offices['LA']).get() (err, res, body) ->
currentTime = JSON.parse(body)['data']['time_zone'][0]['localtime'].slice 5
times += "LA: #{currentTime}\n"
msg.send times
robot.respond /time in (.*)$/i, (msg) ->
spawn = require('child_process').spawn
API_KEY = "g728y37tz9xdyyurnw97d8f5"
API_URI = "http://api.worldweatheronline.com/free/v1/tz.ashx"
msg.http(API_URI).query({
q: msg.match[1]
key: API_KEY
format: 'json'
}).get() (err, res, body) ->
try
result = JSON.parse(body)['data']
city = result['request'][0]['query']
currentTime = result['time_zone'][0]['localtime'].slice 5
offset = result['time_zone'][0]['utcOffset']
msg.send "Current time in #{city} => #{currentTime} (UTC #{offset})"
catch error
msg.send "Sorry, no city found. Please, check your input and try it again"
robot.respond /ping (.*)$/i, (msg) ->
spawn = require('child_process').spawn
dest = msg.match[1]
command = "ping -c 3 -s 32 #{dest}"
msg.send "#{command} ..."
@exec = require('child_process').exec
@exec command, (error, stdout, stderr) ->
msg.send error
msg.send stdout
msg.send stderr
robot.respond /hostname$/i, (msg) ->
spawn = require('child_process').spawn
command = "hostname"
msg.send "#{command} ..."
@exec = require('child_process').exec
@exec command, (error, stdout, stderr) ->
msg.send error
msg.send stdout
msg.send stderr