From 6ebf354735cce785cedc7fb87f2a6a47fe82b8a6 Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 5 Apr 2015 13:57:25 +0200 Subject: [PATCH] Better help --- plugins/help.lua | 62 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/plugins/help.lua b/plugins/help.lua index 186a2af..f3f062e 100644 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -37,38 +37,68 @@ function has_usage_data(dict) return true end -function telegram_help( ) - local ret = "" - for k, dict in pairs(plugins) do - if (type(dict.usage) == "table") then - for ku,usage in pairs(dict.usage) do - ret = ret..usage..'\n' - end - ret = ret..'\n' - elseif has_usage_data(dict) then -- Is not empty - ret = ret..dict.usage..'\n\n' +function plugin_help(name) + 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 + 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 return ret end function run(msg, matches) - if matches[1] == "!help md" then - return html_help() - else + if matches[1] == "!help" then 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 return { description = "Help plugin. Get info from other plugins. ", usage = { - "!help: Show all the help", - "!help md: Generate a GitHub Markdown table" + "!help: Show list of plugins.", + "!help all: Show all commands for every plugin.", + "!help [plugin name]: Commands for that plugin." }, patterns = { "^!help$", - "^!help md$" + "^!help all", + "^!help (.+)" }, run = run } \ No newline at end of file