Loading plugins after configuration

This commit is contained in:
David Muñoz 2014-11-05 13:21:56 +01:00
parent 88e0336227
commit c6b99bec64

View File

@ -5,8 +5,6 @@
VERSION = 'v0.6' VERSION = 'v0.6'
plugins = {}
-- taken from http://stackoverflow.com/a/11130774/3163199 -- taken from http://stackoverflow.com/a/11130774/3163199
function scandir(directory) function scandir(directory)
local i, t, popen = 0, {}, io.popen local i, t, popen = 0, {}, io.popen
@ -17,15 +15,6 @@
return t return t
end end
-- load all plugins in the plugins/ directory
for k, v in pairs(scandir("plugins")) do
if not (v:sub(0, 1) == ".") then
print("Loading plugin", v)
t = loadfile("plugins/" .. v)()
table.insert(plugins, t)
end
end
function on_msg_receive (msg) function on_msg_receive (msg)
if msg_valid(msg) == false then if msg_valid(msg) == false then
return return
@ -336,11 +325,6 @@
end end
end end
-- Start and load values
config = load_config()
our_id = 0
now = os.time()
function get_receiver(msg) function get_receiver(msg)
if msg.to.type == 'user' then if msg.to.type == 'user' then
return 'user#id'..msg.from.id return 'user#id'..msg.from.id
@ -350,7 +334,6 @@
end end
end end
function on_our_id (id) function on_our_id (id)
our_id = id our_id = id
end end
@ -373,3 +356,23 @@
function on_binlog_replay_end () function on_binlog_replay_end ()
started = 1 started = 1
end end
-- Start and load values
config = load_config()
our_id = 0
now = os.time()
-- load plugins
plugins = {}
-- load all plugins in the plugins/ directory
for k, v in pairs(scandir("plugins")) do
if not (v:sub(0, 1) == ".") then
print("Loading plugin", v)
t = loadfile("plugins/" .. v)()
table.insert(plugins, t)
end
end