2015-11-25 03:22:04 +01:00
|
|
|
-- 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
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
local help = {}
|
|
|
|
|
2016-06-07 06:31:34 +02:00
|
|
|
local utilities = require('otouto.utilities')
|
2016-04-11 06:04:47 +02:00
|
|
|
|
2016-04-14 05:48:20 +02:00
|
|
|
local help_text
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
function help:init(config)
|
2016-06-18 16:41:21 +02:00
|
|
|
help.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('hilfe', true):t('help', true).table
|
|
|
|
end
|
|
|
|
|
|
|
|
function help:action(msg, config)
|
2016-04-27 05:43:15 +02:00
|
|
|
local commandlist = {}
|
2016-06-11 14:46:41 +02:00
|
|
|
help_text = '*Verfügbare Befehle:*\n• '..config.cmd_pat
|
2016-04-14 05:48:20 +02:00
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
for _,plugin in ipairs(self.plugins) do
|
|
|
|
if plugin.command then
|
2016-06-18 16:41:21 +02:00
|
|
|
|
2016-04-27 05:43:15 +02:00
|
|
|
table.insert(commandlist, plugin.command)
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2016-04-11 06:04:47 +02:00
|
|
|
|
2016-07-25 13:47:39 +02:00
|
|
|
table.insert(commandlist, 'hilfe [Befehl]')
|
2016-04-27 05:43:15 +02:00
|
|
|
table.sort(commandlist)
|
2016-06-11 14:46:41 +02:00
|
|
|
help_text = help_text .. table.concat(commandlist, '\n• '..config.cmd_pat) .. '\nParameter: <benötigt> [optional]'
|
2016-01-12 11:22:28 +01:00
|
|
|
|
2016-04-27 05:43:15 +02:00
|
|
|
help_text = help_text:gsub('%[', '\\[')
|
2016-04-08 23:12:02 +02:00
|
|
|
local input = utilities.input(msg.text_lower)
|
2016-01-08 14:44:37 +01:00
|
|
|
|
|
|
|
-- 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
|
2016-05-29 19:08:39 +02:00
|
|
|
local res = utilities.send_message(self, msg.from.id, help_text, true, nil, true)
|
2016-01-08 14:44:37 +01:00
|
|
|
if not res then
|
2016-06-11 14:46:41 +02:00
|
|
|
utilities.send_reply(self, msg, 'Bitte schreibe mir zuerst [privat](http://telegram.me/' .. self.info.username .. '?start=help) für eine Hilfe.', true)
|
2016-01-08 14:44:37 +01:00
|
|
|
elseif msg.chat.type ~= 'private' then
|
2016-06-11 14:46:41 +02:00
|
|
|
utilities.send_reply(self, msg, 'Ich habe dir die Hilfe per PN gesendet!.')
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
2016-01-08 14:44:37 +01:00
|
|
|
return
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
for _,plugin in ipairs(self.plugins) do
|
|
|
|
if plugin.command and utilities.get_word(plugin.command, 1) == input and plugin.doc then
|
2016-06-11 14:46:41 +02:00
|
|
|
local output = '*Hilfe für* _' .. utilities.get_word(plugin.command, 1) .. '_ *:*' .. plugin.doc
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
2016-01-08 14:44:37 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-11 14:46:41 +02:00
|
|
|
utilities.send_reply(self, msg, 'Für diesen Befehl gibt es keine Hilfe.')
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return help
|