Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created May 26, 2013 16:23
Show Gist options
  • Save ELLIOTTCABLE/5653246 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/5653246 to your computer and use it in GitHub Desktop.
var tinysong = function(context, song_name, number){
var uri = "http://tinysong.com/s/"+song_name.split(' ').join('+');
console.log(uri);
request({ uri: uri, json: true, encoding: 'utf8'
, qs: {format: 'json', limit: number, key: '323d2374a9253c2bfc73fd0e6a461fb7'}
}, function(err, res, songs){
if (err || songs.error) {
console.log(err, songs.error);
context.channel.send_reply(context.sender, "HTTP request failed. ):") }
else {
var blue = "\0032", green = "\0033", yellow = "\0037", reset="\017";
var reply = songs.map(function(song){
return green+'“'+song.SongName+'”'+reset+', '
+yellow+song.ArtistName+reset+': '
+blue+'<'+song.Url+'>'+reset }).join(', ')
console.log(util.inspect(reply))
context.channel.send_reply(context.sender, reply, {color: true})
}
});
}
this.register_command("song", function(context, text){ tinysong(context, text, 3) });
this.register_listener(/^♪\s+(.*)$/, function(context,_, text){ tinysong(context, text, 1) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment