3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

some additions to the strings file and the entire program should now be using the string entries

This commit is contained in:
Luke Slater 2012-03-24 23:48:28 +00:00
parent b6f281d88c
commit 95eaa7f948
5 changed files with 54 additions and 42 deletions

View File

@ -25,7 +25,7 @@ var adminCommands = function(dbot) {
child = exec("git pull", function (error, stdout, stderr) {
console.log(stderr);
dbot.say(data.channel, 'Git pulled that shit.');
dbot.say(data.channel, dbot.strings[dbot.language].gpull);
commands.reload(data, params);
}.bind(this));
},
@ -33,7 +33,7 @@ var adminCommands = function(dbot) {
'reload': function(data, params) {
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
dbot.reloadModules();
dbot.say(data.channel, 'Reloaded that shit.');
dbot.say(data.channel, dbot.strings[dbot.language].reload);
},
'say': function(data, params) {
@ -59,7 +59,7 @@ var adminCommands = function(dbot) {
'load': function(data, params) {
dbot.moduleNames.push(params[1]);
dbot.reloadModules();
dbot.say(data.channel, 'Loaded new module: ' + params[1]);
dbot.say(data.channel, dbot.strings[dbot.language].load_module + params[1]);
},
'unload': function(data, params) {
@ -71,9 +71,9 @@ var adminCommands = function(dbot) {
dbot.moduleNames.splice(moduleIndex, 1);
dbot.reloadModules();
dbot.say(data.channel, 'Turned off module: ' + params[1]);
dbot.say(data.channel, dbot.strings[dbot.language].unload_module + params[1]);
} else {
dbot.say(data.channel, 'Module ' + params[1] + ' isn\'t loaded... Idiot...');
dbot.say(data.channel, params[1] + dbot.strings[dbot.language].unload_error);
}
},
@ -83,31 +83,31 @@ var adminCommands = function(dbot) {
} else {
dbot.db.bans[params[2]] = [ params[1] ];
}
dbot.say(data.channel, params[1] + ' banned from ' + params[2]);
dbot.say(data.channel, params[1] + dbot.strings[dbot.language].banned + params[2]);
},
'unban': function(data, params) {
if(dbot.db.bans.hasOwnProperty(params[2]) && dbot.db.bans[params[2]].include(params[1])) {
dbot.db.bans[params[2]].splice(dbot.db.bans[params[2]].indexOf(params[1]), 1);
dbot.say(data.channel, params[1] + ' unbanned from ' + params[2]);
dbot.say(data.channel, params[1] + dbot.strings[dbot.language].unbanned + params[2]);
} else {
dbot.say(data.channel, 'It appears ' + params[1] + 'wasn\'t banned from that command, you fool.');
dbot.say(data.channel, params[1] + dbot.strings[dbot.language].unban_error);
}
},
'modehate': function(data, params) {
dbot.db.modehate.push(params[1]);
dbot.say(data.channel, 'Now modehating on ' + params[1]);
dbot.say(data.channel, dbot.strings[dbot.language].modehate + params[1]);
},
'unmodehate': function(data, params) {
dbot.db.modehate.splice(dbot.db.modehate.indexOf(params[1]), 1);
dbot.say(data.channel, 'No longer modehating on ' + params[1]);
dbot.say(data.channel, dbot.strings[dbot.language].unmodehate + params[1]);
},
'lock': function(data, params) {
dbot.db.locks.push(params[1]);
dbot.say(data.channel, 'Locked ' + params[1] + ' quotes.');
dbot.say(data.channel, dbot.strings[dbot.language].qlock + params[1]);
}
};

View File

@ -53,7 +53,7 @@ var quotes = function(dbot) {
if(quotes.hasOwnProperty(key)) {
dbot.say(data.channel, q[1] + ': ' + interpolatedQuote(key));
} else {
dbot.say(data.channel, 'Nobody loves ' + q[1]);
dbot.say(data.channel, dbot.strings[dbot.language].category_not_found + q[1]);
}
}
},
@ -70,7 +70,7 @@ var quotes = function(dbot) {
qSizes = qSizes.sort(function(a, b) { return a[1] - b[1]; });
qSizes = qSizes.slice(qSizes.length - 10).reverse();
var qString = "Largest categories: ";
var qString = dbot.strings[dbot.language].large_categories;
for(var i=0;i<qSizes.length;i++) {
qString += qSizes[i][0] + " (" + qSizes[i][1] + "), ";
@ -81,12 +81,12 @@ var quotes = function(dbot) {
'~qsearch': function(data, params) {
if(params[2] === undefined) {
dbot.say(data.channel, 'Next time provide a search parameter. Commence incineration.');
dbot.say(data.channel, dbot.strings[dbot.language].syntax_error);
} else {
params[1].trim();
key = params[1].toLowerCase();
if(!quotes.hasOwnProperty(key)) {
dbot.say(data.channel, 'That category has no quotes in it. Commence incineration.');
dbot.say(data.channel, dbot.strings[dbot.language].empty_category);
} else {
var matches = [];
@ -97,7 +97,7 @@ var quotes = function(dbot) {
}.bind(this));
if(matches.length == 0) {
dbot.say(data.channel, 'No results found.');
dbot.say(data.channel, dbot.strings[dbot.language].no_results);
} else {
dbot.say(data.channel, params[1] + ' (' + params[2] + '): ' + matches.random() + ' [' + matches.length + ' results]');
}
@ -118,9 +118,10 @@ var quotes = function(dbot) {
delete quotes[key];
}
rmAllowed = false;
dbot.say(data.channel, '\'' + quote + '\' removed from ' + q[1]);
dbot.say(data.channel, '\'' + quote + '\'' +
dbot.strings[dbot.language].removed_from + q[1]);
} else {
dbot.say(data.channel, q[1] + ' is locked. Commence incineration.');
dbot.say(data.channel, q[1] + dbot.strings[dbot.language].locked_category);
}
} else {
dbot.say(data.channel, 'No quotes exist under ' + q[1]);
@ -131,16 +132,16 @@ var quotes = function(dbot) {
if(!dbot.db.locks.include(last)) {
quotes[last].pop();
rmAllowed = false;
dbot.say(data.channel, 'Last quote removed from ' + last + '.');
dbot.say(data.channel, dbot.strings[dbot.language].last_removed + last + '.');
} else {
dbot.say(data.channel, last + ' is locked. Commence incineration.');
dbot.say(data.channel, last + dbot.strings[dbot.language].locked_category);
}
} else {
dbot.say(data.channel, 'No quotes were added recently.');
dbot.say(data.channel, dbot.strings[dbot.language].no_recent_adds);
}
}
} else {
dbot.say(data.channel, 'No spamming that shit. Try again in a few minutes...');
dbot.say(data.channel, dbot.strings[dbot.language].rmlast_spam);
}
},
@ -157,21 +158,23 @@ var quotes = function(dbot) {
delete quotes[q[1]];
}
rmAllowed = false;
dbot.say(data.channel, '\'' + q[2] + '\' removed from ' + q[1]);
dbot.say(data.channel, '\'' + q[2] + '\'' +
dbot.strings[dbot.language].removed_from + q[1]);
} else {
dbot.say(data.channel, '\'' + q[2] + '\' doesn\'t exist under user \'' + q[1] + '\'.');
dbot.say(data.channel, '\'' + q[2] + '\'' +
dbot.strings[dbot.language].q_not_exist_under + '\'' + q[1] + '\'.');
}
} else {
dbot.say(data.channel, q[1] + ' is locked. Initiate incineration.');
dbot.say(data.channel, q[1] + dbot.strings[dbot.language].locked_category);
}
} else {
dbot.say(data.channel, 'No quotes exist under ' + q[1]);
dbot.say(data.channel, dbot.strings[dbot.language].no_quotes + q[1]);
}
} else {
dbot.say(data.channel, 'Invalid syntax. Initiate incineration.');
dbot.say(data.channel, dbot.strings[dbot.language].syntax_error);
}
} else {
dbot.say(data.channel, 'No spamming that shit. Try again in a few minutes...');
dbot.say(data.channel, dbot.strings[dbot.language].rmlast_spam);
}
},
@ -190,7 +193,7 @@ var quotes = function(dbot) {
for(var category in quotes) {
totalQuoteCount += category.length;
}
dbot.say(data.channel, 'There are ' + totalQuoteCount + ' quotes in total.');
dbot.say(data.channel, dbot.strings[dbot.language].total_quotes + totalQuoteCount + '.');
}
},
@ -202,16 +205,17 @@ var quotes = function(dbot) {
quotes[key] = [];
} else {
if (quotes[key].include(q[2])) {
dbot.say(data.channel, 'Quote already in DB. Initiate incineration.');
dbot.say(data.channel, dbot.strings[dbot.language].quote_exists);
return;
}
}
quotes[key].push(q[2]);
addStack.push(q[1]);
rmAllowed = true;
dbot.say(data.channel, 'Quote saved in \'' + q[1] + '\' (' + quotes[key].length + ')');
dbot.say(data.channel, dbot.strings[dbot.language].quote_saved +
'\'' + q[1] + '\' (' + quotes[key].length + ')');
} else {
dbot.say(data.channel, 'Invalid syntax. Initiate incineration.');
dbot.say(data.channel, dbot.strings[dbot.language].syntax_error);
}
},
@ -223,9 +227,9 @@ var quotes = function(dbot) {
if(!quotes.hasOwnProperty(key) || (quotes.hasOwnProperty(key) &&
quotes[key].length == 1)) {
quotes[key] = [q[2]];
dbot.say(data.channel, 'Quote saved as ' + q[1]);
dbot.say(data.channel, dbot.strings[dbot.language].quote_saved + q[1]);
} else {
dbot.say(data.channel, 'No replacing arrays, you whore.');
dbot.say(data.channel, dbot.strings[dbot.language].quote_replace);
}
}
},
@ -241,7 +245,7 @@ var quotes = function(dbot) {
'~link': function(data, params) {
if(params[1] === undefined || !quotes.hasOwnProperty(params[1].toLowerCase())) {
dbot.say(data.channel, 'Syntax error. Commence incineration.');
dbot.say(data.channel, dbot.strings[dbot.language].syntax_error);
} else {
dbot.say(data.channel, 'Link to "'+params[1]+'" - http://nc.no.de:443/quotes/'+params[1]);
}
@ -258,9 +262,9 @@ var quotes = function(dbot) {
}
}
if(pruned.length > 0) {
dbot.say(data.channel, "Pruning empty quote categories: " + pruned.join(", "));
dbot.say(data.channel, dbot.strings[dbot.language].prune + pruned.join(", "));
} else {
dbot.say(data.channel, "No empty quote categories. Commence incineration.");
dbot.say(data.channel, dbot.strings[dbot.language].no_prune);
}
}
};

