This repository was archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathplay.coffee
195 lines (161 loc) · 7.61 KB
/
play.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Description:
# Play music. At your office. Like a boss. https://github.com/play/play
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_PLAY_URL
# HUBOT_PLAY_TOKEN
#
# Commands:
# hubot play - Plays music.
# hubot play next - Plays the next song.
# hubot play previous - Plays the previous song.
# hubot what's playing - Returns the currently-played song.
# hubot what's next - Returns next song in the queue.
# hubot I want this song - Returns a download link for the current song.
# hubot I want this album - Returns a download link for the current album.
# hubot play <artist> - Queue up ten songs from a given artist.
# hubot play <album> - Queue up an entire album.
# hubot play <song> - Queue up a particular song. This grabs the first song by playcount.
# hubot play <something> right [fucking] now - Play this shit right now.
# hubot where's play - Gives you the URL to the web app.
# hubot volume? - Returns the current volume level.
# hubot volume [0-100] - Sets the volume.
# hubot be quiet - Mute play.
# hubot say <message> - `say` your message over your speakers.
# hubot clear play - Clears the Play queue.
#
# Author:
# holman
URL = "#{process.env.HUBOT_PLAY_URL}"
authedRequest = (message, path, action, options, callback) ->
message.http("#{URL}#{path}")
.query(login: message.message.user.githubLogin, token: "#{process.env.HUBOT_PLAY_TOKEN}")
.header('Content-Length', 0)
.query(options)[action]() (err, res, body) ->
callback(err,res,body)
module.exports = (robot) ->
robot.respond /where'?s play/i, (message) ->
message.finish()
authedRequest message, '/stream_url', 'get', {}, (err, res, body) ->
message.send("play's at #{URL} and you can stream from #{body}")
robot.respond /what'?s playing/i, (message) ->
authedRequest message, '/now_playing', 'get', {}, (err, res, body) ->
json = JSON.parse(body)
str = "\"#{json.name}\" by #{json.artist}, from \"#{json.album}\"."
message.send("#{URL}/images/art/#{json.id}.png?login=HOTFIX#.jpg")
message.send("Now playing " + str)
robot.respond /what'?s next/i, (message) ->
authedRequest message, '/queue', 'get', {}, (err, res, body) ->
json = JSON.parse(body)
song = json.songs[1]
if typeof(song) == "object"
message.send("We will play this awesome track \"#{song.name}\" by #{song.artist} in just a minute!")
else
message.send("The queue is empty :( Try adding some songs, eh?")
robot.respond /say (.*)/i, (message) ->
authedRequest message, '/say', 'post', {message: message.match[1]}, (err, res, body) ->
message.send(message.match[1])
robot.respond /play next/i, (message) ->
message.finish()
authedRequest message, '/next', 'put', {}, (err, res, body) ->
json = JSON.parse(body)
message.send("On to the next one (which conveniently is #{json.artist}'s \"#{json.name}\")")
#
# VOLUME
#
robot.respond /app volume\?/i, (message) ->
message.finish()
authedRequest message, '/app-volume', 'get', {}, (err, res, body) ->
message.send("Yo :#{message.message.user.name}:, the volume is #{body} :mega:")
robot.respond /app volume (.*)/i, (message) ->
params = {volume: message.match[1]}
authedRequest message, '/app-volume', 'put', params, (err, res, body) ->
message.send("Bumped the volume to #{body}, :#{message.message.user.name}:")
robot.respond /volume\?/i, (message) ->
message.finish()
authedRequest message, '/system-volume', 'get', {}, (err, res, body) ->
message.send("Yo :#{message.message.user.name}:, the volume is #{body} :mega:")
robot.respond /volume ([+-])?(.*)/i, (message) ->
if message.match[1]
multiplier = if message.match[1][0] == '+' then 1 else -1
authedRequest message, '/system-volume', 'get', {}, (err, res, body) ->
newVolume = parseInt(body) + parseInt(message.match[2]) * multiplier
params = {volume: newVolume}
authedRequest message, '/system-volume', 'put', params, (err, res, body) ->
message.send("Bumped the volume to #{body}, :#{message.message.user.name}:")
else
params = {volume: message.match[2]}
authedRequest message, '/system-volume', 'put', params, (err, res, body) ->
message.send("Bumped the volume to #{body}, :#{message.message.user.name}:")
robot.respond /pause|(pause play)|(play pause)/i, (message) ->
message.finish()
params = {volume: 0}
authedRequest message, '/system-volume', 'put', params, (err, res, body) ->
message.send("The office is now quiet. (But the stream lives on!)")
robot.respond /(unpause play)|(play unpause)/i, (message) ->
message.finish()
params = {volume: 50}
authedRequest message, '/system-volume', 'put', params, (err, res, body) ->
message.send("The office is now rockin' at half-volume.")
robot.respond /start play/i, (message) ->
message.finish()
authedRequest message, '/play', 'put', {}, (err, res, body) ->
json = JSON.parse(body)
message.send("Okay! :)")
robot.respond /stop play/i, (message) ->
message.finish()
authedRequest message, '/pause', 'put', {}, (err, res, body) ->
json = JSON.parse(body)
message.send("Okay. :(")
#
# STARS
#
robot.respond /I want this song/i, (message) ->
authedRequest message, '/now_playing', 'get', {}, (err, res, body) ->
json = JSON.parse(body)
url = "#{URL}/song/#{json.id}/download"
message.send("Pretty rad, innit? Grab it for yourself: #{url}")
robot.respond /I want this album/i, (message) ->
authedRequest message, '/now_playing', 'get', {}, (err, res, body) ->
json = JSON.parse(body)
url = "#{URL}/artist/#{escape json.artist}/album/#{escape json.album}/download"
message.send("you fucking stealer: #{url}")
robot.respond /(play something i('d)? like)|(play the good shit)/i, (message) ->
message.finish()
authedRequest message, '/queue/stars', 'post', {}, (err, res, body) ->
json = JSON.parse(body)
str = json.songs.map (song) ->
"\"#{song.name} by #{song.artist}\""
str.join(', ')
message.send("NOW HEAR THIS: You will soon listen to #{str}")
robot.respond /I (like|star|love|dig) this( song)?/i, (message) ->
authedRequest message, '/now_playing', 'post', {}, (err, res, body) ->
json = JSON.parse(body)
message.send("It's certainly not a pedestrian song, is it. I'll make a "+
"note that you like #{json.artist}'s \"#{json.name}\".")
#
# PLAYING
#
robot.respond /play (.*)/i, (message) ->
params = {subject: message.match[1]}
authedRequest message, '/freeform', 'post', params, (err, res, body) ->
if body.length == 0
return message.send("That doesn't exist in Play. Or anywhere, probably. If it's not"+
" in Play the shit don't exist. I'm a total hipster.")
json = JSON.parse(body)
str = json.songs.map (song) ->
"\"#{song.name}\" by #{song.artist}"
str.join(', ')
message.send("Queued up #{str}")
robot.respond /clear play/i, (message) ->
authedRequest message, '/queue/all', 'delete', {}, (err, res, body) ->
message.send(":fire: :bomb:")
robot.respond /spin (it|that shit)/i, (message) ->
authedRequest message, '/dj', 'post', {}, (err, res, body) ->
message.send(":mega: :cd: :dvd: :cd: :dvd: :cd: :dvd: :speaker:")
robot.respond /stop (spinning|dj)/i, (message) ->
authedRequest message, '/dj', 'delete', {note: "github-dj-#{message.message.user.githubLogin}"}, (err, res, body) ->
message.send("Nice work. You really did a great job. Your session has been saved and added to Play as: #{body}")