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/otouto/plugins/help.lua
topkecleon acc7046d64 administration 1.13.1
Added optional target for kick/ban logs. Added flag 7 to use default log
 per group. This way, a realm can have a public kick/ban log but governors
 are able to opt out. Added flag 8, antilink. Kicks for Telegram join links
 which do not refer to groups within the realm. Added flag 9, modrights, to
 give moderators access to changing the group photo, title, link, and motd
 (config option is deprecated. RIP). /unban will reset the target's autokick
 counter. Added configuration for default flag settings.

Revision to bindings.lua.
BASE_URL has been moved to bindings. There is no real reason for it to remain
in instance. Token is passed to bindings.init at load. All plugins have been
updated accordingly.
2016-08-23 00:16:32 -04:00

54 lines
2.3 KiB
Lua

local utilities = require('otouto.utilities')
local help = {}
function help:init(config)
help.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('help', true):t('h', true).table
help.command = 'help [command]'
help.doc = config.cmd_pat .. 'help [command] \nReturns usage information for a given command.'
end
function help:action(msg, config)
local input = utilities.input(msg.text_lower)
if input then
if not help.help_word then
for _, plugin in ipairs(self.plugins) do
if plugin.command and plugin.doc and not plugin.help_word then
plugin.help_word = utilities.get_word(plugin.command, 1)
end
end
end
for _,plugin in ipairs(self.plugins) do
if plugin.help_word == input:gsub('^/', '') then
local output = '*Help for* _' .. plugin.help_word .. '_*:*\n' .. plugin.doc
utilities.send_message(msg.chat.id, output, true, nil, true)
return
end
end
utilities.send_reply(msg, 'Sorry, there is no help for that command.')
else
-- Generate the help message on first run.
if not help.text then
local commandlist = {}
for _, plugin in ipairs(self.plugins) do
if plugin.command then
table.insert(commandlist, plugin.command)
end
end
table.sort(commandlist)
help.text = '*Available commands:*\n' .. config.cmd_pat .. table.concat(commandlist, '\n'..config.cmd_pat) .. '\nArguments: <required> [optional]'
help.text = help.text:gsub('%[', '\\[')
end
-- Attempt to send the help message via PM.
-- If msg is from a group, tell the group whether the PM was successful.
local res = utilities.send_message(msg.from.id, help.text, true, nil, true)
if not res then
utilities.send_reply(msg, 'Please [message me privately](http://telegram.me/' .. self.info.username .. '?start=help) for a list of commands.', true)
elseif msg.chat.type ~= 'private' then
utilities.send_reply(msg, 'I have sent you the requested information in a private message.')
end
end
end
return help