Browse files

Version 0.0.6

Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
  • Loading branch information...
1 parent 195b030 commit 6bc3ff6cfbd867f2e20042fec5af17605736eeec @creatorrr committed Mar 29, 2013
Showing with 40 additions and 17 deletions.
  1. +1 −1 package.json
  2. +1 −1 src/index.coffee
  3. +37 −12 src/listeners.coffee
  4. +0 −1 src/pages.coffee
  5. +1 −1 src/routes.coffee
  6. +0 −1 src/socket-controller.coffee
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "hubot-rdio",
- "version": "0.0.6-test",
+ "version": "0.0.6",
"description": "Rdio controller for hubot.",
"main": "lib/index.js",
"scripts": {
View
2 src/index.coffee
@@ -21,7 +21,7 @@ module.exports = (robot) ->
robot.respond /init rdio/i, listeners.init
# robot.respond /test rdio/i, listeners.test
- # robot.respond /play (song|artist|album) (["'\w: \-_]+).*$/i, listeners.play
+ robot.respond /play (track|artist|album) (["'\w: \-_]+).*$/i, listeners.play
robot.respond /play whatever/i, listeners.playWhatever
robot.respond /pause( music){0,1}/i, listeners.pause
View
49 src/listeners.coffee
@@ -1,9 +1,20 @@
# External libraries
+{inspect} = require 'util'
Rdio = require 'node-rdio'
# Load globals
{RDIO_CONSUMER, RDIO_SECRET, DOMAIN, CALLBACK} = require './globals'
+# Helpers
+isString = (obj) ->
+ Object::toString.call(obj) is '[object String]'
+
+random = (min, max) -> min + Math.floor Math.random()*(max - min + 1)
+
+getRandom = (arr) -> arr[random 0, arr.length]
+
+capitalize = (str) -> (str.charAt 0).toUpperCase() + str[1..]
+
module.exports = listeners = (robot) ->
getRdio = ->
accessToken = robot.brain.get 'RdioAccessToken'
@@ -46,27 +57,41 @@ module.exports = listeners = (robot) ->
test: (msg) ->
rdio = getRdio()
- rdio.call 'currentUser', (error, data) ->
+ rdio.call 'currentUser', (error, {result}) ->
if error
- robot.logger.warn "Error: #{ error }"
+ robot.logger.debug "Error: #{ error }"
return msg.send "Error: #{ error }"
- msg.send "Success: #{ (require 'utils').inspect data }"
+ msg.send "Success: #{ inspect result }"
- pause: ->
+ pause: (msg) ->
robot.emit 'player:send', 'pause'
+ msg.send 'Song paused.'
playWhatever: (msg) ->
rdio = getRdio()
- rdio.call 'getTopCharts', {type: 'Track'}, (error, data) ->
+ rdio.call 'getTopCharts', {type: 'Track'}, (error, {result}) ->
+ if error
+ robot.logger.debug "Error: #{ error }"
+ return msg.send "Error: #{ error }"
+
+ track = getRandom result
+ robot.emit 'player:send', 'play', track
+
+ msg.send "Playing track #{ track.name }"
+
+ play: (msg) ->
+ mode = capitalize msg.match[0].toLowerCase()
+ query = msg.match[1]
+
+ rdio = getRdio()
+ rdio.call 'search', {type: mode, query: query}, (error, data) ->
if error
- robot.logger.warn "Error: #{ error }"
+ robot.logger.debug "Error: #{ error }"
return msg.send "Error: #{ error }"
- try
- track = (JSON.parse data)[0]
- catch e
- track = key: 'a997982'
- finally
- robot.emit 'player:send', 'play', track
+ msg.send inspect data
+
+ # track = getRandom result
+ # robot.emit 'player:send', 'play', track
}
View
1 src/pages.coffee
@@ -61,7 +61,6 @@ pages =
coffeescript ->
socket = io.connect()
- socket.on 'lady gaga', (data) -> alert data
socket.on 'pause', -> $('#pause').click()
socket.on 'play', (track) ->
console.log track
View
2 src/routes.coffee
@@ -60,7 +60,7 @@ module.exports = routes = (robot) ->
res.end pages.redirect
message: "Yay! Your access token is #{ accessToken }"
- redirect: '/'
+ redirect: '/player'
player: (req, res) ->
res.writeHead 200,
View
1 src/socket-controller.coffee
@@ -2,7 +2,6 @@ module.exports = (robot) ->
new ->
@sockets = []
robot.on 'sockets:connection', (socket) =>
- socket.emit 'lady gaga', data: 'lol'
socket.on 'event', (args...) ->
robot.emit 'player:receive', args...

0 comments on commit 6bc3ff6

Please sign in to comment.