View File

@ -42,11 +42,12 @@ var spelling = function(dbot) {
var otherQ = data.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4);
if(q) {
correct(data, q[1] || q[2], data.user, function (e) {
dbot.say(data.channel, e.correcter + ' meant: ' + e.fix);
dbot.say(data.channel, e.correcter + dbot.strings[dbot.language].spelling_self + e.fix);
});
} else if(otherQ) {
correct(data, otherQ[2] || otherQ[3], otherQ[1], function (e) {
dbot.say(data.channel, e.correcter + ' thinks ' + e.candidate + ' meant: ' + e.fix);
dbot.say(data.channel, e.correcter + dbot.strings[dbot.language].spelling_other +
e.candidate + dbot.strings[dbot.language].spelling_self + e.fix);
});
} else {
if(last.hasOwnProperty(data.channel)) {

6
run.js
View File

@ -40,6 +40,9 @@ var DBot = function(timers) {
this.db.locks = [];
}
// Load the strings file
this.strings = fs.readFileSync('strings.json', 'utf-8');
// Populate bot properties with config data
this.name = this.config.name || 'dbox';
this.admin = this.config.admin || [ 'reality' ];
@ -49,6 +52,7 @@ var DBot = function(timers) {
this.port = this.config.port || 6667;
this.webPort = this.config.webPort || 443;
this.moduleNames = this.config.modules || [ 'command', 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ];
this.language = this.config.language || 'english';
this.sessionData = {};
this.timers = timers.create();
@ -113,7 +117,7 @@ DBot.prototype.reloadModules = function() {
try {
this.rawModules.push(require('./modules/' + name));
} catch(err) {
console.log('Failed to load module: ' + name);
console.log(this.strings[this.language].module_load_error + name);
}
}.bind(this));

View File

@ -26,13 +26,14 @@
"load_module": "Loaded new module: ",
"unload_module": "Turned off module: ",
"unload_error": " isn't loaded. Idiot.",
"banned": " banned from ",
"unbanned": " unbanned from ",
"unban_error": " wasn't banned from that command, fool.",
"modehate": "Hating on ",
"unmodehate": "No longer hating on ",
"qlock": "Locked quote category: ",
"spelling_self": " meant: ",
"spelling_other_1": " thinks ",
"spelling_other_2": " meant:"
"spelling_other": " thinks ",
},
"spanish": {
@ -62,6 +63,8 @@
"load_module": "",
"unload_module": "",
"unload_error": "",
"banned": "",
"unbanned": "",
"unban_error": ".",
"modehate": "",
"unmodehate": "",