Better help
This commit is contained in:
parent
c1d2885e9c
commit
6ebf354735
@ -37,38 +37,68 @@ function has_usage_data(dict)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function telegram_help( )
|
function plugin_help(name)
|
||||||
local ret = ""
|
local plugin = plugins[name]
|
||||||
for k, dict in pairs(plugins) do
|
if not plugin then return nil end
|
||||||
if (type(dict.usage) == "table") then
|
|
||||||
for ku,usage in pairs(dict.usage) do
|
local text = ""
|
||||||
ret = ret..usage..'\n'
|
if (type(plugin.usage) == "table") then
|
||||||
end
|
for ku,usage in pairs(plugin.usage) do
|
||||||
ret = ret..'\n'
|
text = text..usage..'\n'
|
||||||
elseif has_usage_data(dict) then -- Is not empty
|
|
||||||
ret = ret..dict.usage..'\n\n'
|
|
||||||
end
|
end
|
||||||
|
text = text..'\n'
|
||||||
|
elseif has_usage_data(plugin) then -- Is not empty
|
||||||
|
text = text..plugin.usage..'\n\n'
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
-- !help command
|
||||||
|
function telegram_help()
|
||||||
|
local text = "Plugin list: \n\n"
|
||||||
|
-- Plugins names
|
||||||
|
for name in pairs(plugins) do
|
||||||
|
text = text..name..'\n'
|
||||||
|
end
|
||||||
|
text = text..'\n'..'Write "!help [plugin name]" for more info.'
|
||||||
|
text = text..'\n'..'Or "!help all" to show all info.'
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
-- !help all command
|
||||||
|
function help_all()
|
||||||
|
local ret = ""
|
||||||
|
for name in pairs(plugins) do
|
||||||
|
ret = ret .. plugin_help(name)
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
function run(msg, matches)
|
||||||
if matches[1] == "!help md" then
|
if matches[1] == "!help" then
|
||||||
return html_help()
|
|
||||||
else
|
|
||||||
return telegram_help()
|
return telegram_help()
|
||||||
|
elseif matches[1] == "!help all" then
|
||||||
|
return help_all()
|
||||||
|
else
|
||||||
|
local text = plugin_help(matches[1])
|
||||||
|
if not text then
|
||||||
|
text = telegram_help()
|
||||||
|
end
|
||||||
|
return text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Help plugin. Get info from other plugins. ",
|
description = "Help plugin. Get info from other plugins. ",
|
||||||
usage = {
|
usage = {
|
||||||
"!help: Show all the help",
|
"!help: Show list of plugins.",
|
||||||
"!help md: Generate a GitHub Markdown table"
|
"!help all: Show all commands for every plugin.",
|
||||||
|
"!help [plugin name]: Commands for that plugin."
|
||||||
},
|
},
|
||||||
patterns = {
|
patterns = {
|
||||||
"^!help$",
|
"^!help$",
|
||||||
"^!help md$"
|
"^!help all",
|
||||||
|
"^!help (.+)"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
Reference in New Issue
Block a user