Created
March 23, 2012 21:40
-
-
Save martinisoft/2175349 to your computer and use it in GitHub Desktop.
Play-Next Hubot Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Play music. At your office. Like a boss. | |
# | |
# NOTE: | |
# This uses the new version of play (the next branch currently) | |
# https://github.com/holman/play/tree/next | |
# | |
# Make sure you set up your HUBOT_PLAY_URL environment variable with the URL to | |
# your company's play. | |
# | |
# Controls | |
# play|bring the noise - Plays music. | |
# stop - Stops the music. | |
# play next|downvote|skip - Plays the next song. | |
# go back|previous - Plays the previous song. | |
# tone it down|quiet|be quiet - Mutes Play. | |
# volume [0-100] - Adjust the volumne of Play. | |
# volume - Check on the volume of iTunes | |
# say <message> - `say` your message over the speakers. | |
# | |
# Queue | |
# what's playing - Returns the currently-played song. | |
# I like/love this song|star this song|upvote - Favorite the currently playing song. | |
# play something I'd like - Queues up to 5 songs you've favorited. | |
# play "artist" - Queue 10 random tracks from an Artist (quotes optional) | |
# play "name" by "artist" - Queues a song name by artist (quotes optional) | |
# play album "album" - Queues an album (quotes optional). | |
URL = "#{process.env.HUBOT_PLAY_URL}" | |
module.exports = (robot) -> | |
# Where's Play? | |
robot.respond /where'?s play/i, (message) -> | |
message.send("play's at #{URL}") | |
# Play | |
robot.respond /(unpause|bring the noise)/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/play") | |
.query(login: message.message.user.githubLogin) | |
.put() (err, res, body) -> | |
try | |
message.send "Fine, fine." | |
catch error | |
message.send "I can't do that Dave..." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Pause | |
robot.respond /(pause|stop the music)/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/pause") | |
.query(login: message.message.user.githubLogin) | |
.put() (err, res, body) -> | |
try | |
message.send "What? You don't like music?" | |
catch error | |
message.send "You can't stop the music dude, don't even try." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Next | |
robot.respond /(play )?(next|downvote|skip)( song)?/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/next") | |
.query(login: message.message.user.githubLogin) | |
.put() (err, res, body) -> | |
try | |
message.send "Onward! To the next track!" | |
catch error | |
message.send "Couldn't skip. You can't explain that." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Previous | |
robot.respond /(go back|previous)/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/previous") | |
.query(login: message.message.user.githubLogin) | |
.put() (err, res, body) -> | |
try | |
message.send "Liked that one huh? Going back a track." | |
catch error | |
message.send "Couldn't go back, Jack." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Mute Play | |
robot.respond /(tone it down|be quiet|quiet)/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/app-volume") | |
.query(login: message.message.user.githubLogin, volume: 0) | |
.put() (err, res, body) -> | |
try | |
message.send "Ok, I'll keep it down. :(" | |
catch error | |
message.send "WHAT WAS THAT?! I COULDN'T HEAR YOU!" | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Volume Adjust | |
robot.respond /volume (.*)/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/app-volume") | |
.query(login: message.message.user.githubLogin, volume: message.match[1]) | |
.put() (err, res, body) -> | |
try | |
message.send "Adjusted Volume to #{message.match[1]}" | |
catch error | |
message.send "Did you know? Changing the volume was problematic for me." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Volume Check | |
robot.respond /volume$/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/app-volume") | |
.query(login: message.message.user.githubLogin) | |
.get() (err, res, body) -> | |
try | |
message.send "iTunes is blasting at: #{body}" | |
catch error | |
message.send "iTunes was soooo not listening to me ask about its Volume Level." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Say | |
robot.respond /say (.*)/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/say") | |
.query(login: message.message.user.githubLogin, message: message.match[1]) | |
.post() (err, res, body) -> | |
try | |
message.send message.match[1] | |
catch error | |
message.send "Say What?!?" | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Now Playing | |
robot.respond /what'?s playing/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/now_playing") | |
.query(login: message.message.user.githubLogin) | |
.get() (err, res, body) -> | |
try | |
json = JSON.parse(body) | |
str = "\"" + json.name + "\" by " + | |
json.artist + ", from \"" + json.album + "\"." | |
message.send "Now playing " + str | |
catch error | |
message.send "Couldn't talk to play, is this the day the music died?" | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Star a song | |
robot.respond /(I like|star|I love|upvote)( this song)?/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/now_playing") | |
.query(login: message.message.user.githubLogin) | |
.post() (err, res, body) -> | |
try | |
json = JSON.parse(body) | |
message.send "You really like #{json.artist}? Fine, I'll do it." | |
catch error | |
message.send "Sorry, you'll have to star Milli Vanilli somewhere else" | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Queue Artist | |
robot.respond /play ["']?(.+)["']?/i, (message) -> | |
return if message.match[1].match(' by ') | |
return if message.match[1] == 'next' | |
return if message.match[1].split(' ')[0] == 'song' | |
return if message.match[1].split(' ')[0] == 'album' | |
return if message.match[1].split(' ')[0] == 'something' | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/freeform") | |
.query(login: message.message.user.githubLogin, subject: message.match[1]) | |
.post() (err, res, body) -> | |
try | |
json = JSON.parse(body) | |
songList = for song in json.songs | |
do (song) -> | |
"#{song.name}" | |
message.send "Queued up 10 Songs by #{message.match[1]}\n" + songList.join("\n") | |
catch error | |
message.send "Play hates #{message.match[1]} so pick something else" | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Queue Album | |
robot.respond /play album ["']?(.+)["']?/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/freeform") | |
.query(login: message.message.user.githubLogin, subject: message.match[1]) | |
.post() (err, res, body) -> | |
try | |
json = JSON.parse(body) | |
message.send "Queued up the album #{message.match[1]}" | |
catch error | |
message.send "Couldn't find #{message.match[1]} anywhere, sure you got that right?" | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Queue Song by Artist | |
robot.respond /play ["']?(.+)["']? by ["']?(.+)["']?/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/queue") | |
.query(login: message.message.user.githubLogin, name: message.match[1], artist: message.match[2]) | |
.post() (err, res, body) -> | |
try | |
message.send "Queued up #{message.match[1]} by #{message.match[2]}" | |
catch error | |
message.send "Play hates #{message.match[2]} so pick something else" | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Queue Starred | |
robot.respond /play something i('d)? like/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/queue/stars") | |
.query(login: message.message.user.githubLogin) | |
.post() (err, res, body) -> | |
try | |
json = JSON.parse(body) | |
songList = for song in json.songs | |
do (song) -> | |
"#{song.name} by #{song.artist}" | |
message.send "Queued up\n" + songList.join("\n") | |
catch error | |
message.send "Play says your favorites suck." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" | |
# Download Song | |
robot.respond /I want this song/i, (message) -> | |
user = message.message.user | |
if user.githubLogin | |
message.http("#{URL}/now_playing") | |
.query(login: message.message.user.githubLogin) | |
.get() (err, res, body) -> | |
try | |
json = JSON.parse(body) | |
message.send "Cool! Me too. You can snag it at: #{URL}/#{json.id}/download" | |
catch error | |
message.send "Grab a flashlight, I can't find the download link to this song." | |
else | |
message.send "I don't know you, introduce yourself with 'i am'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment