2015-01-23 23:49:51 +01:00
|
|
|
-- Generate an HTML table for GitHub
|
|
|
|
function html_help()
|
|
|
|
local text = [[<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<td><strong>Name</strong></td>
|
|
|
|
<td><strong>Description</strong></td>
|
|
|
|
<td><strong>Usage</strong></td>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>]]
|
2014-11-04 16:09:08 +01:00
|
|
|
|
2015-01-23 23:49:51 +01:00
|
|
|
for k,v in pairs(plugins_names()) do
|
|
|
|
t = loadfile("plugins/"..v)()
|
|
|
|
text = text.."<tr>"
|
|
|
|
text = text.."<td>"..v.."</td>"
|
|
|
|
text = text.."<td>"..t.description.."</td>"
|
|
|
|
text = text.."<td>"
|
|
|
|
if (type(t.usage) == "table") then
|
|
|
|
for ku,vu in pairs(t.usage) do
|
|
|
|
text = text..vu.."<br>"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
text = text..t.usage
|
|
|
|
end
|
|
|
|
text = text.."</td>"
|
|
|
|
text = text.."</tr>"
|
|
|
|
end
|
|
|
|
text = text.."</tbody></table>"
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
2015-02-04 23:03:42 +01:00
|
|
|
function has_usage_data(dict)
|
|
|
|
if (dict.usage == nil or dict.usage == '') then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-01-23 23:49:51 +01:00
|
|
|
function telegram_help( )
|
2014-11-04 16:09:08 +01:00
|
|
|
local ret = ""
|
|
|
|
for k, dict in pairs(plugins) do
|
2015-02-04 23:03:42 +01:00
|
|
|
if (type(dict.usage) == "table") then
|
|
|
|
for ku,usage in pairs(dict.usage) do
|
|
|
|
ret = ret..usage..'\n'
|
2015-01-23 23:49:51 +01:00
|
|
|
end
|
2015-02-04 23:03:42 +01:00
|
|
|
ret = ret..'\n'
|
|
|
|
elseif has_usage_data(dict) then -- Is not empty
|
|
|
|
ret = ret..dict.usage..'\n\n'
|
2015-01-23 23:49:51 +01:00
|
|
|
end
|
2014-11-04 16:09:08 +01:00
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2015-01-23 23:49:51 +01:00
|
|
|
function run(msg, matches)
|
|
|
|
if matches[1] == "!help md" then
|
|
|
|
return html_help()
|
|
|
|
else
|
|
|
|
return telegram_help()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-04 16:09:08 +01:00
|
|
|
return {
|
2015-03-04 23:51:36 +01:00
|
|
|
description = "Help plugin. Get info from other plugins. ",
|
|
|
|
usage = {
|
|
|
|
"!help: Show all the help",
|
|
|
|
"!help md: Generate a GitHub Markdown table"
|
|
|
|
},
|
|
|
|
patterns = {
|
|
|
|
"^!help$",
|
|
|
|
"^!help md$"
|
|
|
|
},
|
|
|
|
run = run
|
2014-11-22 15:05:54 +01:00
|
|
|
}
|