mirror of
https://github.com/reality/dbot.git
synced 2024-11-24 04:49:25 +01:00
Merge pull request #29 from psquid/master
webPort config option (default 443), no DB splatting, and ~ignore command (plus timer.js and run.js changes to make it possible).
This commit is contained in:
commit
6584dc477d
@ -3,17 +3,57 @@
|
|||||||
var command = function(dbot) {
|
var command = function(dbot) {
|
||||||
var dbot = dbot;
|
var dbot = dbot;
|
||||||
|
|
||||||
|
var ignoreCommands = function (data, params) {
|
||||||
|
if(data.channel == dbot.name) data.channel = data.user;
|
||||||
|
var targetCommand = params[1];
|
||||||
|
var ignoreMins = parseFloat(params[2]);
|
||||||
|
|
||||||
|
if(!dbot.sessionData.hasOwnProperty("ignoreCommands")) {
|
||||||
|
dbot.sessionData.ignoreCommands = {};
|
||||||
|
}
|
||||||
|
if(!dbot.sessionData.ignoreCommands.hasOwnProperty(targetCommand)) {
|
||||||
|
dbot.sessionData.ignoreCommands[targetCommand] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dbot.sessionData.ignoreCommands[targetCommand].include(data.channel)) {
|
||||||
|
dbot.say(data.channel, "Already ignoring '" + targetCommand + "' in '" + data.channel + "'.");
|
||||||
|
} else {
|
||||||
|
dbot.sessionData.ignoreCommands[targetCommand].push(data.channel);
|
||||||
|
dbot.timers.addOnceTimer(ignoreMins * 60 * 1000, function() {
|
||||||
|
dbot.sessionData.ignoreCommands[targetCommand].splice(dbot.sessionData.ignoreCommands[targetCommand].indexOf(data.channel), 1);
|
||||||
|
dbot.say(data.channel, "No longer ignoring '" + targetCommand + "' in '" + data.channel + "'.");
|
||||||
|
});
|
||||||
|
dbot.say(data.channel, "Ignoring '" + targetCommand + "' in '" + data.channel + "' for the next " + ignoreMins + " minute" + (ignoreMins == 1 ? "" : "s") + ".");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
'onLoad': function() {
|
||||||
|
return {
|
||||||
|
'~ignore': ignoreCommands
|
||||||
|
};
|
||||||
|
},
|
||||||
'listener': function(data) {
|
'listener': function(data) {
|
||||||
params = data.message.split(' ');
|
params = data.message.split(' ');
|
||||||
if(data.channel == dbot.name) data.channel = data.user;
|
if(data.channel == dbot.name) data.channel = data.user;
|
||||||
|
|
||||||
|
var ignoringCommand = false;
|
||||||
|
if(dbot.sessionData.hasOwnProperty("ignoreCommands")) {
|
||||||
|
if(dbot.sessionData.ignoreCommands.hasOwnProperty(params[0])) {
|
||||||
|
if(dbot.sessionData.ignoreCommands[params[0]].include(data.channel)) {
|
||||||
|
ignoringCommand = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(dbot.commands.hasOwnProperty(params[0])) {
|
if(dbot.commands.hasOwnProperty(params[0])) {
|
||||||
if((dbot.db.bans.hasOwnProperty(params[0]) &&
|
if((dbot.db.bans.hasOwnProperty(params[0]) &&
|
||||||
dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user))
|
dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user)) {
|
||||||
dbot.say(data.channel, data.user +
|
dbot.say(data.channel, data.user +
|
||||||
' is banned from using this command. Commence incineration.');
|
' is banned from using this command. Commence incineration.');
|
||||||
else {
|
} else if(ignoringCommand) {
|
||||||
|
// do nothing, this stops us falling through to the non-command stuff
|
||||||
|
} else {
|
||||||
dbot.commands[params[0]](data, params);
|
dbot.commands[params[0]](data, params);
|
||||||
dbot.save();
|
dbot.save();
|
||||||
}
|
}
|
||||||
|
@ -247,6 +247,9 @@ var quotes = function(dbot) {
|
|||||||
dbot.db.bans['*'].include(data.user)) {
|
dbot.db.bans['*'].include(data.user)) {
|
||||||
dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.');
|
dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.');
|
||||||
} else {
|
} else {
|
||||||
|
if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) {
|
||||||
|
dbot.db.quoteArrs['realityonce'] = [];
|
||||||
|
}
|
||||||
dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.');
|
dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.');
|
||||||
addStack.push('realityonce');
|
addStack.push('realityonce');
|
||||||
rmAllowed = true;
|
rmAllowed = true;
|
||||||
|
@ -37,7 +37,7 @@ var webInterface = function(dbot) {
|
|||||||
res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } });
|
res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(443);
|
app.listen(dbot.webPort);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'onDestroy': function() {
|
'onDestroy': function() {
|
||||||
|
19
run.js
19
run.js
@ -6,11 +6,18 @@ require('./snippets');
|
|||||||
var DBot = function(timers) {
|
var DBot = function(timers) {
|
||||||
// Load external files
|
// Load external files
|
||||||
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
||||||
|
this.db = null;
|
||||||
|
var rawDB;
|
||||||
try {
|
try {
|
||||||
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
var rawDB = fs.readFileSync('db.json', 'utf-8');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.db = {};
|
this.db = {}; /* if no db file, make empty one */
|
||||||
} finally { /* fill any missing parts of the db; if this is a new DB, that's all of them */
|
}
|
||||||
|
if(!this.db) { /* if it wasn't empty */
|
||||||
|
this.db = JSON.parse(rawDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* repair any deficiencies in the DB; if this is a new DB, that's everything */
|
||||||
if(!this.db.hasOwnProperty("bans")) {
|
if(!this.db.hasOwnProperty("bans")) {
|
||||||
this.db.bans = {};
|
this.db.bans = {};
|
||||||
}
|
}
|
||||||
@ -20,9 +27,6 @@ var DBot = function(timers) {
|
|||||||
if(!this.db.hasOwnProperty("quoteArrs")) {
|
if(!this.db.hasOwnProperty("quoteArrs")) {
|
||||||
this.db.quoteArrs = {};
|
this.db.quoteArrs = {};
|
||||||
}
|
}
|
||||||
if(!this.db.quoteArrs.hasOwnProperty("realityonce")) {
|
|
||||||
this.db.quoteArrs.realityonce = [];
|
|
||||||
}
|
|
||||||
if(!this.db.hasOwnProperty("kicks")) {
|
if(!this.db.hasOwnProperty("kicks")) {
|
||||||
this.db.kicks = {};
|
this.db.kicks = {};
|
||||||
}
|
}
|
||||||
@ -35,7 +39,6 @@ var DBot = function(timers) {
|
|||||||
if(!this.db.hasOwnProperty("locks")) {
|
if(!this.db.hasOwnProperty("locks")) {
|
||||||
this.db.locks = [];
|
this.db.locks = [];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Populate bot properties with config data
|
// Populate bot properties with config data
|
||||||
this.name = this.config.name || 'dbox';
|
this.name = this.config.name || 'dbox';
|
||||||
@ -44,7 +47,9 @@ var DBot = function(timers) {
|
|||||||
this.nickserv = this.config.nickserv || 'zippy';
|
this.nickserv = this.config.nickserv || 'zippy';
|
||||||
this.server = this.config.server || 'elara.ivixor.net';
|
this.server = this.config.server || 'elara.ivixor.net';
|
||||||
this.port = this.config.port || 6667;
|
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.moduleNames = this.config.modules || [ 'command', 'js', 'admin', 'kick', 'modehate', 'quotes', 'puns', 'spelling', 'web', 'youare' ];
|
||||||
|
this.sessionData = {};
|
||||||
|
|
||||||
this.timers = timers.create();
|
this.timers = timers.create();
|
||||||
|
|
||||||
|
8
timer.js
8
timer.js
@ -1,15 +1,23 @@
|
|||||||
var timers = function() {
|
var timers = function() {
|
||||||
var timers = [];
|
var timers = [];
|
||||||
|
var timeouts = [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'addTimer': function(interval, callback) { // Because who puts the callback first. Really.
|
'addTimer': function(interval, callback) { // Because who puts the callback first. Really.
|
||||||
timers.push(setInterval(callback, interval));
|
timers.push(setInterval(callback, interval));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'addOnceTimer': function(delay, callback) { // Because who seriously puts the callback first here too?
|
||||||
|
timeouts.push(setTimeout(callback, delay));
|
||||||
|
},
|
||||||
|
|
||||||
'clearTimers': function() {
|
'clearTimers': function() {
|
||||||
for(var i;i<timers.length;i++) {
|
for(var i;i<timers.length;i++) {
|
||||||
clearInterval(timers[i]);
|
clearInterval(timers[i]);
|
||||||
}
|
}
|
||||||
|
for(var i;i<timeouts.length;i++) {
|
||||||
|
clearTimeout(timeouts[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user