db now saves every minute. Will make it configurable in future.
This commit is contained in:
parent
64160e700c
commit
971b27335b
9
bot.lua
9
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_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_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.
|
is_started = true -- and whether or not the bot should be running.
|
||||||
database.usernames = database.usernames or {} -- Table to cache usernames by user ID.
|
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
|
end
|
||||||
|
|
||||||
if last_cron < os.time() - 5 then -- Run cron jobs if the time has come.
|
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
|
for i,v in ipairs(plugins) do
|
||||||
if v.cron then -- Call each plugin's cron function, if it has one.
|
if v.cron then -- Call each plugin's cron function, if it has one.
|
||||||
local res, err = pcall(function() v.cron() end)
|
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
|
end
|
||||||
end
|
end
|
||||||
save_data('otouto.db', database) -- Save the database.
|
-- Save the database.
|
||||||
last_cron = os.time() -- And finally, update the variable.
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ local action = function(msg)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if msg.date < os.time() - 1 then return end
|
if msg.date < os.time() then return end
|
||||||
|
|
||||||
if msg.text:match('^/reload') then
|
if msg.text:match('^/reload') then
|
||||||
bot_init()
|
bot_init()
|
||||||
|
Reference in New Issue
Block a user