2015-04-05 16:27:04 +02:00
|
|
|
do
|
|
|
|
|
2015-05-28 16:47:30 +02:00
|
|
|
-- Returns the key (index) in the config.enabled_plugins table
|
2015-04-05 16:27:04 +02:00
|
|
|
local function plugin_enabled( name )
|
2015-04-06 23:28:09 +02:00
|
|
|
for k,v in pairs(_config.enabled_plugins) do
|
|
|
|
if name == v then
|
|
|
|
return k
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- If not found
|
|
|
|
return false
|
2014-12-24 12:44:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Returns true if file exists in plugins folder
|
2015-04-05 16:27:04 +02:00
|
|
|
local function plugin_exists( name )
|
2014-12-24 12:44:57 +01:00
|
|
|
for k,v in pairs(plugins_names()) do
|
2014-12-31 17:14:48 +01:00
|
|
|
if name..'.lua' == v then
|
2014-12-24 12:44:57 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2015-04-05 16:27:04 +02:00
|
|
|
local function list_plugins(only_enabled)
|
2015-04-06 23:28:09 +02:00
|
|
|
local text = ''
|
|
|
|
for k, v in pairs( plugins_names( )) do
|
|
|
|
-- ✔ enabled, ❌ disabled
|
|
|
|
local status = '❌'
|
|
|
|
-- Check if is enabled
|
|
|
|
for k2, v2 in pairs(_config.enabled_plugins) do
|
|
|
|
if v == v2..'.lua' then
|
|
|
|
status = '✔'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not only_enabled or status == '✔' then
|
|
|
|
-- get the name
|
|
|
|
v = string.match (v, "(.*)%.lua")
|
|
|
|
text = text..v..' '..status..'\n'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return text
|
2014-12-24 01:38:41 +01:00
|
|
|
end
|
|
|
|
|
2015-04-06 23:26:13 +02:00
|
|
|
local function reload_plugins( )
|
2015-04-06 23:28:09 +02:00
|
|
|
plugins = {}
|
|
|
|
load_plugins()
|
|
|
|
return list_plugins(true)
|
2015-04-06 23:26:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-04-16 21:42:05 +02:00
|
|
|
local function enable_plugin( plugin_name )
|
2015-05-12 20:15:15 +02:00
|
|
|
print('Überprüfe ob "'..plugin_name..'" existiert')
|
2015-04-06 23:28:09 +02:00
|
|
|
-- Check if plugin is enabled
|
2015-04-16 21:42:05 +02:00
|
|
|
if plugin_enabled(plugin_name) then
|
2015-04-17 16:29:30 +02:00
|
|
|
return 'Plugin "'..plugin_name..'" ist aktiviert!'
|
2015-04-06 23:28:09 +02:00
|
|
|
end
|
|
|
|
-- Checks if plugin exists
|
2015-04-16 21:42:05 +02:00
|
|
|
if plugin_exists(plugin_name) then
|
2015-04-06 23:28:09 +02:00
|
|
|
-- Add to the config table
|
2015-04-16 21:42:05 +02:00
|
|
|
table.insert(_config.enabled_plugins, plugin_name)
|
2015-05-12 20:15:15 +02:00
|
|
|
print(plugin_name..' zu to _config table hinzugefügt')
|
2015-04-06 23:28:09 +02:00
|
|
|
save_config()
|
|
|
|
-- Reload the plugins
|
|
|
|
return reload_plugins( )
|
|
|
|
else
|
2015-05-12 20:15:15 +02:00
|
|
|
return 'Das Plugin "'..plugin_name..'" existiert nicht!'
|
2015-04-06 23:28:09 +02:00
|
|
|
end
|
2015-04-06 23:26:13 +02:00
|
|
|
end
|
|
|
|
|
2015-04-12 21:55:01 +02:00
|
|
|
local function disable_plugin( name, chat )
|
2015-04-06 23:28:09 +02:00
|
|
|
-- Check if plugins exists
|
|
|
|
if not plugin_exists(name) then
|
2015-05-12 20:15:15 +02:00
|
|
|
return 'Das Plugin "'..plugin_name..'" existiert nicht!'
|
2015-04-06 23:28:09 +02:00
|
|
|
end
|
|
|
|
local k = plugin_enabled(name)
|
|
|
|
-- Check if plugin is enabled
|
|
|
|
if not k then
|
2015-04-17 16:29:30 +02:00
|
|
|
return 'Das Plugin "'..name..'" ist nicht aktiviert!'
|
2015-04-06 23:28:09 +02:00
|
|
|
end
|
|
|
|
-- Disable and reload
|
|
|
|
table.remove(_config.enabled_plugins, k)
|
|
|
|
save_config( )
|
|
|
|
return reload_plugins(true)
|
2015-04-06 23:26:13 +02:00
|
|
|
end
|
|
|
|
|
2015-04-12 21:55:01 +02:00
|
|
|
local function disable_plugin_on_chat(receiver, plugin)
|
|
|
|
if not plugin_exists(plugin) then
|
2015-05-12 20:15:15 +02:00
|
|
|
return "Dieses Plugin existiert nicht!"
|
2015-04-12 21:55:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if not _config.disabled_plugin_on_chat then
|
|
|
|
_config.disabled_plugin_on_chat = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
if not _config.disabled_plugin_on_chat[receiver] then
|
|
|
|
_config.disabled_plugin_on_chat[receiver] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
_config.disabled_plugin_on_chat[receiver][plugin] = true
|
|
|
|
|
|
|
|
save_config()
|
2015-04-17 16:29:30 +02:00
|
|
|
return 'Das Plugin "'..plugin..'" ist hier nun deaktiviert!'
|
2015-04-12 21:55:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function reenable_plugin_on_chat(receiver, plugin)
|
|
|
|
if not _config.disabled_plugin_on_chat then
|
2015-05-12 20:15:15 +02:00
|
|
|
return 'Hier sind keine Plugins deaktiviert.'
|
2015-04-12 21:55:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if not _config.disabled_plugin_on_chat[receiver] then
|
2015-05-12 20:15:15 +02:00
|
|
|
return 'Hier sind keine Plugins deaktiviert.'
|
2015-04-12 21:55:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if not _config.disabled_plugin_on_chat[receiver][plugin] then
|
2015-04-14 20:21:23 +02:00
|
|
|
return 'Dieses Plugin ist nicht deaktiviert!'
|
2015-04-12 21:55:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
_config.disabled_plugin_on_chat[receiver][plugin] = false
|
2015-04-16 21:42:05 +02:00
|
|
|
save_config()
|
2015-04-17 16:29:30 +02:00
|
|
|
return 'Das Plugin "'..plugin..'" ist wieder aktiviert!'
|
2015-04-12 21:55:01 +02:00
|
|
|
end
|
|
|
|
|
2015-04-05 16:27:04 +02:00
|
|
|
local function run(msg, matches)
|
2015-04-06 23:28:09 +02:00
|
|
|
-- Show the available plugins
|
2015-04-14 20:21:23 +02:00
|
|
|
if matches[1] == '/plugins' then
|
2015-04-06 23:28:09 +02:00
|
|
|
return list_plugins()
|
|
|
|
end
|
2015-04-12 21:55:01 +02:00
|
|
|
|
2015-05-28 16:47:30 +02:00
|
|
|
-- Re-enable a plugin for this chat
|
2015-04-12 21:55:01 +02:00
|
|
|
if matches[1] == 'enable' and matches[3] == 'chat' then
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
local plugin = matches[2]
|
2015-05-12 20:15:15 +02:00
|
|
|
print('Aktiviere "'..plugin..'" in diesem Chat')
|
2015-04-12 21:55:01 +02:00
|
|
|
return reenable_plugin_on_chat(receiver, plugin)
|
|
|
|
end
|
|
|
|
|
2015-04-06 23:28:09 +02:00
|
|
|
-- Enable a plugin
|
|
|
|
if matches[1] == 'enable' then
|
2015-04-17 16:29:30 +02:00
|
|
|
local plugin_name = matches[2]
|
2015-05-12 20:15:15 +02:00
|
|
|
print("A+: "..matches[2])
|
2015-04-16 21:42:05 +02:00
|
|
|
return enable_plugin(plugin_name)
|
2015-04-06 23:28:09 +02:00
|
|
|
end
|
2015-04-12 21:55:01 +02:00
|
|
|
|
|
|
|
-- Disable a plugin on a chat
|
|
|
|
if matches[1] == 'disable' and matches[3] == 'chat' then
|
|
|
|
local plugin = matches[2]
|
|
|
|
local receiver = get_receiver(msg)
|
2015-05-12 20:15:15 +02:00
|
|
|
print('Deaktiviere "'..plugin..'" in diesem Chat')
|
2015-04-12 21:55:01 +02:00
|
|
|
return disable_plugin_on_chat(receiver, plugin)
|
|
|
|
end
|
|
|
|
|
2015-04-06 23:28:09 +02:00
|
|
|
-- Disable a plugin
|
|
|
|
if matches[1] == 'disable' then
|
2015-05-12 20:15:15 +02:00
|
|
|
print("Deaktiviere: "..matches[2])
|
2015-04-06 23:28:09 +02:00
|
|
|
return disable_plugin(matches[2])
|
|
|
|
end
|
2015-04-12 21:55:01 +02:00
|
|
|
|
2015-04-06 23:28:09 +02:00
|
|
|
-- Reload all the plugins!
|
|
|
|
if matches[1] == 'reload' then
|
|
|
|
return reload_plugins(true)
|
|
|
|
end
|
2014-12-24 01:38:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-04-28 17:49:11 +02:00
|
|
|
description = "Plugin Verwaltung",
|
|
|
|
usage = { "Das kann nur Akamaru" },
|
|
|
|
patterns = {"^/plugins$","^/plugins? (enable) ([%w_%.%-]+)$","^/plugins? (disable) ([%w_%.%-]+)$","^/plugins? (enable) ([%w_%.%-]+) (chat)","^/plugins? (disable) ([%w_%.%-]+) (chat)","^/plugins? (reload)$" },
|
2015-04-06 23:28:09 +02:00
|
|
|
run = run,
|
|
|
|
privileged = true
|
2015-04-17 16:29:30 +02:00
|
|
|
}
|
|
|
|
end
|