disable plugins and some checks
This commit is contained in:
parent
d0a728e214
commit
03e52b1d41
@ -1,21 +1,61 @@
|
|||||||
function enable_plugin( filename )
|
function enable_plugin( filename )
|
||||||
-- Checks if file exists
|
-- Check if plugin is enabled
|
||||||
if file_exists('plugins/'..filename) then
|
if plugin_enabled(filename) then
|
||||||
|
return 'Plugin '..filename..' is enabled'
|
||||||
|
end
|
||||||
|
-- Checks if plugin exists
|
||||||
|
if plugin_exists(filename) then
|
||||||
-- Add to the config table
|
-- Add to the config table
|
||||||
table.insert(config.enabled_plugins, filename)
|
table.insert(config.enabled_plugins, filename)
|
||||||
-- Reload the plugins
|
-- Reload the plugins
|
||||||
reload_plugins( )
|
return reload_plugins( )
|
||||||
else
|
else
|
||||||
return 'Plugin does not exists'
|
return 'Plugin '..filename..' does not exists'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function disable_plugin( filename )
|
||||||
|
-- Check if plugins exists
|
||||||
|
if not plugin_exists(filename) then
|
||||||
|
return 'Plugin '..filename..' does not exists'
|
||||||
|
end
|
||||||
|
local k = plugin_enabled(filename)
|
||||||
|
-- Check if plugin is enabled
|
||||||
|
if not k then
|
||||||
|
return 'Plugin '..filename..' not enabled'
|
||||||
|
end
|
||||||
|
-- Disable and reload
|
||||||
|
table.remove(config.enabled_plugins, k)
|
||||||
|
return reload_plugins(true)
|
||||||
|
end
|
||||||
|
|
||||||
function reload_plugins( )
|
function reload_plugins( )
|
||||||
plugins = {}
|
plugins = {}
|
||||||
load_plugins()
|
load_plugins()
|
||||||
return list_plugins(true)
|
return list_plugins(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Retruns the key (index) in the config.enabled_plugins table
|
||||||
|
function plugin_enabled( name )
|
||||||
|
for k,v in pairs(config.enabled_plugins) do
|
||||||
|
if name == v then
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- If not found
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns true if file exists in plugins folder
|
||||||
|
function plugin_exists( name )
|
||||||
|
for k,v in pairs(plugins_names()) do
|
||||||
|
if name == v then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function list_plugins(only_enabled)
|
function list_plugins(only_enabled)
|
||||||
local text = ''
|
local text = ''
|
||||||
for k, v in pairs( plugins_names( )) do
|
for k, v in pairs( plugins_names( )) do
|
||||||
@ -39,24 +79,30 @@ function run(msg, matches)
|
|||||||
if matches[1] == '!plugins' then
|
if matches[1] == '!plugins' then
|
||||||
return list_plugins()
|
return list_plugins()
|
||||||
end
|
end
|
||||||
-- Reload all the plugins!
|
|
||||||
if matches[1] == 'reload' then
|
|
||||||
return reload_plugins(true)
|
|
||||||
end
|
|
||||||
-- Enable a plugin
|
-- Enable a plugin
|
||||||
if matches[1] == 'enable' then
|
if matches[1] == 'enable' then
|
||||||
print("enable: "..matches[2])
|
print("enable: "..matches[2])
|
||||||
return enable_plugin(matches[2])
|
return enable_plugin(matches[2])
|
||||||
end
|
end
|
||||||
|
-- Disable a plugin
|
||||||
|
if matches[1] == 'disable' then
|
||||||
|
print("disable: "..matches[2])
|
||||||
|
return disable_plugin(matches[2])
|
||||||
|
end
|
||||||
|
-- Reload all the plugins!
|
||||||
|
if matches[1] == 'reload' then
|
||||||
|
return reload_plugins(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Enable / Disable plugins",
|
description = "Enables, disables and reloads plugins",
|
||||||
usage = "!plugins",
|
usage = "!plugins, !plugins enable [plugin.lua], !plugins disable [plugin.lua], !plugins reload",
|
||||||
patterns = {
|
patterns = {
|
||||||
"^!plugins$",
|
"^!plugins$",
|
||||||
"^!plugins (enable) ([%w%.]+)$",
|
"^!plugins? (enable) (.*)$",
|
||||||
"^!plugins (reload)$"
|
"^!plugins? (disable) (.*)$",
|
||||||
|
"^!plugins? (reload)$"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
Reference in New Issue
Block a user