forked from GitHub/dbot
Timers and an ~rmlast command to remove the last quote.
This commit is contained in:
parent
87ce257ca9
commit
54746625fd
@ -1,5 +1,7 @@
|
||||
var quotes = function(dbot) {
|
||||
var quotes = dbot.db.quoteArrs;
|
||||
var addStack = [];
|
||||
var rmAllowed = true;
|
||||
|
||||
var commands = {
|
||||
'~q': function(data, params) {
|
||||
@ -14,6 +16,21 @@ var quotes = function(dbot) {
|
||||
}
|
||||
},
|
||||
|
||||
'~rmlast': function(data, params) {
|
||||
if(rmAllowed == true) {
|
||||
var last = addStack.pop();
|
||||
if(last) {
|
||||
quotes[last].pop();
|
||||
rmAllowed = false;
|
||||
dbot.say(data.channel, 'Last quote removed from ' + last + '.');
|
||||
} else {
|
||||
dbot.say(data.channel, 'No quotes were added recently.');
|
||||
}
|
||||
} else {
|
||||
dbot.say(data.channel, 'No spamming that shit. Try again in a few minutes...');
|
||||
}
|
||||
},
|
||||
|
||||
'~qcount': function(data, params) {
|
||||
var q = data.message.valMatch(/^~qcount ([\d\w\s]*)/, 2);
|
||||
if(q) {
|
||||
@ -34,6 +51,8 @@ var quotes = function(dbot) {
|
||||
quotes[q[1]] = [];
|
||||
}
|
||||
quotes[q[1]].push(q[2]);
|
||||
addStack.push(q[1]);
|
||||
rmAllowed = true;
|
||||
dbot.say(data.channel, 'Quote saved in \'' + q[1] + '\' (' + quotes[q[1]].length + ')');
|
||||
}
|
||||
},
|
||||
@ -69,6 +88,9 @@ var quotes = function(dbot) {
|
||||
|
||||
return {
|
||||
'onLoad': function() {
|
||||
dbot.timers.addTimer(1000 * 60 * 3, function() {
|
||||
rmAllowed = true;
|
||||
});
|
||||
return commands;
|
||||
}
|
||||
};
|
||||
|
14
run.js
14
run.js
@ -1,20 +1,19 @@
|
||||
require('./snippets');
|
||||
var fs = require('fs');
|
||||
var timers = require('./timer');
|
||||
var jsbot = require('./jsbot');
|
||||
require('./snippets');
|
||||
|
||||
var modules = ['user', 'admin', 'puns', 'kick', 'reality', 'karma', 'youare', 'quotes'];
|
||||
|
||||
var DBot = function(dModules, quotes) {
|
||||
var DBot = function(dModules, timers) {
|
||||
this.admin = 'reality';
|
||||
this.waitingForKarma = false;
|
||||
this.name = 'depressionbot';
|
||||
this.name = 'testressionbot';
|
||||
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
||||
this.timers = timers.create();
|
||||
|
||||
this.instance = jsbot.createJSBot(this.name, 'elara.ivixor.net', 6667, this, function() {
|
||||
this.instance.join('#realitest');
|
||||
this.instance.join('#itonlygetsworse');
|
||||
this.instance.join('#42');
|
||||
this.instance.join('#fail');
|
||||
}.bind(this));
|
||||
|
||||
this.moduleNames = dModules;
|
||||
@ -34,6 +33,7 @@ DBot.prototype.reloadModules = function() {
|
||||
this.rawModules = [];
|
||||
this.modules = [];
|
||||
this.commands = {};
|
||||
this.timers.clearTimers();
|
||||
|
||||
var path = require.resolve('./snippets');
|
||||
require.cache[path] = undefined;
|
||||
@ -91,4 +91,4 @@ DBot.prototype.reloadModules = function() {
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
new DBot(modules);
|
||||
new DBot(modules, timers);
|
||||
|
19
timer.js
Normal file
19
timer.js
Normal file
@ -0,0 +1,19 @@
|
||||
var timers = function() {
|
||||
var timers = [];
|
||||
|
||||
return {
|
||||
'addTimer': function(interval, callback) { // Because who puts the callback first. Really.
|
||||
timers.push(setInterval(callback, interval));
|
||||
},
|
||||
|
||||
'clearTimers': function() {
|
||||
for(var i;i<timers.length;i++) {
|
||||
clearInterval(timers[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.create = function() {
|
||||
return timers();
|
||||
}
|
Loading…
Reference in New Issue
Block a user