Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #6 from guilleiguaran/lastfm-np
Add script for current playing song in Last.fm
  • Loading branch information
atmos committed Oct 26, 2011
2 parents 0d96683 + cb66664 commit c61959d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/scripts/lastfm_np.coffee
@@ -0,0 +1,18 @@
# Last (or current) played song by a user in Last.fm
#
# hubot <what's playing> someone - Returns song name and artist
#

module.exports = (robot) ->
robot.respond /what's playing (.*)/i, (msg) ->
user = escape(msg.match[1])
apiKey = process.env.HUBOT_LASTFM_APIKEY
msg.http('http://ws.audioscrobbler.com/2.0/?')
.query(method: 'user.getrecenttracks', user: user, api_key: apiKey, format: 'json')
.get() (err, res, body) ->
results = JSON.parse(body)
if results.error
msg.send results.message
return
song = results.recenttracks.track[0]
msg.send "#{song.name} by #{song.artist['#text']}"

0 comments on commit c61959d

Please sign in to comment.