From c6b99bec64ee76b2e8e86ea949e4b831db675f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mun=CC=83oz?= Date: Wed, 5 Nov 2014 13:21:56 +0100 Subject: [PATCH] Loading plugins after configuration --- bot/bot.lua | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 032c486..d088eac 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -4,8 +4,6 @@ -- lrexlib = require("rex_pcre") VERSION = 'v0.6' - - plugins = {} -- taken from http://stackoverflow.com/a/11130774/3163199 function scandir(directory) @@ -16,16 +14,7 @@ end return t 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) if msg_valid(msg) == false then return @@ -336,11 +325,6 @@ end end - -- Start and load values - config = load_config() - our_id = 0 - now = os.time() - function get_receiver(msg) if msg.to.type == 'user' then return 'user#id'..msg.from.id @@ -350,7 +334,6 @@ end end - function on_our_id (id) our_id = id end @@ -373,3 +356,23 @@ function on_binlog_replay_end () started = 1 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 +