windhamdavid 5 years ago
commit
06e7ad1290
9 changed files with 131 additions and 0 deletions
  1. BIN
      .DS_Store
  2. 1 0
      .gitignore
  3. 6 0
      .travis.yml
  4. 20 0
      LICENSE
  5. 11 0
      README.md
  6. 12 0
      index.coffee
  7. 27 0
      package.json
  8. 18 0
      script/bootstrap
  9. 36 0
      src/last-fm.coffee

BIN
.DS_Store


+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+node_modules

+ 6 - 0
.travis.yml

@@ -0,0 +1,6 @@
+language: node_js
+node_js:
+  - "0.11"
+  - "0.10"
+notifications:
+  email: false

+ 20 - 0
LICENSE

@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 hubot-scripts
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 11 - 0
README.md

@@ -0,0 +1,11 @@
+#### Hubot Last.fm
+
+[![Build Status](https://travis-ci.org/windhamdavid/hubot-last-fm.png)](https://travis-ci.org/windhamdavid/hubot-last-fm)
+
+
+##### Configuration:
+HUBOT_LASTFM_APIKEY
+
+##### Commands:
+hubot what's <last FM user> playing  - Returns song name and artist
+hubot what am I playing - only works if last.fm nick = username who typed it

+ 12 - 0
index.coffee

@@ -0,0 +1,12 @@
+fs = require 'fs'
+path = require 'path'
+
+module.exports = (robot, scripts) ->
+  scriptsPath = path.resolve(__dirname, 'src')
+  fs.exists scriptsPath, (exists) ->
+    if exists
+      for script in fs.readdirSync(scriptsPath)
+        if scripts? and '*' not in scripts
+          robot.loadFile(scriptsPath, script) if script in scripts
+        else
+          robot.loadFile(scriptsPath, script)

+ 27 - 0
package.json

@@ -0,0 +1,27 @@
+{
+  "name": "hubot-last-fm",
+  "description": "Last.fm for Hubot",
+  "version": "1.0.0",
+  "author": "David Windham",
+  "license": "MIT",
+
+  "keywords": [
+    "hubot",
+    "hubot-scripts"
+  ],
+
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/windhamdavid/hubot-last-fm.git"
+  },
+
+  "bugs": {
+    "url": "https://github.com/windhamdavid/hubot-last-fm/issues"
+  },
+
+  "dependencies": {
+    "coffee-script": "~1.8"
+  },
+
+  "main": "index.coffee"
+}

+ 18 - 0
script/bootstrap

@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# Make sure everything is development forever
+export NODE_ENV=development
+
+# Load environment specific environment variables
+if [ -f .env ]; then 
+  source .env
+fi
+
+if [ -f .env.${NODE_ENV} ]; then
+  source .env.${NODE_ENV}
+fi
+
+npm install
+
+# Make sure coffee id on the path
+export PATH="node_modules/.bin:$PATH"

+ 36 - 0
src/last-fm.coffee

@@ -0,0 +1,36 @@
+#
+# Description:
+#   Last (or current) played song by a user in Last.fm
+#
+# Dependencies:
+#   None
+#
+# Configuration:
+#   HUBOT_LASTFM_APIKEY
+#
+# Commands:
+#   hubot what's <last FM user> playing  - Returns song name and artist
+#   hubot what am I playing - only works if last.fm nick = username who typed it
+#
+# Author:
+#   windhamdavid
+
+
+getSong = (msg, usr) ->
+  user = usr ? msg.match[2]
+  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']}"
+
+module.exports = (robot) ->
+  robot.respond /what(')?s (.*) playing/i, (msg) ->
+    getSong(msg)
+  robot.respond /what am I playing/i, (msg) ->
+    getSong(msg, msg.message.user.name)