Fixes für CallbackQuerys
- Bot-Name muss nicht mehr übergeben werden, Denkfehler meinerseits, sorry! - Fehlermeldung, falls callback nicht existiert
This commit is contained in:
parent
c7fde261f5
commit
aa4429a434
@ -100,12 +100,13 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
|||||||
-- vardump(msg)
|
-- vardump(msg)
|
||||||
-- vardump(callback)
|
-- vardump(callback)
|
||||||
|
|
||||||
if msg.date < os.time() - 1800 then -- Do not process old messages.
|
if msg.date < os.time() - 3600 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)
|
utilities.answer_callback_query(callback, 'Nachricht älter als eine Stunde, bitte sende den Befehl selbst noch einmal.', true)
|
||||||
return
|
return
|
||||||
end
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -142,8 +143,7 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
callback.data = string.gsub(callback.data, '@'..self.info.username..' ', "")
|
|
||||||
local called_plugin = callback.data:match('(.*):.*')
|
local called_plugin = callback.data:match('(.*):.*')
|
||||||
local param = callback.data:sub(callback.data:find(':')+1)
|
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]
|
local plugin = self.plugins[n]
|
||||||
if plugin.name == called_plugin then
|
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 is_plugin_disabled_on_chat(plugin.name, msg) then utilities.answer_callback_query(callback, 'Plugin wurde in diesem Chat deaktiviert.') return end
|
||||||
plugin:callback(callback, msg, self, config, param)
|
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
|
||||||
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
|
if not is_whitelisted then abort_inline_query(inline_query) return end
|
||||||
end
|
end
|
||||||
|
|
||||||
if inline_query.query:match('"') then
|
inline_query.query = inline_query.query:gsub('"', '\\"')
|
||||||
inline_query.query = inline_query.query:gsub('"', '\\"')
|
|
||||||
end
|
|
||||||
|
|
||||||
if string.len(inline_query.query) > 200 then
|
if string.len(inline_query.query) > 200 then
|
||||||
abort_inline_query(inline_query)
|
abort_inline_query(inline_query)
|
||||||
@ -211,7 +215,7 @@ function bot:run(config)
|
|||||||
local v = res.result[n]
|
local v = res.result[n]
|
||||||
self.last_update = v.update_id
|
self.last_update = v.update_id
|
||||||
if v.inline_query then
|
if v.inline_query then
|
||||||
bot.process_inline_query(self, v.inline_query, config)
|
bot.process_inline_query(self, v.inline_query, config)
|
||||||
elseif v.callback_query then
|
elseif v.callback_query then
|
||||||
bot.on_callback_receive(self, v.callback_query, v.callback_query.message, config)
|
bot.on_callback_receive(self, v.callback_query, v.callback_query.message, config)
|
||||||
elseif v.message then
|
elseif v.message then
|
||||||
|
@ -104,13 +104,13 @@ function gImages:callback(callback, msg, self, config, input)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if mimetype == 'image/gif' then
|
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
|
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
|
end
|
||||||
|
|
||||||
if not result then
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -233,13 +233,13 @@ function gImages:action(msg, config, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if mimetype == 'image/gif' then
|
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
|
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
|
end
|
||||||
|
|
||||||
if not result then
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -989,5 +989,4 @@ function utilities.fix_utf8(str)
|
|||||||
return string.char(utf8.codepoint(str, 1, -1))
|
return string.char(utf8.codepoint(str, 1, -1))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return utilities
|
||||||
return utilities
|
|
Reference in New Issue
Block a user