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-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-08-07 02:17:37 +02:00
help.triggers = {
" ^/hilfe (.+) " ,
" ^/help (.+) " ,
" ^/(hilfe)_(.+) " ,
2016-08-07 21:30:28 +02:00
" ^/hilfe$ "
2016-08-07 02:17:37 +02:00
}
2016-08-07 00:01:42 +02:00
help.inline_triggers = {
" ^hilfe (.+) " ,
" ^help (.+) "
}
end
2016-08-07 02:17:37 +02:00
function help : inline_callback ( inline_query , config , matches )
2016-08-07 00:01:42 +02:00
local query = matches [ 1 ]
2016-08-08 17:23:36 +02:00
for n = 1 , # self.plugins do
local plugin = self.plugins [ n ]
2016-08-07 00:01:42 +02:00
if plugin.command and utilities.get_word ( plugin.command , 1 ) == query and plugin.doc then
local doc = plugin.doc
local doc = doc : gsub ( ' " ' , ' \\ " ' )
local doc = doc : gsub ( ' \\ n ' , ' \\ \n ' )
local chosen_plugin = utilities.get_word ( plugin.command , 1 )
2016-08-07 21:20:48 +02:00
local results = ' [{"type":"article","id":"9","title":"Hilfe für ' .. chosen_plugin .. ' ","description":"Hilfe für das Plugin \\ " ' .. chosen_plugin .. ' \\ " wird gepostet.","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/help/hilfe.jpg","input_message_content":{"message_text":" ' .. doc .. ' ","parse_mode":"Markdown"}}] '
2016-08-24 15:38:29 +02:00
utilities.answer_inline_query ( inline_query , results , 600 , nil , nil , ' Hilfe anzeigen ' , ' hilfe_ ' .. chosen_plugin )
2016-08-07 00:01:42 +02:00
end
end
2016-08-24 15:38:29 +02:00
utilities.answer_inline_query ( inline_query )
2016-06-18 16:41:21 +02:00
end
2016-08-07 02:17:37 +02:00
function help : action ( msg , config , matches )
if matches [ 2 ] then
input = matches [ 2 ]
elseif matches [ 1 ] ~= ' /hilfe ' then
input = matches [ 1 ]
else
input = nil
end
2016-04-14 05:48:20 +02:00
2016-08-07 02:17:37 +02: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
local commandlist = { }
local help_text = ' *Verfügbare Befehle:* \n • ' .. config.cmd_pat
2016-08-08 17:23:36 +02:00
for n = 1 , # self.plugins do
local plugin = self.plugins [ n ]
2016-08-07 02:17:37 +02:00
if plugin.command then
2016-08-07 20:45:51 +02:00
commandlist [ # commandlist + 1 ] = plugin.command
2016-08-07 02:17:37 +02:00
end
2015-11-25 03:22:04 +01:00
end
2016-04-11 06:04:47 +02:00
2016-08-07 20:45:51 +02:00
commandlist [ # commandlist + 1 ] = ' hilfe [Befehl] '
2016-04-27 05:43:15 +02:00
table.sort ( commandlist )
2016-08-07 02:17:37 +02:00
local help_text = help_text .. table.concat ( commandlist , ' \n • ' .. config.cmd_pat ) .. ' \n Parameter: <benötigt> [optional] '
local help_text = help_text : gsub ( ' %[ ' , ' \\ [ ' )
2016-01-12 11:22:28 +01:00
2016-08-24 15:38:29 +02:00
local res = utilities.send_message ( msg.from . id , help_text , true , nil , true )
2016-08-07 02:17:37 +02:00
if not res then
2016-08-24 15:38:29 +02:00
utilities.send_reply ( msg , ' Bitte schreibe mir zuerst [privat](http://telegram.me/ ' .. self.info . username .. ' ?start=help) für eine Hilfe. ' , true )
2016-08-07 02:17:37 +02:00
elseif msg.chat . type ~= ' private ' then
2016-08-24 15:38:29 +02:00
utilities.send_reply ( msg , ' Ich habe dir die Hilfe privat gesendet!. ' )
2015-07-03 00:15:52 +02:00
end
2016-08-07 02:17:37 +02:00
return
end
2015-07-03 00:15:52 +02:00
2016-08-08 17:23:36 +02:00
for n = 1 , # self.plugins do
local plugin = self.plugins [ n ]
2016-08-07 02:17:37 +02:00
if plugin.command and utilities.get_word ( plugin.command , 1 ) == input and plugin.doc then
local output = ' *Hilfe für* _ ' .. utilities.get_word ( plugin.command , 1 ) .. ' _ *:* ' .. plugin.doc
2016-08-24 15:38:29 +02:00
utilities.send_message ( msg.chat . id , output , true , nil , true )
2016-08-07 02:17:37 +02:00
return
2016-01-08 14:44:37 +01:00
end
2016-08-07 02:17:37 +02:00
end
2016-01-08 14:44:37 +01:00
2016-08-24 15:38:29 +02:00
utilities.send_reply ( msg , ' Für diesen Befehl gibt es keine Hilfe. ' )
2015-07-03 00:15:52 +02:00
end
2016-08-07 02:17:37 +02:00
return help