Fixes für CallbackQuerys

- Bot-Name muss nicht mehr übergeben werden, Denkfehler meinerseits, sorry!
- Fehlermeldung, falls callback nicht existiert
This commit is contained in:
Andreas Bielawski 2016-09-22 21:40:46 +02:00
parent c7fde261f5
commit aa4429a434
3 changed files with 22 additions and 19 deletions

View File

@ -100,12 +100,13 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
-- vardump(msg)
-- vardump(callback)
if msg.date < os.time() - 1800 then -- Do not process old messages.
utilities.answer_callback_query(callback, 'Nachricht älter als eine halbe Stunde, bitte sende den Befehl selbst noch einmal.', true)
if msg.date < os.time() - 3600 then -- Do not process old messages.
utilities.answer_callback_query(callback, 'Nachricht älter als eine Stunde, bitte sende den Befehl selbst noch einmal.', true)
return
end
if not callback.data:find(':') or not callback.data:find('@'..self.info.username..' ') then
if not callback.data:find(':') then
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Parameter.')
return
end
@ -143,7 +144,6 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
end
end
callback.data = string.gsub(callback.data, '@'..self.info.username..' ', "")
local called_plugin = callback.data:match('(.*):.*')
local param = callback.data:sub(callback.data:find(':')+1)
@ -155,7 +155,13 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
local plugin = self.plugins[n]
if plugin.name == called_plugin then
if is_plugin_disabled_on_chat(plugin.name, msg) then utilities.answer_callback_query(callback, 'Plugin wurde in diesem Chat deaktiviert.') return end
if plugin.callback then
plugin:callback(callback, msg, self, config, param)
return
else
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Plugin unterstützt keine Callbacks.')
return
end
end
end
@ -181,9 +187,7 @@ function bot:process_inline_query(inline_query, config) -- When an inline query
if not is_whitelisted then abort_inline_query(inline_query) return end
end
if inline_query.query:match('"') then
inline_query.query = inline_query.query:gsub('"', '\\"')
end
if string.len(inline_query.query) > 200 then
abort_inline_query(inline_query)

View File

@ -104,13 +104,13 @@ function gImages:callback(callback, msg, self, config, input)
end
if mimetype == 'image/gif' then
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}')
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..input..'"}]]}')
else
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}')
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..input..'"}]]}')
end
if not result then
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..input..'"}]]}')
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages:'..input..'"}]]}')
return
end
end
@ -233,13 +233,13 @@ function gImages:action(msg, config, matches)
end
if mimetype == 'image/gif' then
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}')
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
else
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}')
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
end
if not result then
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages:'..URL.escape(input)..'"}]]}')
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
return
end
end

View File

@ -989,5 +989,4 @@ function utilities.fix_utf8(str)
return string.char(utf8.codepoint(str, 1, -1))
end
return utilities