3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 22:39:26 +01:00

do the thing thing

This commit is contained in:
reality 2013-12-19 20:02:50 +00:00
parent 44a3b4e7c6
commit 0422c3702d

View File

@ -8,6 +8,7 @@ var _ = require('underscore')._,
var reddit = function(dbot) { var reddit = function(dbot) {
this.ApiRoot = 'http://reddit.com/'; this.ApiRoot = 'http://reddit.com/';
this.UserAgent = 'dbot by u/realitone'; this.UserAgent = 'dbot by u/realitone';
this.ints = [];
this.internalAPI = { this.internalAPI = {
'getChannelFeeds': function(server, cName, callback) { 'getChannelFeeds': function(server, cName, callback) {
@ -39,6 +40,11 @@ var reddit = function(dbot) {
var channels = [], var channels = [],
checkTimes = []; checkTimes = [];
for(i=0;i<this.ints.length;i++) {
console.log('destroying ' +this.runningIntervals[i]);
clearInterval(this.ints[i]);
}
this.db.scan('reddit_feeds', function(channel) { this.db.scan('reddit_feeds', function(channel) {
if(channel) { if(channel) {
channels.push(channel); channels.push(channel);
@ -48,7 +54,7 @@ var reddit = function(dbot) {
checkTimes[channel.id] = {}; checkTimes[channel.id] = {};
_.each(channel.feeds, function(feed) { _.each(channel.feeds, function(feed) {
checkTimes[channel.id][feed.subreddit] = Date.now(); checkTimes[channel.id][feed.subreddit] = Date.now();
dbot.api.timers.addTimer(30000, function() { this.ints.push(setInterval(function() {
this.api.getNewPosts(feed.subreddit, checkTimes[channel.id][feed.subreddit], function(err, posts) { this.api.getNewPosts(feed.subreddit, checkTimes[channel.id][feed.subreddit], function(err, posts) {
if(!err && posts.length > 0) { if(!err && posts.length > 0) {
_.each(posts, function(post) { _.each(posts, function(post) {
@ -66,7 +72,7 @@ var reddit = function(dbot) {
checkTimes[channel.id][feed.subreddit] = Date.now(); checkTimes[channel.id][feed.subreddit] = Date.now();
} }
}.bind(this)); }.bind(this));
}.bind(this)); }, feed.interval));
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));