Support for config.outputPrefix [#462]

This commit is contained in:
reality 2013-05-21 17:13:19 +00:00
parent 0daa08b401
commit 36d40f65a3
4 changed files with 21 additions and 15 deletions

View File

@ -1,4 +1,5 @@
{
"dependencies": [ "command" ],
"ignorable": true
"ignorable": true,
"outputPrefix": "\u00039spotify\u000f"
}

View File

@ -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));

View File

@ -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."
}
}

12
run.js
View File

@ -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