From 8688ee05ba4f9ef46cca0b24e5e9aa04e09000b5 Mon Sep 17 00:00:00 2001 From: reality Date: Tue, 9 Jul 2013 21:08:55 +0000 Subject: [PATCH] soundcloud command [#524] --- modules/soundcloud/soundcloud.js | 27 +++++++++++++++++++++++++++ modules/soundcloud/strings.json | 3 +++ 2 files changed, 30 insertions(+) diff --git a/modules/soundcloud/soundcloud.js b/modules/soundcloud/soundcloud.js index 97aab8c..9308ae5 100644 --- a/modules/soundcloud/soundcloud.js +++ b/modules/soundcloud/soundcloud.js @@ -8,6 +8,33 @@ var _ = require('underscore')._, var soundcloud = function(dbot) { this.ApiRoot = 'http://api.soundcloud.com'; + this.commands = { + '~soundcloud': function(event) { + var query = event.input[1]; + request.get(this.ApiRoot + '/tracks.json', { + 'qs': { + 'client_id': this.config.client_id, + 'q': query + }, + 'json': true + }, function(error, response, body) { + if(body.length != 0) { + body = body[0]; + event.reply(dbot.t('sc_track', { + 'title': body.title, + 'artist': body.user.username, + 'genre': body.genre.trim(), + 'plays': body.playback_count, + 'favs': body.favoritings_count + }) + ' — ' + body.permalink_url); + } else { + event.reply(dbot.t('sc_notrack')); + } + }); + } + }; + this.commands['~soundcloud'].regex = [/^~soundcloud (.+)$/, 2]; + this.onLoad = function() { dbot.api.link.addHandler(this.name, /https?:\/\/(www\.)?soundcloud\.com\//, diff --git a/modules/soundcloud/strings.json b/modules/soundcloud/strings.json index 59c21d1..a3eb6d4 100644 --- a/modules/soundcloud/strings.json +++ b/modules/soundcloud/strings.json @@ -1,5 +1,8 @@ { "sc_track": { "en": "[{title} by {artist} — {genre} — \u000312▶\u000f{plays} \u000304♥\u000f{favs}]" + }, + "sc_notrack": { + "en": "No results found." } }