diff --git a/bot.lua b/bot.lua index 38d9e4b..df60011 100755 --- a/bot.lua +++ b/bot.lua @@ -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 diff --git a/plugins/control.lua b/plugins/control.lua index e0a0a0f..663cc1e 100644 --- a/plugins/control.lua +++ b/plugins/control.lua @@ -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()