db now saves every minute. Will make it configurable in future.

This commit is contained in:
topkecleon 2016-02-22 18:07:16 -05:00
parent 64160e700c
commit 971b27335b
2 changed files with 8 additions and 3 deletions

View File

@ -36,6 +36,7 @@ bot_init = function() -- The function run when the bot is started or reloaded.
last_update = last_update or 0 -- Set loop variables: Update offset,
last_cron = last_cron or os.time() -- the time of the last cron job,
last_db_save = os.date('%M', os.time())
is_started = true -- and whether or not the bot should be running.
database.usernames = database.usernames or {} -- Table to cache usernames by user ID.
@ -102,6 +103,7 @@ while is_started do -- Start a loop while the bot should be running.
end
if last_cron < os.time() - 5 then -- Run cron jobs if the time has come.
last_cron = os.time() -- Update the timer variable.
for i,v in ipairs(plugins) do
if v.cron then -- Call each plugin's cron function, if it has one.
local res, err = pcall(function() v.cron() end)
@ -110,8 +112,11 @@ while is_started do -- Start a loop while the bot should be running.
end
end
end
save_data('otouto.db', database) -- Save the database.
last_cron = os.time() -- And finally, update the variable.
-- Save the database.
if last_db_save ~= os.date('%M', os.time()) then
last_db_save = os.date('%M', os.time())
save_data('otouto.db', database)
end
end
end

View File

@ -9,7 +9,7 @@ local action = function(msg)
return
end
if msg.date < os.time() - 1 then return end
if msg.date < os.time() then return end
if msg.text:match('^/reload') then
bot_init()