diff --git a/modules/spotify/config.json b/modules/spotify/config.json index a051064..6ee3966 100644 --- a/modules/spotify/config.json +++ b/modules/spotify/config.json @@ -1,4 +1,5 @@ { "dependencies": [ "command" ], - "ignorable": true + "ignorable": true, + "outputPrefix": "\u00039spotify\u000f" } diff --git a/modules/spotify/spotify.js b/modules/spotify/spotify.js index 729ec88..764586b 100644 --- a/modules/spotify/spotify.js +++ b/modules/spotify/spotify.js @@ -29,7 +29,6 @@ var spotify = function(dbot) { if(!error && response.statusCode == 200) { if(_.has(body, 'track')) { event.reply(dbot.t('track', { - 's': this.spotifyText, 'artist': _.map(body.track.artists, function(a) { return a.name }).join(', '), 'album': body.track.album.name, @@ -37,13 +36,11 @@ var spotify = function(dbot) { })); } else if(_.has(body, 'album')) { event.reply(dbot.t('album', { - 's': this.spotifyText, 'artist': body.album.artist, 'album': body.album.name })); } else if(_.has(body, 'artist')) { event.reply(dbot.t('artist', { - 's': this.spotifyText, 'artist': body.artist.name })); } @@ -78,7 +75,6 @@ var spotify = function(dbot) { this.api.spotifySearch(query, function(body, t) { if(body) { event.reply(dbot.t('found', { - 's': this.spotifyText, 'artist': _.map(body.tracks[0].artists, function(a) { return a.name }).join(', '), 'album': body.tracks[0].album.name, @@ -86,7 +82,7 @@ var spotify = function(dbot) { 'url': t })); } else { - event.reply(dbot.t('not-found', { 's': this.spotifyText })); + event.reply(dbot.t('not-found')); } }.bind(this)); }, @@ -103,7 +99,6 @@ var spotify = function(dbot) { this.api.spotifySearch(name, function(body, t) { if(body) { event.reply(dbot.t('found', { - 's': this.spotifyText, 'artist': _.map(body.tracks[0].artists, function(a) { return a.name }).join(', '), 'album': body.tracks[0].album.name, @@ -111,7 +106,7 @@ var spotify = function(dbot) { 'url': t })); } else { - event.reply('No results'); + event.reply(dbot.t('not-found')); } }.bind(this)); }.bind(this)); diff --git a/modules/spotify/strings.json b/modules/spotify/strings.json index 125b7ca..22cb4b4 100644 --- a/modules/spotify/strings.json +++ b/modules/spotify/strings.json @@ -1,19 +1,19 @@ { "artist": { - "en": "{s} [artist] {artist}" + "en": "[artist] {artist}" }, "album": { - "en": "{s} [album] {artist} – {album}" + "en": "[album] {artist} – {album}" }, "track": { - "en": "{s} [track] {artist} – {track} (from {album})" + "en": "[track] {artist} – {track} (from {album})" }, "found": { - "en": "{s} [{url}] {artist} – {track} (from {album})" + "en": "[{url}] {artist} – {track} (from {album})" }, "not-found": { - "en": "{s} No results.", + "en": "{No results.", "na'vi": "{s}, Oel ke tsun rivum ayuoti.", - "nl": "{s} Geen resultaten." + "nl": "Geen resultaten." } } diff --git a/run.js b/run.js index b42e4e6..07a017e 100644 --- a/run.js +++ b/run.js @@ -95,7 +95,12 @@ DBot.prototype.t = function(string, formatData) { } if(_.has(this.strings[string], lang)) { + var module = this.stringMap[string]; formattedString = this.strings[string][lang].format(formatData); + if(this.config[module].outputPrefix) { + formattedString = '[' + this.config[module].outputPrefix + '] ' + + formattedString; + } } } @@ -127,7 +132,7 @@ DBot.prototype.reloadModules = function() { this.modules = {}; this.commands = {}; this.api = {}; - this.commandMap = {}; // Map of which commands belong to which modules + this.stringMap = {}; this.usage = {}; // Load config changes @@ -219,6 +224,11 @@ DBot.prototype.reloadModules = function() { propertyData = JSON.parse(fs.readFileSync(moduleDir + property + '.json', 'utf-8')); } catch(err) {}; _.extend(this[property], propertyData); + if(property == 'strings') { + _.each(_.keys(propertyData), function(string) { + this.stringMap[string] = name; + }.bind(this)); + } }, this); // Load the module itself