forked from GitHub/dbot
remove timers.js [#170]
This commit is contained in:
parent
aeea3fc269
commit
a5cede8c92
@ -96,7 +96,7 @@ var commands = function(dbot) {
|
||||
},
|
||||
|
||||
'~rmlast': function(event) {
|
||||
if(this.rmAllowed == true || _.include(dbot.config.admins, event.user)) {
|
||||
if(this.rmAllowed === true || _.include(dbot.config.admins, event.user)) {
|
||||
var key = event.input[1].trim().toLowerCase();
|
||||
if(_.has(quotes, key)) {
|
||||
var quote = quotes[key].pop();
|
||||
|
@ -44,9 +44,9 @@ var quotes = function(dbot) {
|
||||
|
||||
'resetRemoveTimer': function(event, key, quote) {
|
||||
this.rmAllowed = false;
|
||||
setTimeout(5000, function() {
|
||||
setTimeout(function() {
|
||||
this.rmAllowed = true;
|
||||
});
|
||||
}.bind(this), 5000);
|
||||
|
||||
this.rmCache.push({
|
||||
'key': key,
|
||||
@ -55,9 +55,9 @@ var quotes = function(dbot) {
|
||||
|
||||
clearTimeout(this.rmTimer);
|
||||
if(this.rmCache.length < dbot.config.quotes.rmLimit) {
|
||||
this.rmTimer = setTimeout(600000, function() {
|
||||
this.rmTimer = setTimeout(function() {
|
||||
this.rmCache.length = 0; // lol what
|
||||
}.bind(this));
|
||||
}.bind(this), 600000);
|
||||
} else {
|
||||
_.each(dbot.config.admins, function(admin) {
|
||||
dbot.say(event.server, admin, dbot.t('rm_cache_limit'));
|
||||
|
7
run.js
7
run.js
@ -1,10 +1,9 @@
|
||||
var fs = require('fs'),
|
||||
_ = require('underscore')._,
|
||||
timers = require('./timer'),
|
||||
jsbot = require('./jsbot/jsbot');
|
||||
require('./snippets');
|
||||
|
||||
var DBot = function(timers) {
|
||||
var DBot = function() {
|
||||
|
||||
/*** Load the DB ***/
|
||||
|
||||
@ -61,7 +60,6 @@ var DBot = function(timers) {
|
||||
this.usage = {};
|
||||
this.status = {};
|
||||
this.sessionData = {};
|
||||
this.timers = timers.create();
|
||||
|
||||
// Populate bot properties with config data
|
||||
// Create JSBot and connect to each server
|
||||
@ -130,7 +128,6 @@ DBot.prototype.reloadModules = function() {
|
||||
this.api = {};
|
||||
this.commandMap = {}; // Map of which commands belong to which modules
|
||||
this.usage = {};
|
||||
this.timers.clearTimers();
|
||||
|
||||
// Load config changes
|
||||
_.extend(this.config, this.db.config);
|
||||
@ -313,4 +310,4 @@ DBot.prototype.cleanNick = function(key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
new DBot(timers);
|
||||
new DBot();
|
||||
|
39
timer.js
39
timer.js
@ -1,39 +0,0 @@
|
||||
var timers = function() {
|
||||
var timers = [];
|
||||
var timeouts = [];
|
||||
|
||||
return {
|
||||
'addTimer': function(interval, callback) { // Because who puts the callback first. Really.
|
||||
var timer = setInterval(callback, interval);
|
||||
timers.push(timer);
|
||||
return timer;
|
||||
},
|
||||
|
||||
'addOnceTimer': function(delay, callback) { // Because who seriously puts the callback first here too?
|
||||
var timeout = setTimeout(callback, delay);
|
||||
timeouts.push(timeout);
|
||||
return timeout;
|
||||
},
|
||||
|
||||
'clearTimers': function() {
|
||||
for(var i;i<timers.length;i++) {
|
||||
clearInterval(timers[i]);
|
||||
}
|
||||
for(var i;i<timeouts.length;i++) {
|
||||
clearTimeout(timeouts[i]);
|
||||
}
|
||||
},
|
||||
|
||||
'clearTimer': function(id) {
|
||||
clearTimer(id);
|
||||
},
|
||||
|
||||
'clearTimeout': function(id) {
|
||||
clearTimeout(id);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.create = function() {
|
||||
return timers();
|
||||
}
|
Loading…
Reference in New Issue
Block a user