help plugin overwritten

thx @synk0
This commit is contained in:
Akamaru 2015-08-01 13:27:29 +02:00
parent f4b7f3f5fe
commit c0c2ae7925

View File

@ -1,70 +1,117 @@
do do
-- Returns true if is not empty function pairsByKeys(t, f)
local function has_usage_data(dict) local a = {}
if (dict.usage == nil or dict.usage == '') then for n in pairs(t) do table.insert(a, n) end
return false table.sort(a, f)
end local i = 0 -- iterator variable
return true local iter = function () -- iterator function
end i = i + 1
if a[i] == nil then return nil
-- Get commands for that plugin else return a[i], t[a[i]]
local function plugin_help(name) end
local plugin = plugins[name]
if not plugin then return nil end
local text = ""
if (type(plugin.usage) == "table") then
for ku,usage in pairs(plugin.usage) do
text = text..usage..'\n'
end end
text = text..'\n' return iter
elseif has_usage_data(plugin) then -- Is not empty
text = text..plugin.usage..'\n\n'
end end
return text
end
-- !help command -- Returns true if is not empty
local function telegram_help() local function has_usage_data(dict)
local text = "Plugin Liste: \n\n" if (dict.usage == nil or dict.usage == '') then
-- Plugins names return false
for name in pairs(plugins) do end
text = text..name..'\n' return true
end end
text = text..'\n'..'Benutze "/hilfe [Plugin Name]" für mehr Informationen'
text = text..'\n'..'Oder "/hilfe all" um alles zu sehen.'
return text
end
-- !help all command -- Get commands for that plugin
local function help_all() local function plugin_help(name,number)
local ret = "" local plugin = ""
for name in pairs(plugins) do if number then
ret = ret .. plugin_help(name) local i = 0
end for name in pairsByKeys(plugins) do
return ret if plugins[name].hide then
end name = nil
else
i = i + 1
if i == tonumber(number) then
plugin = plugins[name]
end
end
end
else
plugin = plugins[name]
if not plugin then return nil end
end
local function run(msg, matches) local text = ""
if matches[1] == "/hilfe" then if (type(plugin.usage) == "table") then
return telegram_help() for ku,usage in pairs(plugin.usage) do
elseif matches[1] == "/hilfe all" then text = text..usage..'\n'
return help_all() end
else text = text..'\n'
local text = plugin_help(matches[1]) elseif has_usage_data(plugin) then -- Is not empty
if not text then text = text..plugin.usage..'\n\n'
text = telegram_help()
end end
return text return text
end end
end
return {
description = "Zeigt die Plugins und Befehle",
usage = {"/hilfe","/hilfe all","/hilfe [Plugin]"},
patterns = {"^/hilfe$","^/hilfe all","^/hilfe (.+)"},
run = run
}
end -- !help command
local function telegram_help()
local i = 0
local text = "Liste aller Plugins\n\n"
-- Plugins names
for name in pairsByKeys(plugins) do
if plugins[name].hide then
name = nil
else
i = i + 1
text = text..i..'. '..name..'\n'
end
end
text = text..'\n'..i.." Plugins sind zurzeit aktiviert"
text = text..'\n'..'Benutze "/hilfe [Plugin Nummer]" fuer mehr Informationen'
text = text..'\n'..'Fragen und/oder Anregungen: @Akamaru'
return text
end
-- !help all command
local function help_all()
local ret = ""
for name in pairsByKeys(plugins) do
if plugins[name].hide then
name = nil
else
ret = ret .. plugin_help(name)
end
end
return ret
end
local function run(msg, matches)
if matches[1] == "/hilfe" then
return telegram_help()
elseif matches[1] == "/hilfe all" then
return help_all()
else
local text = ""
if tonumber(matches[1]) then
text = plugin_help(nil,matches[1])
else
text = plugin_help(matches[1])
end
if not text then
text = telegram_help()
end
return text
end
end
return {
description = "Zeigt die Plugins und Befehle",
usage = {"/hilfe","/hilfe all","/hilfe [Plugin]"},
patterns = {"^/hilfe$","^/hilfe all","^/hilfe (.+)"},
run = run
}
end