forked from amsoell/hubot-nowplaying
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nowplaying.coffee
57 lines (49 loc) · 1.89 KB
/
nowplaying.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
# Description:
# Nowplaying queries music services to report what is playing at the moment (and recently)
#
# Dependencies:
# "xml2js": "0.1.14"
#
# Configuration:
# None
#
# Commands:
# what's playing - Find out what's playing on Radio Paradise
# hubot what's playing
# what played before - Find out what played before the current track on Radio Paradise
# hubot what played before
xml2js = require "xml2js"
nowPlaying = (msg) ->
query = encodeURIComponent(msg.match[1])
msg.http("http://radioparadise.com/xml/now.xml")
.get() (err, res, body) ->
if res.statusCode is 200 and !err?
parser = new xml2js.Parser()
parser.parseString body, (err, result) ->
if result.playlist and (result = result.playlist).song?
if result.song.length?
song = result.song[0]
else
song = result.song
msg.send "*#{song.title}* by _#{song.artist}_ is currently playing on Radio Paradise: #{song.coverart} What are people saying about this song? http://www.radioparadise.com/rp_2.php#name=Music&file=songinfo&song_id=#{song.songid}"
thenPlaying = (msg) ->
query = encodeURIComponent(msg.match[1])
msg.http("http://radioparadise.com/xml/now_4.xml")
.get() (err, res, body) ->
if res.statusCode is 200 and !err?
parser = new xml2js.Parser()
i = 0
parser.parseString body, (err, result)->
if result.playlist
for song in result.playlist.song
if i++>0
msg.send "*#{song.title}* by _#{song.artist}_"
module.exports = (robot) ->
robot.hear /^what.*(playing|on the radio|on radio)/i, (msg) ->
nowPlaying(msg)
robot.respond /what.*(playing|on the radio|on radio)/i, (msg) ->
nowPlaying(msg)
robot.hear /^what (played|was) before/i, (msg) ->
thenPlaying(msg)
robot.respond /what (played|was) before/i, (msg) ->
thenPlaying(msg)