- Inline-Querys werden jetzt unterstützt!
-> Das erste Plugin mit Inline-Query-Support ist "Echo", das wie @bold funktioniert -> Neue Variable zur Config hinzugefügt, mit der man bestimmen kann, ob nur whitelisted User oder alle Inline-Querys benutzen können - AFK zeigt AFK-Text jetzt fett an
This commit is contained in:
parent
d09ddc7520
commit
7ce4411a65
@ -21,6 +21,10 @@ Brawlbot v2 ist freie Software; du darfst in modifizieren und weiterverbreiten,
|
||||
* * *
|
||||
# Für User
|
||||
## Setup
|
||||
### Ubuntu und Debian
|
||||
Ubuntu und Debian liefern Luarocks nur für Lua 5.1 aus. Um Luarocks für Lua 5.2 zu verwenden, folge bitte der [Anleitung auf StackOverflow](http://stackoverflow.com/a/20359102)
|
||||
|
||||
### Setup
|
||||
Du benötigst **Lua 5.2+**, eine aktive **Redis-Instanz** und die folgenden **LuaRocks-Module**:
|
||||
* luasocket
|
||||
* luasec
|
||||
@ -28,6 +32,7 @@ Du benötigst **Lua 5.2+**, eine aktive **Redis-Instanz** und die folgenden **Lu
|
||||
* dkjson
|
||||
* lpeg
|
||||
* redis-lua
|
||||
* fakeredis
|
||||
* oauth
|
||||
* xml
|
||||
* feedparser
|
||||
|
@ -21,6 +21,10 @@ Sende /hilfe, um zu starten
|
||||
-- The symbol that starts a command. Usually noted as '/' in documentation.
|
||||
cmd_pat = '/',
|
||||
|
||||
-- false = only whitelisted users can use inline querys
|
||||
-- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted!
|
||||
enable_inline_for_everyone = true,
|
||||
|
||||
errors = { -- Generic error messages used in various plugins.
|
||||
generic = 'An unexpected error occurred.',
|
||||
connection = 'Verbindungsfehler.',
|
||||
|
@ -76,15 +76,6 @@ function bot:init(config) -- The function run when the bot is started or reloade
|
||||
|
||||
end
|
||||
|
||||
function bot:process_inline_query(inline_query, config) -- When an inline query is received
|
||||
-- remove comment to enable debugging
|
||||
if inline_query.query == '' then return end
|
||||
local result, error = bindings.request(self, 'answerInlineQuery', {
|
||||
inline_query_id = inline_query.id,
|
||||
results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/b.jpg","title":"Fett","description":"*'..inline_query.query..'*","input_message_content":{"message_text":"*'..inline_query.query..'*","parse_mode":"Markdown"}}]'
|
||||
} )
|
||||
end
|
||||
|
||||
function bot:on_msg_receive(msg, config) -- The fn run whenever a message is received.
|
||||
-- remove comment to enable debugging
|
||||
-- vardump(msg)
|
||||
@ -152,6 +143,23 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
||||
end
|
||||
end
|
||||
|
||||
-- NOTE: To enable InlineQuerys, send /setinline to @BotFather
|
||||
function bot:process_inline_query(inline_query, config) -- When an inline query is received
|
||||
-- remove comment to enable debugging
|
||||
-- vardump(inline_query)
|
||||
|
||||
if not config.enable_inline_for_everyone then
|
||||
local is_whitelisted = redis:get('whitelist:user#id'..inline_query.from.id)
|
||||
if not is_whitelisted then return end
|
||||
end
|
||||
|
||||
if inline_query.query == '' then return end
|
||||
|
||||
for _, plugin in ipairs(self.plugins) do
|
||||
match_inline_plugins(self, inline_query, config, plugin)
|
||||
end
|
||||
end
|
||||
|
||||
function bot:run(config)
|
||||
bot.init(self, config) -- Actually start the script.
|
||||
|
||||
@ -207,6 +215,26 @@ function pre_process_msg(self, msg, config)
|
||||
return new_msg
|
||||
end
|
||||
|
||||
function match_inline_plugins(self, inline_query, config, plugin)
|
||||
for _, trigger in pairs(plugin.inline_triggers or {}) do
|
||||
if string.match(string.lower(inline_query.query), trigger) then
|
||||
local success, result = pcall(function()
|
||||
for k, pattern in pairs(plugin.inline_triggers) do
|
||||
matches = match_pattern(pattern, inline_query.query)
|
||||
if matches then
|
||||
break;
|
||||
end
|
||||
end
|
||||
print(plugin.name..' triggered')
|
||||
return plugin.inline_callback(self, inline_query, config, matches)
|
||||
end)
|
||||
if not success then
|
||||
print(result)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function match_plugins(self, msg, config, plugin)
|
||||
for _, trigger in pairs(plugin.triggers or {}) do
|
||||
if string.match(msg.text_lower, trigger) then
|
||||
|
@ -95,7 +95,9 @@ function afk:pre_process(msg, self)
|
||||
redis:hset(hash, 'afk', false)
|
||||
if afk_text then
|
||||
redis:hset(hash, 'afk_text', false)
|
||||
utilities.send_message(self, msg.chat.id, user_name..' ist wieder da (war: '..afk_text..' für '..duration..')!')
|
||||
local afk_text = afk_text:gsub("%*","")
|
||||
local afk_text = afk_text:gsub("_","")
|
||||
utilities.send_message(self, msg.chat.id, user_name..' ist wieder da (war: *'..afk_text..'* für '..duration..')!', true, nil, true)
|
||||
else
|
||||
utilities.send_message(self, msg.chat.id, user_name..' ist wieder da (war '..duration..' weg)!')
|
||||
end
|
||||
|
@ -6,25 +6,37 @@ echo.command = 'echo <Text>'
|
||||
|
||||
function echo:init(config)
|
||||
echo.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('echo', true).table
|
||||
echo.inline_triggers = {
|
||||
"^e (.*)"
|
||||
}
|
||||
echo.doc = [[*
|
||||
]]..config.cmd_pat..[[echo* _<Text>_: Gibt den Text aus]]
|
||||
end
|
||||
|
||||
function echo:inline_callback(inline_query, config, matches)
|
||||
local text = matches[1]
|
||||
local results = '['
|
||||
|
||||
-- enable custom markdown button
|
||||
if text:match('%[.*%]%(.*%)') or text:match('%*.*%*') or text:match('_.*_') or text:match('`.*`') then
|
||||
results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/custom.jpg","title":"Eigenes Markdown","description":"'..text..'","input_message_content":{"message_text":"'..text..'","parse_mode":"Markdown"}},'
|
||||
end
|
||||
|
||||
local results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fett.jpg","title":"Fett","description":"*'..text..'*","input_message_content":{"message_text":"*'..text..'*","parse_mode":"Markdown"}},{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/kursiv.jpg","title":"Kursiv","description":"_'..text..'_","input_message_content":{"message_text":"_'..text..'_","parse_mode":"Markdown"}},{"type":"article","id":"'..math.random(100000000000000000)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/echo/fixedsys.jpg","title":"Feste Breite","description":"`'..text..'`","input_message_content":{"message_text":"`'..text..'`","parse_mode":"Markdown"}}]'
|
||||
utilities.answer_inline_query(self, inline_query, results, 0)
|
||||
end
|
||||
|
||||
function echo:action(msg)
|
||||
|
||||
local input = utilities.input(msg.text)
|
||||
|
||||
if not input then
|
||||
utilities.send_message(self, msg.chat.id, echo.doc, true, msg.message_id, true)
|
||||
else
|
||||
local output
|
||||
if msg.chat.type == 'supergroup' then
|
||||
output = '*Echo:*\n"' .. utilities.md_escape(input) .. '"'
|
||||
end
|
||||
utilities.send_message(self, msg.chat.id, input, true, nil, true)
|
||||
local input = utilities.input(msg.text)
|
||||
if not input then
|
||||
utilities.send_message(self, msg.chat.id, echo.doc, true, msg.message_id, true)
|
||||
else
|
||||
local output
|
||||
if msg.chat.type == 'supergroup' then
|
||||
output = '*Echo:*\n"' .. utilities.md_escape(input) .. '"'
|
||||
end
|
||||
|
||||
|
||||
utilities.send_message(self, msg.chat.id, input, true, nil, true)
|
||||
end
|
||||
end
|
||||
|
||||
return echo
|
||||
|
@ -191,6 +191,19 @@ function utilities:get_chat_administrators(chat_id)
|
||||
} )
|
||||
end
|
||||
|
||||
-- https://core.telegram.org/bots/api#answerinlinequery
|
||||
function utilities:answer_inline_query(inline_query, results, cache_time, is_personal, next_offset, switch_pm_text, switch_pm_parameter)
|
||||
return bindings.request(self, 'answerInlineQuery', {
|
||||
inline_query_id = inline_query.id,
|
||||
results = results,
|
||||
cache_time = cache_time,
|
||||
is_personal = is_personal,
|
||||
next_offset = next_offset,
|
||||
switch_pm_text = switch_pm_text,
|
||||
switch_pm_parameter = switch_pm_parameter
|
||||
} )
|
||||
end
|
||||
|
||||
-- get the indexed word in a string
|
||||
function utilities.get_word(s, i)
|
||||
s = s or ''
|
||||
|
Reference in New Issue
Block a user