Skip to content

Commit

Permalink
Merge pull request #14 from mobyvb/soundcloud
Browse files Browse the repository at this point in the history
Added Soundcloud support
  • Loading branch information
irapha committed Aug 6, 2014
2 parents d67d439 + 254d416 commit dbb4d69
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions scripts/sound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var http = require('http');

module.exports = function(robot) {

robot.respond(/(?:sound(?:cloud)?)(?: me)? (.*)/i, function(msg) {
var query = msg.match[1];
var options = {
host: 'api.soundcloud.com',
port: 80,
path: '/tracks.json?q=' + query.replace(" ", "%20") + '&client_id=2cb63ea0eb1310eadd006fad73c68b75'
};

body = "";

http.get(options, function(res) {
res.on('data', function(chunk) {
body += chunk;
});

res.on('end', function() {
body = JSON.parse(body);

if (!body.length){
return msg.send("I didn't find any sounds for \""+query+"\"...");
}
msg.send(body[0].permalink_url);
return;

});
});
});
};

0 comments on commit dbb4d69

Please sign in to comment.