Basic cron version

This commit is contained in:
yago
2014-12-16 21:50:19 +01:00
parent 198f700f86
commit 8b04aefd45
2 changed files with 40 additions and 15 deletions

View File

@ -59,11 +59,13 @@ function do_action(msg)
matches = { string.match(text, pattern) }
if matches[1] then
print(" matches",pattern)
result = desc.run(msg, matches)
print(" sending", result)
if (result) then
_send_msg(receiver, result)
return
if desc.run ~= nil then
result = desc.run(msg, matches)
print(" sending", result)
if (result) then
_send_msg(receiver, result)
return
end
end
end
end
@ -182,6 +184,10 @@ end
function on_binlog_replay_end ()
started = 1
load_plugins()
-- Uncomment the line to enable cron plugins.
-- cron_plugins()
-- See plugins/ping.lua as an example for cron
end
-- Start and load values
@ -195,7 +201,6 @@ plugins = {}
-- load all plugins in the plugins/ directory
function load_plugins()
plugins = {}
for k, v in pairs(scandir("plugins")) do
-- Load only lua files
if (v:match(".lua$")) then
@ -206,5 +211,16 @@ function load_plugins()
end
end
load_plugins()
-- Cron all the enabled plugins
function cron_plugins()
for name, desc in pairs(plugins) do
if desc.cron ~= nil then
print("croned!"..desc.description)
desc.cron()
end
end
-- Called again in 5 mins
postpone (cron_plugins, false, 5*60.0)
end