-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from mobyvb/soundcloud
Added Soundcloud support
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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; | ||
|
||
}); | ||
}); | ||
}); | ||
}; |