Identation as spaces
This commit is contained in:
parent
7f9bbae615
commit
eecb820568
@ -2,13 +2,13 @@ do
|
|||||||
|
|
||||||
-- Retruns the key (index) in the config.enabled_plugins table
|
-- Retruns the key (index) in the config.enabled_plugins table
|
||||||
local function plugin_enabled( name )
|
local function plugin_enabled( name )
|
||||||
for k,v in pairs(_config.enabled_plugins) do
|
for k,v in pairs(_config.enabled_plugins) do
|
||||||
if name == v then
|
if name == v then
|
||||||
return k
|
return k
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- If not found
|
-- If not found
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns true if file exists in plugins folder
|
-- Returns true if file exists in plugins folder
|
||||||
@ -22,100 +22,100 @@ local function plugin_exists( name )
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function list_plugins(only_enabled)
|
local 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
|
||||||
-- ✔ enabled, ❌ disabled
|
-- ✔ enabled, ❌ disabled
|
||||||
local status = '❌'
|
local status = '❌'
|
||||||
-- Check if is enabled
|
-- Check if is enabled
|
||||||
for k2, v2 in pairs(_config.enabled_plugins) do
|
for k2, v2 in pairs(_config.enabled_plugins) do
|
||||||
if v == v2..'.lua' then
|
if v == v2..'.lua' then
|
||||||
status = '✔'
|
status = '✔'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not only_enabled or status == '✔' then
|
if not only_enabled or status == '✔' then
|
||||||
-- get the name
|
-- get the name
|
||||||
v = string.match (v, "(.*)%.lua")
|
v = string.match (v, "(.*)%.lua")
|
||||||
text = text..v..' '..status..'\n'
|
text = text..v..' '..status..'\n'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reload_plugins( )
|
local function reload_plugins( )
|
||||||
plugins = {}
|
plugins = {}
|
||||||
load_plugins()
|
load_plugins()
|
||||||
return list_plugins(true)
|
return list_plugins(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function enable_plugin( filename )
|
local function enable_plugin( filename )
|
||||||
-- Check if plugin is enabled
|
-- Check if plugin is enabled
|
||||||
if plugin_enabled(filename) then
|
if plugin_enabled(filename) then
|
||||||
return 'Plugin '..filename..' is enabled'
|
return 'Plugin '..filename..' is enabled'
|
||||||
end
|
end
|
||||||
-- Checks if plugin exists
|
-- Checks if plugin exists
|
||||||
if plugin_exists(filename) then
|
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)
|
||||||
save_config()
|
save_config()
|
||||||
-- Reload the plugins
|
-- Reload the plugins
|
||||||
return reload_plugins( )
|
return reload_plugins( )
|
||||||
else
|
else
|
||||||
return 'Plugin '..filename..' does not exists'
|
return 'Plugin '..filename..' does not exists'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disable_plugin( name )
|
local function disable_plugin( name )
|
||||||
-- Check if plugins exists
|
-- Check if plugins exists
|
||||||
if not plugin_exists(name) then
|
if not plugin_exists(name) then
|
||||||
return 'Plugin '..name..' does not exists'
|
return 'Plugin '..name..' does not exists'
|
||||||
end
|
end
|
||||||
local k = plugin_enabled(name)
|
local k = plugin_enabled(name)
|
||||||
-- Check if plugin is enabled
|
-- Check if plugin is enabled
|
||||||
if not k then
|
if not k then
|
||||||
return 'Plugin '..name..' not enabled'
|
return 'Plugin '..name..' not enabled'
|
||||||
end
|
end
|
||||||
-- Disable and reload
|
-- Disable and reload
|
||||||
table.remove(_config.enabled_plugins, k)
|
table.remove(_config.enabled_plugins, k)
|
||||||
save_config( )
|
save_config( )
|
||||||
return reload_plugins(true)
|
return reload_plugins(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run(msg, matches)
|
local function run(msg, matches)
|
||||||
-- Show the available plugins
|
-- Show the available plugins
|
||||||
if matches[1] == '!plugins' then
|
if matches[1] == '!plugins' then
|
||||||
return list_plugins()
|
return list_plugins()
|
||||||
end
|
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
|
-- Disable a plugin
|
||||||
if matches[1] == 'disable' then
|
if matches[1] == 'disable' then
|
||||||
print("disable: "..matches[2])
|
print("disable: "..matches[2])
|
||||||
return disable_plugin(matches[2])
|
return disable_plugin(matches[2])
|
||||||
end
|
end
|
||||||
-- Reload all the plugins!
|
-- Reload all the plugins!
|
||||||
if matches[1] == 'reload' then
|
if matches[1] == 'reload' then
|
||||||
return reload_plugins(true)
|
return reload_plugins(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Plugin to manage other plugins. Enable, disable or reload.",
|
description = "Plugin to manage other plugins. Enable, disable or reload.",
|
||||||
usage = {
|
usage = {
|
||||||
"!plugins: list all plugins",
|
"!plugins: list all plugins",
|
||||||
"!plugins enable [plugin]: enable plugin",
|
"!plugins enable [plugin]: enable plugin",
|
||||||
"!plugins disable [plugin]: disable plugin",
|
"!plugins disable [plugin]: disable plugin",
|
||||||
"!plugins reload: reloads all plugins" },
|
"!plugins reload: reloads all plugins" },
|
||||||
patterns = {
|
patterns = {
|
||||||
"^!plugins$",
|
"^!plugins$",
|
||||||
"^!plugins? (enable) (.*)$",
|
"^!plugins? (enable) (.*)$",
|
||||||
"^!plugins? (disable) (.*)$",
|
"^!plugins? (disable) (.*)$",
|
||||||
"^!plugins? (reload)$" },
|
"^!plugins? (reload)$" },
|
||||||
run = run,
|
run = run,
|
||||||
privileged = true
|
privileged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
Reference in New Issue
Block a user