forked from GitHub/dbot
give all modules their own folders. overhauled admin strings
This commit is contained in:
parent
b2ea634d8c
commit
b622d7a239
148
modules/admin.js
148
modules/admin.js
@ -1,148 +0,0 @@
|
||||
/**
|
||||
* Module Name: Admin
|
||||
* Description: Set of commands which only one who is a DepressionBot
|
||||
* administrator can run - as such, it has its own command execution listener.
|
||||
*/
|
||||
var fs = require('fs');
|
||||
var sys = require('sys')
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var admin = function(dbot) {
|
||||
var commands = {
|
||||
// Join a channel
|
||||
'join': function(event) {
|
||||
var channel = event.params[1];
|
||||
if(event.allChannels.hasOwnProperty(channel)) {
|
||||
event.reply("I'm already in that channel.");
|
||||
} else {
|
||||
dbot.instance.join(event, channel);
|
||||
event.reply(dbot.t('join', {'channel': channel}));
|
||||
}
|
||||
},
|
||||
|
||||
// Leave a channel
|
||||
'part': function(event) {
|
||||
var channel = event.params[1];
|
||||
if(!event.allChannels.hasOwnProperty(channel)) {
|
||||
event.reply("I'm not in that channel.");
|
||||
} else {
|
||||
event.instance.part(event, channel);
|
||||
event.reply(dbot.t('part', {'channel': channel}));
|
||||
}
|
||||
},
|
||||
|
||||
// Op admin caller in given channel
|
||||
'opme': function(event) {
|
||||
var channel = event.params[1];
|
||||
|
||||
// If given channel isn't valid just op in current one.
|
||||
if(!event.allChannels.hasOwnProperty(channel)) {
|
||||
channel = event.channel.name;
|
||||
}
|
||||
dbot.instance.mode(event, channel, ' +o ' + event.user);
|
||||
},
|
||||
|
||||
// Do a git pull and reload
|
||||
'greload': function(event) {
|
||||
var child = exec("git pull", function (error, stdout, stderr) {
|
||||
event.reply(dbot.t('gpull'));
|
||||
commands.reload(event);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
// Reload DB, translations and modules.
|
||||
'reload': function(event) {
|
||||
dbot.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
||||
dbot.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
||||
dbot.reloadModules();
|
||||
event.reply(dbot.t('reload'));
|
||||
},
|
||||
|
||||
// Say something in a channel (TODO probably doesn't work.)
|
||||
'say': function(event) {
|
||||
var channel = event.params[1];
|
||||
if(event.params[1] === "@") {
|
||||
var channel = event.channel.name;
|
||||
}
|
||||
var message = event.params.slice(2).join(' ');
|
||||
dbot.say(event.server, channel, message);
|
||||
},
|
||||
|
||||
// Load new module
|
||||
'load': function(event) {
|
||||
var moduleName = event.params[1];
|
||||
dbot.moduleNames.push(moduleName);
|
||||
dbot.reloadModules();
|
||||
event.reply(dbot.t('load_module', {'moduleName': moduleName}));
|
||||
},
|
||||
|
||||
// Unload a loaded module
|
||||
'unload': function(event) {
|
||||
var moduleName = event.params[1];
|
||||
if(dbot.moduleNames.include(moduleName)) {
|
||||
var cacheKey = require.resolve('../modules/' + moduleName);
|
||||
delete require.cache[cacheKey];
|
||||
|
||||
var moduleIndex = dbot.moduleNames.indexOf(moduleName);
|
||||
dbot.moduleNames.splice(moduleIndex, 1);
|
||||
dbot.reloadModules();
|
||||
|
||||
event.reply(dbot.t('unload_module', {'moduleName': moduleName}));
|
||||
} else {
|
||||
event.reply(dbot.t('unload_error', {'moduleName': moduleName}));
|
||||
}
|
||||
},
|
||||
|
||||
// Ban user from command or *
|
||||
'ban': function(event) {
|
||||
var username = event.params[1];
|
||||
var command = event.params[2];
|
||||
|
||||
if(!dbot.db.bans.hasOwnProperty(command)) {
|
||||
dbot.db.bans[command] = [ ];
|
||||
}
|
||||
dbot.db.bans[command].push(username);
|
||||
event.reply(dbot.t('banned', {'user': username, 'command': command}));
|
||||
},
|
||||
|
||||
// Unban a user from command or *
|
||||
'unban': function(event) {
|
||||
var username = event.params[1];
|
||||
var command = event.params[2];
|
||||
if(dbot.db.bans.hasOwnProperty(command) && dbot.db.bans[command].include(username)) {
|
||||
dbot.db.bans[command].splice(dbot.db.bans[command].indexOf(username), 1);
|
||||
event.reply(dbot.t('unbanned', {'user': username, 'command': command}));
|
||||
} else {
|
||||
event.reply(dbot.t('unban_error', {'user': username}));
|
||||
}
|
||||
},
|
||||
|
||||
// Lock quote category so quotes can't be removed
|
||||
'lock': function(event) {
|
||||
var category = event.params[1];
|
||||
dbot.db.locks.push(category);
|
||||
event.reply(dbot.t('qlock', {'category': category}));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'name': 'admin',
|
||||
'ignorable': false,
|
||||
|
||||
/**
|
||||
* Run the appropriate admin command given the input (and user).
|
||||
*/
|
||||
'listener': function(event) {
|
||||
var commandName = event.params[0];
|
||||
if(commands.hasOwnProperty(commandName) && dbot.admin.include(event.user)) {
|
||||
commands[commandName](event);
|
||||
dbot.save();
|
||||
}
|
||||
},
|
||||
'on': 'PRIVMSG'
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return admin(dbot);
|
||||
};
|
68
modules/admin/strings.json
Normal file
68
modules/admin/strings.json
Normal file
@ -0,0 +1,68 @@
|
||||
{
|
||||
"join": {
|
||||
"english": "Joined {channel}",
|
||||
"spanish" : "Entrado en {channel}",
|
||||
"na'vi": "fpxäkìm {channel}(nemfa)",
|
||||
"welsh": "Wedi ymuno {channel}"
|
||||
},
|
||||
"part": {
|
||||
"english": "Left {channel}",
|
||||
"spanish" : "Abandonada {channel}",
|
||||
"na'vi": "Hum {channel}",
|
||||
"welsh": "Wedi gadael {channel}"
|
||||
},
|
||||
"gpull": {
|
||||
"english": "Git pulled that shit.",
|
||||
"spanish": "Hecho git pull en esta mierda.",
|
||||
"na'vi": "Gìtìl fì'uti stamarsìm.",
|
||||
"welsh": "Wedi tynnu git yr cach na i gyd"
|
||||
},
|
||||
"reload": {
|
||||
"english": "Reloaded that shit.",
|
||||
"spanish": "Recargado esta mierda.",
|
||||
"na'vi": "Oel fìuti stìyeftxaw.",
|
||||
"welsh": "Ail-lwytho'r cach na"
|
||||
},
|
||||
"load_module": {
|
||||
"english": "Loaded new module: {moduleName}",
|
||||
"spanish": "Cargado módulo nuevo: {moduleName}",
|
||||
"na'vi": "Oel {moduleName}it amip stìyeftxaw.",
|
||||
"welsh": "Wedi llwytho modiwl newydd: {moduleName}"
|
||||
},
|
||||
"unload_module": {
|
||||
"english": "Turned off module: {moduleName}",
|
||||
"spanish": "Descargado módulo: {moduleName}",
|
||||
"na'vi": "Oel {moduleName} tswìya'.",
|
||||
"welsh": "Wedi troi ffwrdd y modiwl: {moduleName}"
|
||||
},
|
||||
"unload_error": {
|
||||
"english": "{moduleName} isn't loaded. Idiot.",
|
||||
"spanish": "{moduleName} no está cargado. Idiota.",
|
||||
"na'vi": "Oel {moduleName}it omum. Nga skxawng lu.",
|
||||
"welsh": "Di {moduleName} ddim wedi llwytho. Twpsyn"
|
||||
},
|
||||
"banned": {
|
||||
"english": "{user} banned from {command}",
|
||||
"spanish": "{user} está prohibido de usar {command}",
|
||||
"na'vi": "{command}ìri {user} ke tung.",
|
||||
"welsh": "{user} wedi ei gohurio o {command}"
|
||||
},
|
||||
"unbanned": {
|
||||
"english": "{user} unbanned from {command}",
|
||||
"spanish": "{user} no está prohibido de user {command}",
|
||||
"na'vi": "{command}ìri {user} tung set.",
|
||||
"welsh": "{user} wedi ei dad-wahardd o {command}"
|
||||
},
|
||||
"unban_error": {
|
||||
"english": "{user} wasn't banned from that command, fool.",
|
||||
"spanish": "{user} no fue prohibido de esta instrucción, tont@.",
|
||||
"na'vi": "{user} fìtsu'oti tamung srekrr, nga skxawng lu.",
|
||||
"welsh": "Nid oedd {user} wedi ei wahardd o'r gyrchymun yna, fŵl"
|
||||
},
|
||||
"qlock": {
|
||||
"english": "Locked quote category: {category}",
|
||||
"spanish": "Cerrado la categoría: {category}",
|
||||
"na'vi": "{category}ìri oel 'upxareti fmoli",
|
||||
"welsh": "Categori wedi cloi: {category}"
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
/**
|
||||
* Module Name: Command
|
||||
* Description: An essential module which maps PRIVMSG input to an appropriate
|
||||
* command and then runs that command, given the user isn't banned from or
|
||||
* ignoring that command.
|
||||
*/
|
||||
var command = function(dbot) {
|
||||
/**
|
||||
* Is user banned from using command?
|
||||
*/
|
||||
var isBanned = function(user, command) {
|
||||
var banned = false;
|
||||
if(dbot.db.bans.hasOwnProperty(command)) {
|
||||
if(dbot.db.bans[command].include(user) || dbot.db.bans['*'].include(user)) {
|
||||
banned = true;
|
||||
}
|
||||
}
|
||||
return banned;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is user ignoring command?
|
||||
*/
|
||||
var isIgnoring = function(user, command) {
|
||||
var module = dbot.commandMap[command];
|
||||
var ignoring = false;
|
||||
if(dbot.db.ignores.hasOwnProperty(user) && dbot.db.ignores[user].include(module)) {
|
||||
ignoring = true;
|
||||
}
|
||||
return ignoring;
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply Regex to event message, store result. Return false if it doesn't
|
||||
* apply.
|
||||
*/
|
||||
var applyRegex = function(commandName, event) {
|
||||
var applies = false;
|
||||
if(dbot.commands[commandName].hasOwnProperty('regex')) {
|
||||
var cRegex = dbot.commands[commandName].regex;
|
||||
var q = event.message.valMatch(cRegex[0], cRegex[1]);
|
||||
if(q) {
|
||||
applies = true;
|
||||
event.input = q;
|
||||
}
|
||||
} else {
|
||||
applies = true;
|
||||
}
|
||||
return applies;
|
||||
};
|
||||
|
||||
return {
|
||||
'name': 'command',
|
||||
'ignorable': false,
|
||||
|
||||
'commands': {
|
||||
'~usage': function(event) {
|
||||
var commandName = event.params[1];
|
||||
console.log(commandName);
|
||||
if(dbot.commands.hasOwnProperty(commandName)) {
|
||||
event.reply('Usage for ' + commandName + ': ' +
|
||||
dbot.commands[commandName].usage);
|
||||
} else {
|
||||
event.reply('No usage information for ' + commandName);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Run the appropriate command given the input.
|
||||
*/
|
||||
'listener': function(event) {
|
||||
var commandName = event.params[0];
|
||||
if(!dbot.commands.hasOwnProperty(commandName)) {
|
||||
commandName = '~';
|
||||
}
|
||||
|
||||
if(isBanned(event.user, commandName)) {
|
||||
event.reply(dbot.t('command_ban', {'user': event.user}));
|
||||
} else {
|
||||
if(!isIgnoring(event.user, commandName)) {
|
||||
if(applyRegex(commandName, event)) {
|
||||
dbot.commands[commandName](event);
|
||||
dbot.save();
|
||||
} else {
|
||||
if(commandName !== '~') {
|
||||
if(dbot.commands[commandName].hasOwnProperty('usage')){
|
||||
event.reply('Usage: ' + dbot.commands[commandName].usage);
|
||||
} else {
|
||||
event.reply(dbot.t('syntax_error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'on': 'PRIVMSG'
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return command(dbot);
|
||||
};
|
||||
|
105
modules/dice.js
105
modules/dice.js
@ -1,105 +0,0 @@
|
||||
var parseDiceSpec = function (specString) {
|
||||
var rawSpec = specString.valMatch(/^([0-9]*)d(%|[0-9]*)(|[+-][0-9]+)$/i, 4);
|
||||
if (rawSpec !== false) {
|
||||
if (rawSpec[2] === "%") {
|
||||
rawSpec[2] = 100;
|
||||
}
|
||||
return {
|
||||
"count": parseInt(rawSpec[1] || 1),
|
||||
"sides": parseInt(rawSpec[2] || 6),
|
||||
"modifier": parseInt(rawSpec[3] || 0)
|
||||
};
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var normalizeDiceSpec = function (specString) {
|
||||
var diceSpec = parseDiceSpec(specString);
|
||||
|
||||
if (diceSpec["sides"] > 10000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (diceSpec["count"] > 1000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (diceSpec["count"] > 1) {
|
||||
var count = diceSpec["count"];
|
||||
} else {
|
||||
var count = "";
|
||||
}
|
||||
|
||||
if (diceSpec["sides"] === 100) {
|
||||
var sides = "%";
|
||||
} else {
|
||||
var sides = diceSpec["sides"];
|
||||
}
|
||||
|
||||
if (diceSpec["modifier"] > 0) {
|
||||
var modifier = "+" + diceSpec["modifier"];
|
||||
} else if (diceSpec["modifier"] < 0) {
|
||||
var modifier = diceSpec["modifier"];
|
||||
} else {
|
||||
var modifier = "";
|
||||
}
|
||||
|
||||
return (count + "d" + sides + modifier);
|
||||
};
|
||||
|
||||
var dice = function(dbot) {
|
||||
var commands = {
|
||||
'~roll': function (event) {
|
||||
var rolls = [];
|
||||
|
||||
if (event.params.length === 1) {
|
||||
event.params.push("d6");
|
||||
}
|
||||
|
||||
for (var i = 1; i < event.params.length; i++) {
|
||||
var diceSpec = parseDiceSpec(event.params[i]);
|
||||
if (diceSpec === false) {
|
||||
rolls.push([event.params[i], false]);
|
||||
} else {
|
||||
rolls.push([normalizeDiceSpec(event.params[i]), [], diceSpec["modifier"]]);
|
||||
for (var j = 0; j < diceSpec["count"] ; j++) {
|
||||
rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < rolls.length; i++) {
|
||||
if (rolls[i][1] === false) {
|
||||
event.reply(rolls[i][0] + ": invalid dice spec");
|
||||
} else {
|
||||
if (rolls[i][1].length > 1) {
|
||||
var total = " (total " + rolls[i][1].sum();
|
||||
if (rolls[i][2] != 0) {
|
||||
if (rolls[i][2] > 0) {
|
||||
total += " + ";
|
||||
} else {
|
||||
total += " - ";
|
||||
}
|
||||
total += Math.abs(rolls[i][2]) + " -> " + (rolls[i][1].sum() + rolls[i][2]);
|
||||
}
|
||||
total += ")"
|
||||
} else {
|
||||
var total = "";
|
||||
}
|
||||
event.reply(rolls[i][0] + ": " + rolls[i][1].join(" ") + total);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'name': 'dice',
|
||||
'commands': commands,
|
||||
'ignorable': true
|
||||
};
|
||||
}
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return dice(dbot);
|
||||
};
|
@ -1,96 +0,0 @@
|
||||
/**
|
||||
* Module Name: Drama
|
||||
* Description: Experimental, you probably don't want it.
|
||||
*/
|
||||
var brain = require('brain');
|
||||
|
||||
var drama = function(dbot) {
|
||||
var dbot = dbot;
|
||||
var last = {};
|
||||
var options = {
|
||||
'backend': {
|
||||
'type': 'Redis',
|
||||
'options': {
|
||||
'hostname': 'localhost',
|
||||
'port': 6379,
|
||||
'name': 'dbotdrama'
|
||||
}
|
||||
},
|
||||
|
||||
'thresholds': {
|
||||
'drama': 3,
|
||||
'beinganasshole': 3,
|
||||
'sd': 3, // self depracating
|
||||
'normal': 1
|
||||
},
|
||||
|
||||
'def': 'normal'
|
||||
};
|
||||
var bayes = new brain.BayesianClassifier(options);
|
||||
|
||||
var commands = {
|
||||
'~train': function(event) {
|
||||
if(dbot.admin.include(event.user)) {
|
||||
bayes.train(last[event.params[1]][event.params[2]], event.params[3]);
|
||||
event.reply('Last thing ' + event.params[2] + ' said in ' +
|
||||
event.params[1] + ' (' + last[event.params[1]][event.params[2]] + ') classified as \'' + event.params[3] + '\'');
|
||||
}
|
||||
},
|
||||
|
||||
'~rtrain': function(event) {
|
||||
if(dbot.admin.include(event.user)) {
|
||||
var category = event.params[1];
|
||||
event.params.splice(0, 2);
|
||||
var msg = event.params.join(' ');
|
||||
bayes.train(msg, category);
|
||||
event.reply('\'' + msg + '\' classified as \'' + category + '\'');
|
||||
}
|
||||
},
|
||||
|
||||
'~classify': function(event) {
|
||||
event.params.splice(0, 1);
|
||||
var msg = event.params.join(' ');
|
||||
bayes.classify(msg, function(category) {
|
||||
event.reply('Classified as: ' + category + '!');
|
||||
}.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'name': 'drama',
|
||||
'ignorable': false,
|
||||
'commands': commands,
|
||||
|
||||
'listener': function(data) {
|
||||
var category = bayes.classify(data.message, function(category) {
|
||||
if(category !== 'normal') {
|
||||
if(category === 'beinganasshole') {
|
||||
if(dbot.db.drama.beinganasshole.hasOwnProperty(event.user)) {
|
||||
dbot.db.drama.beinganasshole[event.user]++;
|
||||
} else {
|
||||
dbot.db.drama.beinganasshole[event.user] = 1;
|
||||
}
|
||||
} else if(category === 'sd') {
|
||||
if(dbot.db.drama.sd.hasOwnProperty(event.user)) {
|
||||
dbot.db.drama.sd[event.user]++;
|
||||
} else {
|
||||
dbot.db.drama.sd[event.user] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
if(last.hasOwnProperty(event.channel)) {
|
||||
last[event.channel][event.user] = data.message;
|
||||
} else {
|
||||
last[event.channel] = { };
|
||||
last[event.channel][event.user] = data.message;
|
||||
}
|
||||
},
|
||||
'on': 'PRIVMSG'
|
||||
};
|
||||
}
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return drama(dbot);
|
||||
};
|
@ -1,81 +0,0 @@
|
||||
/**
|
||||
* Module Name: Ignore
|
||||
* Description: Handles commands in which users can choose to ignore listeners
|
||||
* and commands from certain modules. It also populates the JSBot instance with
|
||||
* this information, since that actually performs the ignorance.
|
||||
*/
|
||||
var ignore = function(dbot) {
|
||||
var commands = {
|
||||
'~ignore': function(event) {
|
||||
var ignorableModules = [];
|
||||
for(var i=0;i<dbot.modules.length;i++) {
|
||||
if(dbot.modules[i].ignorable != null && dbot.modules[i].ignorable == true) {
|
||||
ignorableModules.push(dbot.modules[i].name);
|
||||
}
|
||||
}
|
||||
var module = event.params[1];
|
||||
|
||||
if(module === undefined) {
|
||||
event.reply(dbot.t('ignore_usage', {'user': event.user, 'modules': ignorableModules.join(', ')}));
|
||||
} else {
|
||||
if(ignorableModules.include(module)) {
|
||||
if(dbot.db.ignores.hasOwnProperty(event.user) && dbot.db.ignores[event.user].include(module)) {
|
||||
event.reply(dbot.t('already_ignoring', {'user': event.user}));
|
||||
} else {
|
||||
if(dbot.db.ignores.hasOwnProperty(module)) {
|
||||
dbot.db.ignores[event.user].push(module);
|
||||
} else {
|
||||
dbot.db.ignores[event.user] = [module];
|
||||
}
|
||||
|
||||
dbot.instance.ignoreTag(event.user, module);
|
||||
event.reply(dbot.t('ignored', {'user': event.user, 'module': module}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('invalid_ignore', {'user': event.user}));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'~unignore': function(event) {
|
||||
var ignoredModules = [];
|
||||
if(dbot.db.ignores.hasOwnProperty(event.user)) {
|
||||
ignoredModules = dbot.db.ignores[event.user];
|
||||
}
|
||||
var module = event.params[1];
|
||||
|
||||
if(module === undefined) {
|
||||
event.reply(dbot.t('unignore_usage', {'user': event.user, 'modules': ignoredModules.join(', ')}));
|
||||
} else {
|
||||
if(ignoredModules.include(module) == false) {
|
||||
event.reply(dbot.t('invalid_unignore', {'user': event.user}));
|
||||
} else {
|
||||
dbot.db.ignores[event.user].splice(dbot.db.ignores[event.user].indexOf(module), 1);
|
||||
dbot.instance.removeIgnore(event.user, module)
|
||||
event.reply(dbot.t('unignored', {'user': event.user, 'module': module}));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'name': 'ignore',
|
||||
'ignorable': false,
|
||||
'commands': commands,
|
||||
|
||||
'onLoad': function() {
|
||||
dbot.instance.clearIgnores();
|
||||
for(var user in dbot.db.ignores) {
|
||||
if(dbot.db.ignores.hasOwnProperty(user)) {
|
||||
for(var i=0;i<dbot.db.ignores[user].length;i++) {
|
||||
dbot.instance.ignoreTag(user, dbot.db.ignores[user][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return ignore(dbot);
|
||||
};
|
@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Module Name: JS
|
||||
* Description: Allows users to run sandboxed JS code, printing the result in
|
||||
* the channel. Also allows admins to run un-sandboxed Javascript code with
|
||||
* access to the DepressionBot instance memory.
|
||||
*/
|
||||
var vm = require('vm');
|
||||
var sbox = require('sandbox');
|
||||
|
||||
var js = function(dbot) {
|
||||
var s = new sbox();
|
||||
|
||||
var commands = {
|
||||
// Run JS code sandboxed, return result to channel.
|
||||
'~js': function(event) {
|
||||
try {
|
||||
s.run(event.input[1], function(output) {
|
||||
event.reply(output.result);
|
||||
}.bind(this));
|
||||
} catch(err) {}
|
||||
},
|
||||
|
||||
// Run JS code un-sandboxed, with access to DBot memory (admin-only).
|
||||
'~ajs': function(event) {
|
||||
if(dbot.admin.include(event.user) ) {
|
||||
var ret = eval(event.input[1]);
|
||||
if(ret !== undefined) {
|
||||
event.reply(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
commands['~js'].regex = [/^~js (.*)/, 2];
|
||||
commands['~ajs'].regex = [/^~ajs (.*)/, 2];
|
||||
commands['~js'].usage = '~js [command]';
|
||||
commands['~ajs'].usage = '~ajs [command]';
|
||||
|
||||
return {
|
||||
'name': 'js',
|
||||
'ignorable': true,
|
||||
'commands': commands
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return js(dbot);
|
||||
};
|
@ -1,76 +0,0 @@
|
||||
var kick = function(dbot) {
|
||||
var commands = {
|
||||
// Give the number of times a given user has been kicked and has kicked
|
||||
// other people.
|
||||
'~kickcount': function(event) {
|
||||
var username = event.params[1];
|
||||
|
||||
if(!dbot.db.kicks.hasOwnProperty(username)) {
|
||||
var kicks = '0';
|
||||
} else {
|
||||
var kicks = dbot.db.kicks[username];
|
||||
}
|
||||
|
||||
if(!dbot.db.kickers.hasOwnProperty(username)) {
|
||||
var kicked = '0';
|
||||
} else {
|
||||
var kicked = dbot.db.kickers[username];
|
||||
}
|
||||
|
||||
event.reply(dbot.t('user_kicks', {'user': username, 'kicks': kicks, 'kicked': kicked}));
|
||||
},
|
||||
|
||||
// Output a list of the people who have been kicked the most and those
|
||||
// who have kicked other people the most.
|
||||
'~kickstats': function(event) {
|
||||
var orderedKickLeague = function(list, topWhat) {
|
||||
var kickArr = Object.prototype.sort(list, function(key, obj) { return obj[key]; });
|
||||
kickArr = kickArr.slice(kickArr.length - 10).reverse();
|
||||
|
||||
var kickString = "Top " + topWhat + ": ";
|
||||
for(var i=0;i<kickArr.length;i++) {
|
||||
kickString += kickArr[i][0] + " (" + kickArr[i][1] + "), ";
|
||||
}
|
||||
|
||||
return kickString.slice(0, -2);
|
||||
};
|
||||
|
||||
event.reply(orderedKickLeague(dbot.db.kicks, 'Kicked'));
|
||||
event.reply(orderedKickLeague(dbot.db.kickers, 'Kickers'));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'name': 'kick',
|
||||
'ignorable': false,
|
||||
'commands': commands,
|
||||
|
||||
'listener': function(event) {
|
||||
if(event.kickee == dbot.name) {
|
||||
dbot.instance.join(event, event.channel);
|
||||
event.reply(dbot.t('kicked_dbot', {'botname': dbot.name}));
|
||||
dbot.db.kicks[dbot.name] += 1;
|
||||
} else {
|
||||
if(!dbot.db.kicks.hasOwnProperty(event.kickee)) {
|
||||
dbot.db.kicks[event.kickee] = 1;
|
||||
} else {
|
||||
dbot.db.kicks[event.kickee] += 1;
|
||||
}
|
||||
|
||||
if(!dbot.db.kickers.hasOwnProperty(event.user)) {
|
||||
dbot.db.kickers[event.user] = 1;
|
||||
} else {
|
||||
dbot.db.kickers[event.user] += 1;
|
||||
}
|
||||
|
||||
event.reply(event.kickee + '-- (' + dbot.t('user_kicks',
|
||||
{'user': event.kickee, 'kicks': dbot.db.kicks[event.kickee], 'kicked': dbot.db.kickers[event.kickee]}) + ')');
|
||||
}
|
||||
},
|
||||
on: 'KICK'
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return kick(dbot);
|
||||
};
|
@ -1,52 +0,0 @@
|
||||
/**
|
||||
* Module Name: Link
|
||||
* Description: Stores recent channel links, with commands to retrieve
|
||||
* information about links.
|
||||
*/
|
||||
var request = require('request');
|
||||
var link = function(dbot) {
|
||||
var urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||
var links = {};
|
||||
|
||||
var commands = {
|
||||
'~title': function(event) {
|
||||
var link = links[event.channel.name];
|
||||
if(event.params[1] !== undefined) {
|
||||
var urlMatches = event.params[1].match(urlRegex);
|
||||
if(urlMatches !== null) {
|
||||
link = urlMatches[0];
|
||||
}
|
||||
}
|
||||
|
||||
request(link, function (error, response, body) {
|
||||
if(!error && response.statusCode == 200) {
|
||||
body = body.replace(/(\r\n|\n\r|\n)/gm, " ");
|
||||
var title = body.valMatch(/<title>(.*)<\/title>/, 2);
|
||||
if(title) {
|
||||
event.reply(title[1]);
|
||||
} else {
|
||||
event.reply('no title found');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'name': 'link',
|
||||
'ignorable': true,
|
||||
'commands': commands,
|
||||
|
||||
'listener': function(event) {
|
||||
var urlMatches = event.message.match(urlRegex);
|
||||
if(urlMatches !== null) {
|
||||
links[event.channel.name] = urlMatches[0];
|
||||
}
|
||||
},
|
||||
'on': 'PRIVMSG'
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return link(dbot);
|
||||
};
|
233
modules/poll.js
233
modules/poll.js
@ -1,233 +0,0 @@
|
||||
var poll = function(dbot) {
|
||||
var polls = dbot.db.polls;
|
||||
var commands = {
|
||||
'~newpoll': function(event) {
|
||||
var av = event.input[1] != undefined;
|
||||
var name = event.input[2];
|
||||
var options = event.input[3].split(',');
|
||||
var description = event.input[4];
|
||||
|
||||
if(name === undefined || name === 'help') {
|
||||
event.reply(dbot.t('newpoll_usage'));
|
||||
} else {
|
||||
if(polls.hasOwnProperty(name)) {
|
||||
event.reply(dbot.t('poll_exists', {'name': name}));
|
||||
} else {
|
||||
if(av) {
|
||||
polls[name] = {
|
||||
'av': av,
|
||||
'name': name,
|
||||
'description': description,
|
||||
'owner': event.user,
|
||||
'votes': {},
|
||||
'options': []
|
||||
};
|
||||
for(var i=0;i<options.length;i++) {
|
||||
polls[name].options.push(options[i]);
|
||||
}
|
||||
} else {
|
||||
polls[name] = {
|
||||
'av': av,
|
||||
'name': name,
|
||||
'description': description,
|
||||
'owner': event.user,
|
||||
'votes': {},
|
||||
'votees': {}
|
||||
};
|
||||
for(var i=0;i<options.length;i++) {
|
||||
polls[name]['votes'][options[i]] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
event.reply(dbot.t('poll_created', {'name': name, 'description': description,
|
||||
'url': dbot.t('url', {'host': dbot.webHost, 'port': dbot.webPort, 'path': 'polls/' + name})}));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'~addoption': function(event) {
|
||||
var name = event.input[1];
|
||||
var option = event.input[2];
|
||||
|
||||
if(polls.hasOwnProperty(name)) {
|
||||
if(polls[name].owner === event.user) {
|
||||
if(!polls[name].votes.hasOwnProperty(name)) {
|
||||
polls[name]['votes'][option] = 0;
|
||||
event.reply(dbot.t('option_added', {'user': event.user,
|
||||
'name': name, 'option': option}));
|
||||
} else {
|
||||
event.reply(dbot.t('option_exists', {'option': option,
|
||||
'name': name, 'user': event.user}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('not_poll_owner', {'user': event.user,
|
||||
'name': name}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('poll_unexistent', {'name': name}));
|
||||
}
|
||||
},
|
||||
|
||||
'~rmoption': function(event) {
|
||||
var name = event.input[1];
|
||||
var option = event.input[2];
|
||||
|
||||
if(polls.hasOwnProperty(name)) {
|
||||
if(polls[name].owner === event.user) {
|
||||
if(polls[name].votes.hasOwnProperty(option)) {
|
||||
delete polls[name]['votes'][option];
|
||||
event.reply(dbot.t('option_removed', {'user': event.user,
|
||||
'name': name, 'option': option}));
|
||||
} else {
|
||||
event.reply(dbot.t('invalid_vote', {'vote': option}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('not_poll_owner', {'name': name}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('poll_unexistent', {'name': name}));
|
||||
}
|
||||
},
|
||||
|
||||
'~vote': function(event) {
|
||||
var name = event.input[1];
|
||||
var vote = event.input[2];
|
||||
|
||||
if(polls.hasOwnProperty(name)) {
|
||||
if(polls[name].av) {
|
||||
var prefs = vote.split(',');
|
||||
prefs = prefs.uniq();
|
||||
var valid = true;
|
||||
|
||||
prefs.each(function(pref) {
|
||||
valid = valid && polls[name].options.indexOf(pref) != -1;
|
||||
});
|
||||
if(valid){
|
||||
if(polls[name].votes.hasOwnProperty(event.user)) {
|
||||
polls[name].votes[event.user] = prefs;
|
||||
event.reply(dbot.t('av_changed_vote', {'vote': prefs.join(','), 'poll': name, 'user': event.user}));
|
||||
} else {
|
||||
polls[name].votes[event.user] = prefs;
|
||||
event.reply(dbot.t('av_voted', {'vote': prefs.join(','), 'poll': name, 'user': event.user}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('invalid_vote', {'vote': vote}));
|
||||
}
|
||||
} else {
|
||||
if(polls[name].votes.hasOwnProperty(vote)) {
|
||||
if(polls[name].votees.hasOwnProperty(event.user)) {
|
||||
var oldVote = polls[name].votees[event.user];
|
||||
polls[name].votes[oldVote]--;
|
||||
polls[name].votes[vote]++;
|
||||
polls[name].votees[event.user] = vote;
|
||||
event.reply(dbot.t('changed_vote', {'vote': vote, 'poll': name,
|
||||
'count': polls[name].votes[vote], 'user': event.user}));
|
||||
} else {
|
||||
polls[name].votes[vote]++;
|
||||
polls[name].votees[event.user] = vote;
|
||||
event.reply(dbot.t('voted', {'vote': vote, 'poll': name,
|
||||
'count': polls[name].votes[vote], 'user': event.user}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('invalid_vote', {'vote': vote}));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('poll_unexistent', {'name': name}));
|
||||
}
|
||||
},
|
||||
|
||||
'~pdesc': function(event) {
|
||||
var name = event.input[1];
|
||||
if(polls.hasOwnProperty(name)) {
|
||||
event.reply(dbot.t('poll_describe', {'name': name, 'description': polls[name].description,
|
||||
'url': dbot.t('url', {'host': dbot.webHost, 'port': dbot.webPort, 'path': 'polls/' + name})}));
|
||||
} else {
|
||||
event.reply(dbot.t('poll_unexistent', {'name': name}));
|
||||
}
|
||||
},
|
||||
|
||||
'~count': function(event) {
|
||||
var name = event.input[1];
|
||||
|
||||
if(polls.hasOwnProperty(name)) {
|
||||
var order;
|
||||
if(polls[name].av) {
|
||||
var finished = false;
|
||||
var rounds = [];
|
||||
var eliminated = [];
|
||||
var voted;
|
||||
|
||||
for(var roundn = 0; roundn < polls[name].options.length; roundn++) {
|
||||
var roundLoser;
|
||||
|
||||
// Populate candidates for this round
|
||||
rounds[roundn] = {};
|
||||
polls[name].options.each(function (option) {
|
||||
if(eliminated.indexOf(option) == -1)
|
||||
rounds[roundn][option] = 0;
|
||||
});
|
||||
|
||||
// Count votes
|
||||
polls[name].votes.withAll(function (name, vote) {
|
||||
voted = false;
|
||||
vote.each(function (pref) {
|
||||
if(!voted && rounds[roundn].hasOwnProperty(pref)) {
|
||||
rounds[roundn][pref]++;
|
||||
voted = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Find the loser
|
||||
var min = polls[name].votes.length() + 1;
|
||||
rounds[roundn].withAll(function (option, count) {
|
||||
if(count < min) {
|
||||
roundLoser = option;
|
||||
min = count;
|
||||
}
|
||||
});
|
||||
|
||||
// Eliminate loser
|
||||
eliminated.push(roundLoser);
|
||||
}
|
||||
order = eliminated.reverse().join(', ')
|
||||
} else {
|
||||
var votesArr = [];
|
||||
polls[name].votes.withAll(function(option, count) {
|
||||
votesArr.push([option, count]);
|
||||
});
|
||||
|
||||
votesArr = votesArr.sort(function(a, b) { return b[1] - a[1]; });
|
||||
|
||||
order = votesArr.map(function(vote) { return vote[0]; });
|
||||
}
|
||||
event.reply(dbot.t('count', {'poll': name, 'description': polls[name].description, 'places': order}));
|
||||
} else {
|
||||
event.reply(dbot.t('poll_unexistent', {'name': name}));
|
||||
}
|
||||
}
|
||||
};
|
||||
commands['~newpoll'].regex = [/~newpoll (av )?([^ ]+) options=([^ ]+) (.+)/, 5];
|
||||
commands['~addoption'].regex = [/~addoption ([^ ]+) ([^ ]+)/, 3];
|
||||
commands['~rmoption'].regex = [/~rmoption ([^ ]+) ([^ ]+)/, 3];
|
||||
commands['~vote'].regex = [/~vote ([^ ]+) ([^ ]+)/, 3];
|
||||
commands['~pdesc'].regex = [/~pdesc ([^ ]+)/, 2];
|
||||
commands['~count'].regex = [/~count ([^ ]+)/, 2];
|
||||
|
||||
commands['~newpoll'].usage = '~newpoll [pollname] options=[each,poll,option] [Poll Description]';
|
||||
commands['~addoption'].usage = '~addoption [pollname] [newoption]';
|
||||
commands['~rmoption'].usage= '~rmoption [pollname] [optiontoremove]';
|
||||
commands['~vote'].usage= '~vote [pollname] [option]';
|
||||
commands['~pdesc'].usage = '~pdesc [pollname]';
|
||||
|
||||
return {
|
||||
'name': 'poll',
|
||||
'ignorable': true,
|
||||
'commands': commands
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return poll(dbot);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
var puns = function(dbot) {
|
||||
var name = 'puns';
|
||||
var dbot = dbot;
|
||||
|
||||
return {
|
||||
'name': name,
|
||||
'ignorable': true,
|
||||
|
||||
'listener': function(event) {
|
||||
event.user = dbot.cleanNick(event.user);
|
||||
if(dbot.moduleNames.include('quotes') &&
|
||||
dbot.db.quoteArrs.hasOwnProperty(event.user)) {
|
||||
event.message = '~q ' + event.user;
|
||||
event.action = 'PRIVMSG';
|
||||
event.params = event.message.split(' ');
|
||||
dbot.instance.emit(event);
|
||||
}
|
||||
},
|
||||
'on': 'JOIN'
|
||||
};
|
||||
}
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return puns(dbot);
|
||||
};
|
@ -1,276 +0,0 @@
|
||||
var quotes = function(dbot) {
|
||||
var name = 'quotes';
|
||||
var quotes = dbot.db.quoteArrs;
|
||||
var addStack = [];
|
||||
var rmAllowed = true;
|
||||
|
||||
// Retrieve a random quote from a given category, interpolating any quote
|
||||
// references (~~QUOTE CATEGORY~~) within it
|
||||
var interpolatedQuote = function(key, quoteTree) {
|
||||
if(quoteTree !== undefined && quoteTree.indexOf(key) != -1) {
|
||||
return '';
|
||||
} else if(quoteTree === undefined) {
|
||||
quoteTree = [];
|
||||
}
|
||||
|
||||
var quoteString = quotes[key].random();
|
||||
|
||||
// Parse quote interpolations
|
||||
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
|
||||
var thisRef;
|
||||
|
||||
while(quoteRefs && (thisRef = quoteRefs.shift()) !== undefined) {
|
||||
var cleanRef = dbot.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
|
||||
if (quotes.hasOwnProperty(cleanRef)) {
|
||||
quoteTree.push(key);
|
||||
quoteString = quoteString.replace("~~" + cleanRef + "~~",
|
||||
interpolatedQuote(cleanRef, quoteTree.slice()));
|
||||
quoteTree.pop();
|
||||
}
|
||||
}
|
||||
|
||||
return quoteString;
|
||||
};
|
||||
|
||||
var commands = {
|
||||
// Alternative syntax to ~q
|
||||
'~': function(event) {
|
||||
commands['~q'](event);
|
||||
},
|
||||
|
||||
// Retrieve quote from a category in the database.
|
||||
'~q': function(event) {
|
||||
var key = event.input[1].trim().toLowerCase();
|
||||
var altKey;
|
||||
if(key.split(' ').length > 0) {
|
||||
altKey = key.replace(/ /g, '_');
|
||||
}
|
||||
|
||||
if(key.charAt(0) !== '_') { // lol
|
||||
if(quotes.hasOwnProperty(key)) {
|
||||
event.reply(key + ': ' + interpolatedQuote(key));
|
||||
} else if(quotes.hasOwnProperty(altKey)) {
|
||||
event.reply(altKey + ': ' + interpolatedQuote(altKey));
|
||||
} else {
|
||||
event.reply(dbot.t('category_not_found', {'category': key}));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Shows a list of the biggest categories
|
||||
'~qstats': function(event) {
|
||||
var qSizes = Object.prototype.sort(quotes, function(key, obj) { return obj[key].length });
|
||||
qSizes = qSizes.slice(qSizes.length - 10).reverse();
|
||||
|
||||
var qString = dbot.t('large_categories');
|
||||
for(var i=0;i<qSizes.length;i++) {
|
||||
qString += qSizes[i][0] + " (" + qSizes[i][1] + "), ";
|
||||
}
|
||||
|
||||
event.reply(qString.slice(0, -2));
|
||||
},
|
||||
|
||||
// Search a given category for some text.
|
||||
'~qsearch': function(event) {
|
||||
var haystack = event.input[1].trim().toLowerCase();
|
||||
var needle = event.input[2];
|
||||
if(quotes.hasOwnProperty(haystack)) {
|
||||
var matches = [];
|
||||
quotes[haystack].each(function(quote) {
|
||||
if(quote.indexOf(needle) != -1) {
|
||||
matches.push(quote);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
if(matches.length == 0) {
|
||||
event.reply(dbot.t('no_results'));
|
||||
} else {
|
||||
event.reply(dbot.t('search_results', {'category': haystack, 'needle': needle,
|
||||
'quote': matches.random(), 'matches': matches.length}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('empty_category'));
|
||||
}
|
||||
},
|
||||
|
||||
'~rmlast': function(event) {
|
||||
if(rmAllowed == true || dbot.admin.include(event.user)) {
|
||||
var key = event.input[1].trim().toLowerCase();
|
||||
if(quotes.hasOwnProperty(key)) {
|
||||
if(!dbot.db.locks.include(key) || dbot.admin.include(event.user)) {
|
||||
var quote = quotes[key].pop();
|
||||
if(quotes[key].length === 0) {
|
||||
delete quotes[key];
|
||||
}
|
||||
rmAllowed = false;
|
||||
event.reply(dbot.t('removed_from', {'quote': quote, 'category': key}));
|
||||
} else {
|
||||
event.reply(dbot.t('locked_category', {'category': q[1]}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('no_quotes', {'category': q[1]}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('rmlast_spam'));
|
||||
}
|
||||
},
|
||||
|
||||
'~rm': function(event) {
|
||||
if(rmAllowed == true || dbot.admin.include(event.user)) {
|
||||
var key = event.input[1].trim().toLowerCase();
|
||||
var quote = event.input[2];
|
||||
|
||||
if(quotes.hasOwnProperty(key)) {
|
||||
if(!dbot.db.locks.include(key)) {
|
||||
var category = quotes[key];
|
||||
var index = category.indexOf(quote);
|
||||
if(index !== -1) {
|
||||
category.splice(index, 1);
|
||||
if(category.length === 0) {
|
||||
delete quotes[key];
|
||||
}
|
||||
event.reply(dbot.t('removed_from', {'category': key, 'quote': quote}));
|
||||
} else {
|
||||
event.reply(dbot.t('q_not_exist_under', {'category': key, 'quote': quote}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('locked_category', {'category': key}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('category_not_found', {'category': key}));
|
||||
}
|
||||
} else {
|
||||
event.reply(dbot.t('rmlast_spam'));
|
||||
}
|
||||
},
|
||||
|
||||
'~qcount': function(event) {
|
||||
var input = event.message.valMatch(/^~qcount ([\d\w\s-]*)/, 2);
|
||||
if(input) { // Give quote count for named category
|
||||
var key = input[1].trim().toLowerCase();
|
||||
if(quotes.hasOwnProperty(key)) {
|
||||
event.reply(dbot.t('quote_count', {'category': key, 'count': quotes[key].length}));
|
||||
} else {
|
||||
event.reply(dbot.t('no_quotes', {'category': key}));
|
||||
}
|
||||
} else { // Give total quote count
|
||||
var totalQuoteCount = 0;
|
||||
for(var category in quotes) {
|
||||
totalQuoteCount += category.length;
|
||||
}
|
||||
event.reply(dbot.t('total_quotes', {'count': totalQuoteCount}));
|
||||
}
|
||||
},
|
||||
|
||||
'~qadd': function(event) {
|
||||
var key = event.input[1].toLowerCase();
|
||||
var text = event.input[2];
|
||||
if(!Object.isArray(quotes[key])) {
|
||||
quotes[key] = [];
|
||||
}
|
||||
|
||||
if(quotes[key].include(text)) {
|
||||
event.reply(dbot.t('quote_exists'));
|
||||
} else {
|
||||
quotes[key].push(text);
|
||||
rmAllowed = true;
|
||||
event.reply(dbot.t('quote_saved', {'category': key, 'count': quotes[key].length}));
|
||||
}
|
||||
},
|
||||
|
||||
'~rq': function(event) {
|
||||
var rQuote = Object.keys(quotes).random();
|
||||
event.reply(rQuote + ': ' + interpolatedQuote(rQuote));
|
||||
},
|
||||
|
||||
'~link': function(event) {
|
||||
var key = event.params[1].trim().toLowerCase();
|
||||
if(quotes.hasOwnProperty(key)) {
|
||||
event.reply(dbot.t('quote_link', {'category': key,
|
||||
'url': dbot.t('url', {'host': dbot.webHost,
|
||||
'port': dbot.webPort, 'path': 'quotes/' + key})}));
|
||||
} else {
|
||||
event.reply(dbot.t('category_not_found'));
|
||||
}
|
||||
},
|
||||
|
||||
'~qprune': function(event) {
|
||||
var pruned = []
|
||||
for(key in quotes) {
|
||||
if(quotes.hasOwnProperty(key)) {
|
||||
if(quotes[key].length == 0) {
|
||||
delete quotes[key];
|
||||
pruned.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(pruned.length > 0) {
|
||||
event.reply(dbot.t('prune', {'categories': pruned.join(", ")}));
|
||||
} else {
|
||||
event.reply(dbot.t('no_prune'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
commands['~'].regex = [/^~([\d\w\s-]*)/, 2];
|
||||
commands['~q'].regex = [/^~q ([\d\w\s-]*)/, 2];
|
||||
commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
|
||||
commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
|
||||
commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2];
|
||||
commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
|
||||
|
||||
commands['~q'].usage = '~q [category]';
|
||||
commands['~qsearch'].usage = '~qsearch [category]=[search]';
|
||||
commands['~rm'].usage = '~rm [category]=[quote to delete]';
|
||||
commands['~rmlast'].usage = '~rmlast [category]'
|
||||
commands['~qadd'].usage = '~qadd [category]=[content]';
|
||||
|
||||
return {
|
||||
'name': 'quotes',
|
||||
'ignorable': true,
|
||||
'commands': commands,
|
||||
|
||||
'onLoad': function() {
|
||||
dbot.timers.addTimer(1000 * 60 * 3, function() {
|
||||
rmAllowed = true;
|
||||
});
|
||||
},
|
||||
|
||||
'listener': function(event) {
|
||||
if((dbot.db.ignores.hasOwnProperty(event) &&
|
||||
dbot.db.ignores[event.user].include(name)) == false) {
|
||||
if(event.user == 'reality') {
|
||||
var once = event.message.valMatch(/^I ([\d\w\s,'-]* once)/, 2);
|
||||
} else {
|
||||
var once = event.message.valMatch(/^reality ([\d\w\s,'-]* once)/, 2);
|
||||
}
|
||||
|
||||
if(once) {
|
||||
if((dbot.db.bans.hasOwnProperty('~qadd') &&
|
||||
dbot.db.bans['~qadd'].include(event.user)) ||
|
||||
dbot.db.bans['*'].include(event.user)) {
|
||||
event.reply(dbot.t('command_ban', {'user': event.user}));
|
||||
} else {
|
||||
if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) {
|
||||
dbot.db.quoteArrs['realityonce'] = [];
|
||||
}
|
||||
if(dbot.db.quoteArrs['realityonce'].include('reality ' + once[1] + '.')) {
|
||||
event.reply(event.user + ': reality has already done that once.');
|
||||
} else {
|
||||
dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.');
|
||||
addStack.push('realityonce');
|
||||
rmAllowed = true;
|
||||
event.reply('\'reality ' + once[1] + '.\' saved.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'on': 'PRIVMSG'
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return quotes(dbot);
|
||||
};
|
@ -237,6 +237,7 @@ var quotes = function(dbot) {
|
||||
},
|
||||
|
||||
'listener': function(event) {
|
||||
// Reality Once listener
|
||||
if((dbot.db.ignores.hasOwnProperty(event) &&
|
||||
dbot.db.ignores[event.user].include(name)) == false) {
|
||||
if(event.user == 'reality') {
|
||||
|
@ -1,52 +0,0 @@
|
||||
var report = function(dbot) {
|
||||
var commands = {
|
||||
'~report': function(event) {
|
||||
var channelName = event.input[1];
|
||||
var nick = event.input[2];
|
||||
var reason = event.input[3];
|
||||
|
||||
if(event.allChannels.hasOwnProperty(channelName)) {
|
||||
var channel = event.allChannels[channelName];
|
||||
if(channel.nicks.hasOwnProperty(nick)) {
|
||||
var ops = [];
|
||||
for(var possibOps in channel.nicks) {
|
||||
if(channel.nicks[possibOps].op == true) {
|
||||
ops.push(possibOps);
|
||||
}
|
||||
}
|
||||
|
||||
// Does the channel have an admin channel?
|
||||
if(event.allChannels.hasOwnProperty('#' + channelName)) {
|
||||
ops.push('#' + channelName);
|
||||
}
|
||||
|
||||
for(var i=0;i<ops.length;i++) {
|
||||
dbot.say(event.server, ops[i],
|
||||
'Attention: ' + event.user + ' has reported ' +
|
||||
nick + ' in ' + channelName + '. The reason ' +
|
||||
'given was: "' + reason + '."');
|
||||
}
|
||||
|
||||
event.reply('Thank you, ' + nick + ' has been reported the channel administrators.');
|
||||
} else {
|
||||
event.reply('User is not in that channel.');
|
||||
}
|
||||
} else {
|
||||
event.reply('I am not in that channel.');
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
commands['~report'].regex = [/^~report ([^ ]+) ([^ ]+) (.+)$/, 4];
|
||||
commands['~report'].usage = '~report [#channel] [username] [reason for reporting]';
|
||||
|
||||
return {
|
||||
'name': 'report',
|
||||
'ignorable': true,
|
||||
'commands': commands
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return report(dbot);
|
||||
};
|
@ -1,68 +0,0 @@
|
||||
var spelling = function(dbot) {
|
||||
var last = {};
|
||||
|
||||
var correct = function (event, correction, candidate, output_callback) {
|
||||
var rawCandidates = last[event.channel.name][candidate].split(' ').allGroupings();
|
||||
var candidates = [];
|
||||
for(var i=0;i<rawCandidates.length;i++) {
|
||||
candidates.push(rawCandidates[i].join(' '));
|
||||
}
|
||||
var winner = false;
|
||||
var winnerDistance = Infinity;
|
||||
|
||||
for(var i=0;i<candidates.length;i++) {
|
||||
var distance = String.prototype.distance(correction.toLowerCase(), candidates[i].toLowerCase());
|
||||
if((distance < winnerDistance) && (distance > 0)) {
|
||||
winner = candidates[i];
|
||||
winnerDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
if(winnerDistance < Math.ceil(winner.length * 1.33)) {
|
||||
if(winner !== correction) {
|
||||
var fix = last[event.channel.name][candidate].replace(winner, correction);
|
||||
if (/^.ACTION/.test(fix)) {
|
||||
fix = fix.replace(/^.ACTION/, '/me');
|
||||
}
|
||||
last[event.channel.name][candidate] = fix;
|
||||
var output = {
|
||||
'fix': fix,
|
||||
'correcter': event.user,
|
||||
'candidate': candidate
|
||||
};
|
||||
output_callback(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'name': 'spelling',
|
||||
'ignorable': true,
|
||||
|
||||
'listener': function(event) {
|
||||
var q = event.message.valMatch(/^(?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 3);
|
||||
var otherQ = event.message.valMatch(/^([\d\w\s]*): (?:\*\*?([\d\w\s']*)|([\d\w\s']*)\*\*?)$/, 4);
|
||||
if(q) {
|
||||
correct(event, q[1] || q[2], event.user, function (e) {
|
||||
event.reply(dbot.t('spelling_self', e));
|
||||
});
|
||||
} else if(otherQ) {
|
||||
correct(event, otherQ[2] || otherQ[3], otherQ[1], function (e) {
|
||||
event.reply(dbot.t('spelling_other', e));
|
||||
});
|
||||
} else {
|
||||
if(last.hasOwnProperty(event.channel.name)) {
|
||||
last[event.channel.name][event.user] = event.message;
|
||||
} else {
|
||||
last[event.channel.name] = { };
|
||||
last[event.channel.name][event.user] = event.message;
|
||||
}
|
||||
}
|
||||
},
|
||||
'on': 'PRIVMSG'
|
||||
}
|
||||
}
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return spelling(dbot);
|
||||
};
|
130
modules/web.js
130
modules/web.js
@ -1,130 +0,0 @@
|
||||
var express = require('express');
|
||||
|
||||
var webInterface = function(dbot) {
|
||||
var pub = 'public';
|
||||
var app = express.createServer();
|
||||
|
||||
app.use(express.compiler({ src: pub, enable: ['sass'] }));
|
||||
app.use(express.static(pub));
|
||||
app.set('view engine', 'jade');
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.render('index', { 'name': dbot.name });
|
||||
});
|
||||
|
||||
app.get('/connections', function(req, res) {
|
||||
var connections = Object.keys(dbot.instance.connections);
|
||||
res.render('connections', { 'name': dbot.name, 'connections': connections });
|
||||
});
|
||||
|
||||
app.get('/channels/:connection', function(req, res) {
|
||||
var connection = req.params.connection;
|
||||
if(dbot.instance.connections.hasOwnProperty(connection)) {
|
||||
var channels = Object.keys(dbot.instance.connections[connection].channels);
|
||||
res.render('channels', { 'name': dbot.name, 'connection': connection, 'channels': channels});
|
||||
} else {
|
||||
res.render('error', { 'name': dbot.name, 'message': 'No such connection.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/users/:connection/:channel', function(req, res) {
|
||||
var connection = req.params.connection;
|
||||
var channel = '#' + req.params.channel;
|
||||
var connections = dbot.instance.connections;
|
||||
|
||||
if(connections.hasOwnProperty(connection) &&
|
||||
connections[connection].channels.hasOwnProperty(channel)) {
|
||||
var nicks = Object.keys(connections[connection].channels[channel].nicks);
|
||||
res.render('users', { 'name': dbot.name, 'connection': connection,
|
||||
'channel': channel, 'nicks': nicks });
|
||||
} else {
|
||||
res.render('error', { 'name': dbot.name, 'message': 'No such connection or channel.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/user/:connection/:channel/:user', function(req, res) {
|
||||
var connection = req.params.connection;
|
||||
var channel = '#' + req.params.channel;
|
||||
var user = dbot.cleanNick(req.params.user);
|
||||
|
||||
var quoteCount = 'no';
|
||||
if(dbot.db.quoteArrs.hasOwnProperty(user)) {
|
||||
var quoteCount = dbot.db.quoteArrs[user].length;
|
||||
}
|
||||
|
||||
if(!dbot.db.kicks.hasOwnProperty(req.params.user)) {
|
||||
var kicks = '0';
|
||||
} else {
|
||||
var kicks = dbot.db.kicks[req.params.user];
|
||||
}
|
||||
|
||||
if(!dbot.db.kickers.hasOwnProperty(req.params.user)) {
|
||||
var kicked = '0';
|
||||
} else {
|
||||
var kicked = dbot.db.kickers[req.params.user];
|
||||
}
|
||||
|
||||
res.render('user', { 'name': dbot.name, 'user': req.params.user,
|
||||
'channel': channel, 'connection': connection, 'cleanUser': user,
|
||||
'quotecount': quoteCount, 'kicks': kicks, 'kicked': kicked });
|
||||
});
|
||||
|
||||
// Lists the quote categories
|
||||
app.get('/quotes', function(req, res) {
|
||||
res.render('quotelist', { 'name': dbot.name, 'quotelist': Object.keys(dbot.db.quoteArrs) });
|
||||
});
|
||||
|
||||
// Lists quotes in a category
|
||||
app.get('/quotes/:key', function(req, res) {
|
||||
var key = req.params.key.toLowerCase();
|
||||
if(dbot.db.quoteArrs.hasOwnProperty(key)) {
|
||||
res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[key], locals: { 'url_regex': RegExp.prototype.url_regex() } });
|
||||
} else {
|
||||
res.render('error', { 'name': dbot.name, 'message': 'No quotes under that key.' });
|
||||
}
|
||||
});
|
||||
|
||||
// Load random quote category page
|
||||
app.get('/rq', function(req, res) {
|
||||
var rCategory = Object.keys(dbot.db.quoteArrs).random();
|
||||
res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } });
|
||||
});
|
||||
|
||||
// Lists all of the polls
|
||||
app.get('/polls', function(req, res) {
|
||||
res.render('polllist', { 'name': dbot.name, 'polllist': Object.keys(dbot.db.polls) });
|
||||
});
|
||||
|
||||
// Shows the results of a poll
|
||||
app.get('/polls/:key', function(req, res) {
|
||||
var key = req.params.key.toLowerCase();
|
||||
if(dbot.db.polls.hasOwnProperty(key) && dbot.db.polls[key].hasOwnProperty('description')) {
|
||||
// tally the votes
|
||||
var totalVotes = 0;
|
||||
for( var v in dbot.db.polls[key].votes ) {
|
||||
var N = Number(dbot.db.polls[key].votes[v]);
|
||||
if( !isNaN(N) ) {
|
||||
totalVotes += N;
|
||||
}
|
||||
}
|
||||
res.render('polls', { 'name': dbot.name, 'description': dbot.db.polls[key].description, 'votees': Object.keys(dbot.db.polls[key].votees), 'options': dbot.db.polls[key].votes, locals: { 'totalVotes': totalVotes, 'url_regex': RegExp.prototype.url_regex() } });
|
||||
} else {
|
||||
res.render('error', { 'name': dbot.name, 'message': 'No polls under that key.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(dbot.webPort);
|
||||
|
||||
return {
|
||||
'name': 'web',
|
||||
'ignorable': false,
|
||||
|
||||
'onDestroy': function() {
|
||||
app.close();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return webInterface(dbot);
|
||||
};
|
@ -1,19 +0,0 @@
|
||||
var youAre = function(dbot) {
|
||||
return {
|
||||
'name': 'youare',
|
||||
'ignorable': false,
|
||||
|
||||
'listener': function(event) {
|
||||
var key = event.message.valMatch(/(\bis\b|\bare\b)\s+([\w\s\d]*?)(\s+)?(,|\.|\band\b|$)/, 5);
|
||||
|
||||
if(key && key[2] != "" && Number.prototype.chanceIn(1, 100) && event.user != 'aisbot') {
|
||||
event.reply(event.user + ': You\'re ' + key[2] + '.');
|
||||
}
|
||||
},
|
||||
'on': 'PRIVMSG'
|
||||
};
|
||||
};
|
||||
|
||||
exports.fetch = function(dbot) {
|
||||
return youAre(dbot);
|
||||
};
|
79
strings.json
79
strings.json
@ -130,73 +130,6 @@
|
||||
"spanish": "¿Querías decir: ",
|
||||
"na'vi": "Srake sweylu nga pamrel sivi: ",
|
||||
"welsh": "A oeddech chi'n feddwl: "
|
||||
},
|
||||
"gpull": {
|
||||
"english": "Git pulled that shit.",
|
||||
"spanish": "Hecho git pull en esta mierda.",
|
||||
"na'vi": "Gìtìl fì'uti stamarsìm.",
|
||||
"welsh": "Wedi tynnu git yr cach na i gyd"
|
||||
},
|
||||
"reload": {
|
||||
"english": "Reloaded that shit.",
|
||||
"spanish": "Recargado esta mierda.",
|
||||
"na'vi": "Oel fìuti stìyeftxaw.",
|
||||
"welsh": "Ail-lwytho'r cach na"
|
||||
},
|
||||
"load_module": {
|
||||
"english": "Loaded new module: {moduleName}",
|
||||
"spanish": "Cargado módulo nuevo: {moduleName}",
|
||||
"na'vi": "Oel {moduleName}it amip stìyeftxaw.",
|
||||
"welsh": "Wedi llwytho modiwl newydd: {moduleName}"
|
||||
},
|
||||
"unload_module": {
|
||||
"english": "Turned off module: {moduleName}",
|
||||
"spanish": "Descargado módulo: {moduleName}",
|
||||
"na'vi": "Oel {moduleName} tswìya'.",
|
||||
"welsh": "Wedi troi ffwrdd y modiwl: {moduleName}"
|
||||
},
|
||||
"unload_error": {
|
||||
"english": "{moduleName} isn't loaded. Idiot.",
|
||||
"spanish": "{moduleName} no está cargado. Idiota.",
|
||||
"na'vi": "Oel {moduleName}it omum. Nga skxawng lu.",
|
||||
"welsh": "Di {moduleName} ddim wedi llwytho. Twpsyn"
|
||||
},
|
||||
"banned": {
|
||||
"english": "{user} banned from {command}",
|
||||
"spanish": "{user} está prohibido de usar {command}",
|
||||
"na'vi": "{command}ìri {user} ke tung.",
|
||||
"welsh": "{user} wedi ei gohurio o {command}"
|
||||
},
|
||||
"unbanned": {
|
||||
"english": "{user} unbanned from {command}",
|
||||
"spanish": "{user} no está prohibido de user {command}",
|
||||
"na'vi": "{command}ìri {user} tung set.",
|
||||
"welsh": "{user} wedi ei dad-wahardd o {command}"
|
||||
},
|
||||
"unban_error": {
|
||||
"english": "{user} wasn't banned from that command, fool.",
|
||||
"spanish": "{user} no fue prohibido de esta instrucción, tont@.",
|
||||
"na'vi": "{user} fìtsu'oti tamung srekrr, nga skxawng lu.",
|
||||
"welsh": "Nid oedd {user} wedi ei wahardd o'r gyrchymun yna, fŵl"
|
||||
},
|
||||
"modehate": {
|
||||
"english": "Hating on {user}",
|
||||
"spanish": "Odiando a {user}",
|
||||
"na'vi": "Oel {user}it vere'kì.",
|
||||
"welsh": "Casau ar {user}"
|
||||
},
|
||||
"unmodehate": {
|
||||
"english": "No longer hating on {user}",
|
||||
"spanish": "Ni siquera odiando a {user}",
|
||||
"na'vi": "Oel {user}it ke vere'kì.",
|
||||
"welsh": "Ddim yn casau ar {user} bellach"
|
||||
},
|
||||
"qlock": {
|
||||
"english": "Locked quote category: {category}",
|
||||
"spanish": "Cerrado la categoría: {category}",
|
||||
"na'vi": "{category}ìri oel 'upxareti fmoli",
|
||||
"welsh": "Categori wedi cloi: {category}"
|
||||
},
|
||||
"spelling_self": {
|
||||
"english": "{correcter} meant: {fix}",
|
||||
"spanish": "{correcter} quería decir: {fix}",
|
||||
@ -287,18 +220,6 @@
|
||||
"na'vi": "{category} ({needle}): '{quote}' [kum a{matches}]",
|
||||
"welsh": "{category} ({needle}): '{quote}' [{matches} canlyniad]"
|
||||
},
|
||||
"join": {
|
||||
"english": "Joined {channel}",
|
||||
"spanish" : "Entrado en {channel}",
|
||||
"na'vi": "fpxäkìm {channel}(nemfa)",
|
||||
"welsh": "Wedi ymuno {channel}"
|
||||
},
|
||||
"part": {
|
||||
"english": "Left {channel}",
|
||||
"spanish" : "Abandonada {channel}",
|
||||
"na'vi": "Hum {channel}",
|
||||
"welsh": "Wedi gadael {channel}"
|
||||
},
|
||||
"newpoll_usage": {
|
||||
"english": "Usage: ~newpoll name [options=opt1,opt2,opt3] description",
|
||||
"spanish" : "Modo de empleo: ~newpoll nombre [options=opción1,opción2,opción3] descripción",
|
||||
|
Loading…
Reference in New Issue
Block a user