Initial test of plugins handler
This commit is contained in:
18
bot/bot.lua
18
bot/bot.lua
@@ -22,11 +22,6 @@ end
|
||||
function ok_cb(extra, success, result)
|
||||
end
|
||||
|
||||
-- Callback to remove tmp files
|
||||
function rmtmp_cb(file_path, success, result)
|
||||
os.remove(file_path)
|
||||
end
|
||||
|
||||
function msg_valid(msg)
|
||||
-- if msg.from.id == our_id then
|
||||
-- return true
|
||||
@@ -170,15 +165,12 @@ function on_binlog_replay_end ()
|
||||
-- See plugins/ping.lua as an example for cron
|
||||
end
|
||||
|
||||
-- load all plugins in the plugins/ directory
|
||||
-- Enable plugins in config.json
|
||||
function load_plugins()
|
||||
for k, v in pairs(scandir("plugins")) do
|
||||
-- Load only lua files
|
||||
if (v:match(".lua$")) then
|
||||
print("Loading plugin", v)
|
||||
t = loadfile("plugins/" .. v)()
|
||||
table.insert(plugins, t)
|
||||
end
|
||||
for k, v in pairs(config.enabled_plugins) do
|
||||
print("Loading plugin", v)
|
||||
t = loadfile("plugins/" .. v)()
|
||||
table.insert(plugins, t)
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"enabled_plugins": [ "plugins.lua", "echo.lua", "hello.lua" ],
|
||||
"rmtmp_delay": 20,
|
||||
"google_api_key": "",
|
||||
"log_file": "/var/www/html/log.txt",
|
||||
|
@@ -67,6 +67,11 @@ function download_to_file( url , noremove )
|
||||
return file_path
|
||||
end
|
||||
|
||||
-- Callback to remove a file
|
||||
function rmtmp_cb(file_path, success, result)
|
||||
os.remove(file_path)
|
||||
end
|
||||
|
||||
function vardump(value, depth, key)
|
||||
local linePrefix = ""
|
||||
local spaces = ""
|
||||
@@ -133,10 +138,34 @@ function is_sudo(msg)
|
||||
return var
|
||||
end
|
||||
|
||||
-- Returns the name of the sender
|
||||
function get_name(msg)
|
||||
local name = msg.from.first_name
|
||||
if name == nil then
|
||||
name = msg.from.id
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
-- Returns at table of lua files inside plugins
|
||||
function plugins_names( )
|
||||
local files = {}
|
||||
for k, v in pairs(scandir("plugins")) do
|
||||
-- Ends with .lua
|
||||
if (v:match(".lua$")) then
|
||||
table.insert(files, v)
|
||||
end
|
||||
end
|
||||
return files
|
||||
end
|
||||
|
||||
-- Function name explains what it does.
|
||||
function file_exists(name)
|
||||
local f = io.open(name,"r")
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user