From 065611bcffc43302d401c1271b53060029d49e59 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Wed, 12 Oct 2011 14:52:58 +0100 Subject: [PATCH] Timed save --- modules/kick.js | 2 -- modules/quotes.js | 1 - run.js | 8 ++++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/kick.js b/modules/kick.js index b8fbe4a..a168ef5 100644 --- a/modules/kick.js +++ b/modules/kick.js @@ -15,8 +15,6 @@ var kick = function(dbot) { } dbot.say(data.channel, data.kickee + '-- (' + data.kickee + ' has been kicked ' + dbot.db.kicks[data.kickee] + ' times)'); } - - dbot.save(); }, on: 'KICK' diff --git a/modules/quotes.js b/modules/quotes.js index a93717e..af139e5 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -120,7 +120,6 @@ var quotes = function(dbot) { addStack.push('realityonce'); rmAllowed = true; dbot.instance.say(data.channel, '\'reality ' + once[1] + '.\' saved.'); - dbot.save(); } }, diff --git a/run.js b/run.js index 2e65437..4acf2a0 100644 --- a/run.js +++ b/run.js @@ -28,7 +28,7 @@ DBot.prototype.say = function(channel, data) { }; DBot.prototype.save = function() { - fs.writeFile('db.json', JSON.stringify(this.db, null, ' ')); + fs.writeFileSync('db.json', JSON.stringify(this.db, null, ' ')); }; DBot.prototype.reloadModules = function() { @@ -45,6 +45,11 @@ DBot.prototype.reloadModules = function() { this.commands = {}; this.timers.clearTimers(); + this.save(); + this.timers.addTimer(1000 * 60 * 10, function() { + this.save(); + }); + var path = require.resolve('./snippets'); require.cache[path] = undefined; require('./snippets'); @@ -90,7 +95,6 @@ DBot.prototype.reloadModules = function() { else { this.commands[params[0]](data, params); } - this.save(); } else { var q = data.message.valMatch(/^~([\d\w\s]*)/, 2); if(q) {