<commit_before>/**
 * Module Name: Timers
 * Description: Persistent timers and shit
 */
var _ = require('underscore')._;

var timers = function(dbot) {
    this.timers = dbot.db.timers;
    this.runningTimers = [];

    this.api = {
        'addTimer': function(callback, timeout, firstDate) {
            var now = new Date().getTime();
            if(firstDate) {
                console.log('Setting first timer to run at ' + firstDate);
                timeout = firstDate.getTime() - now; 
                setTimeout(function(callback) {
                    console.log('Running first timer at ' + new Date().toUTCString()); 
                    callback();
                    this.api.addTimer(callback, timeout);
                }.bind(this), timeout);
            } else {
                setInterval(function(callback) {
                    console.log('Running subsequent timer at ' + new Date().toUTCString()); 
                    callback();
                }.bind(this), timeout);
            }
        }
    };

    this.onLoad = function() { 
        // TODO: Persist timers
    }.bind(this);
};

exports.fetch = function(dbot) {
    return new timers(dbot);
};<commit_msg>This should be a fully functional timers module [#160]<commit_after>/**
 * Module Name: Timers
 * Description: Persistent timers and shit
 */
var _ = require('underscore')._;

var timers = function(dbot) {
    this.timers = dbot.db.timers;
    this.runningTimeouts = [];
    this.runningIntervals = [];

    this.api = {
        'addTimer': function(callback, timeout, firstDate) {
            var now = new Date().getTime();
            if(firstDate) {
                console.log('Setting first timer to run at ' + firstDate);
                firstTimeout = firstDate.getTime() - now; 
                setTimeout(function(callback) {
                    console.log('Running first timer at ' + new Date().toUTCString()); 
                    this.runningIntervals.push(this.api.addTimer(callback, timeout));
                    callback();
                }.bind(this), firstTimeout);
            } else {
                this.runningIntervals.push(setInterval(function(callback) {
                    console.log('Running subsequent timer at ' + new Date().toUTCString()); 
                    callback();
                }.bind(this), timeout));
            }
        }
    };

    this.onDestroy = function() { 
        for(var i=0;i<this.runningTimeouts;i++ {
            clearTimeout(this.runningTimeouts[i]); 
        }
        for(i=0;i<this.runningIntervals;i++ {
            clearTimer(this.runningIntervals[i]); 
        }
    }.bind(this);
};

exports.fetch = function(dbot) {
    return new timers(dbot);
};
{'fraction_non_alphanumeric': 0.13163716814159293, 'fraction_numerical': 0.0018436578171091445, 'mean_word_length': 1.8378661087866108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6167047', 'n_tokens_mistral': 763, 'n_tokens_neox': 717, 'n_words': 153}