This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/plugins/help.lua

55 lines
1.4 KiB
Lua
Raw Normal View History

-- This plugin should go at the end of your plugin list in
-- config.lua, but not after greetings.lua.
2015-07-03 00:15:52 +02:00
local commandlist = {}
for i,v in ipairs(plugins) do
if v.command then
table.insert(commandlist, v.command)
end
end
2015-07-08 04:24:12 +02:00
table.insert(commandlist, 'help [command]')
table.sort(commandlist)
local help_text = '*Available commands:*\n• /' .. table.concat(commandlist,'\n• /') .. '\nArguments: <required> [optional]'
help_text = help_text:gsub('%[', '\\[')
2015-07-03 00:15:52 +02:00
local triggers = {
'^/help[@'..bot.username..']*',
'^/h[@'..bot.username..']*$'
}
2015-07-03 00:15:52 +02:00
local action = function(msg)
2015-07-04 16:54:41 +02:00
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.')
2015-07-03 00:15:52 +02:00
end
return
2015-07-03 00:15:52 +02:00
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.')
2015-07-03 00:15:52 +02:00
end
return {
action = action,
triggers = triggers
}