Rewrote help.lua and added markup support to several plugins.
help.lua has been rewritten to support "/help command". New variable "command" has been added to plugins for the syntax (w/out slash) to be displayed in main help message. "doc" will be displayed upon "/help command". Output of >12 plugins has been reformated to utilize markup. There is a fairly standard style throughout plugins. get_word() in utilities.lua now has defaults for nil arguments.
This commit is contained in:
@ -1,16 +1,18 @@
|
||||
-- This plugin should go at the end of your plugin list in
|
||||
-- config.lua, but not after greetings.lua.
|
||||
|
||||
local help_text = 'Available commands:\n'
|
||||
local help_text = '*Available commands:*'
|
||||
|
||||
for i,v in ipairs(plugins) do
|
||||
if v.doc then
|
||||
local a = string.sub(v.doc, 1, string.find(v.doc, '\n')-1)
|
||||
help_text = help_text .. a .. '\n'
|
||||
if v.command then
|
||||
help_text = help_text .. '\n /' .. v.command:gsub('%[', '\\[')
|
||||
end
|
||||
end
|
||||
|
||||
local help_text = help_text .. 'Arguments: <required> [optional]'
|
||||
help_text = help_text .. [[\n
|
||||
/help <command>
|
||||
Arguments: <required> \[optional]
|
||||
]]
|
||||
|
||||
local triggers = {
|
||||
'^/help[@'..bot.username..']*',
|
||||
@ -20,16 +22,30 @@ local triggers = {
|
||||
|
||||
local action = function(msg)
|
||||
|
||||
if msg.from.id ~= msg.chat.id then
|
||||
if sendMessage(msg.from.id, help_text) then
|
||||
local input = msg.text_lower:input()
|
||||
|
||||
-- Attempts to send the help message via PM.
|
||||
-- If msg is from a group, it tells the group whether the PM was successful.
|
||||
if not input then
|
||||
local res = sendMessage(msg.from.id, help_text, true, nil, true)
|
||||
if not res then
|
||||
sendReply(msg, 'Please message me privately for a list of commands.')
|
||||
elseif msg.chat.type ~= 'private' then
|
||||
sendReply(msg, 'I have sent you the requested information in a private message.')
|
||||
else
|
||||
sendReply(msg, help_text)
|
||||
end
|
||||
else
|
||||
sendReply(msg, help_text)
|
||||
return
|
||||
end
|
||||
|
||||
for i,v in ipairs(plugins) do
|
||||
if v.command and get_word(v.command, 1) == input and v.doc then
|
||||
local output = '*Help for* _' .. get_word(v.command, 1) .. '_ *:*\n' .. v.doc
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
sendReply(msg, 'Sorry, there is no help for that command.')
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user