-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvb.coffee
60 lines (55 loc) · 2.05 KB
/
dvb.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Description
# hubot script to get current dvb information
#
# Configuration:
#
#
# Commands:
# hubot dvb <stopname> - Output the next 4 upcoming connections for <stopname>
# hubot dvb <stopname> in <num> - Output the next 4 connections for <stopname> after <num> minutes
# hubot find stop <searchString> - Try to locate a stop with a name similar to <searchString>
#
#
# Notes:
#
#
# Author:
# Kilian Koeltzsch <[email protected]>
dvb = require 'dvbjs'
format_connection = (connection) ->
if connection.arrivaltime == 0
"#{connection.line} #{connection.direction} jetzt"
else if connection.arrivaltime == 1
"#{connection.line} #{connection.direction} in #{connection.arrivaltime} Minute"
else
"#{connection.line} #{connection.direction} in #{connection.arrivaltime} Minuten"
module.exports = (robot) ->
# Match "dvb zellescher weg"
robot.respond /dvb (\D*)$/i, (res) ->
hst = res.match[1]
dvb.monitor hst, 0, 4, (err, data) ->
res.reply "That didn't seem to work :/ - #{err}" if err?
if data.length == 0
res.reply "Couldn't find anything"
return
res.send data.map(format_connection).join('\n')
# Match "dvb zellescher weg in 10 minuten"
robot.respond /dvb\s+(.*)in (\d*)/i, (res) ->
hst = res.match[1]
vz = res.match[2]
dvb.monitor hst, vz, 4, (err, data) ->
res.reply "That didn't seem to work :/ - #{err}" if err?
if data.length == 0
res.reply "Couldn't find anything"
return
res.send data.map(format_connection).join('\n')
# Match "find stop zelle"
robot.respond /find stop\s+(.*)/i, (res) ->
stop = res.match[1]
dvb.find stop, (err, data) ->
res.reply "That didn't seem to work :/ - #{err}" if err?
if data.length == 0
res.reply "Couldn't find anything for _#{stop}_"
return
searchString = encodeURIComponent "#{data[0].coords[0]},#{data[0].coords[1]}"
res.send "Did you mean _#{data[0].stop}_?\nhttp://maps.google.com/maps/api/staticmap?markers=#{searchString}&size=400x400&maptype=roadmap&sensor=false&format=png"