Unterstützung für Callback_Querys, allerdings weiß ich nicht, ob mir die aktuelle Lösung gefällt. Mal ne Nacht drüber schlafen.

This commit is contained in:
Andreas Bielawski
2016-07-02 01:31:50 +02:00
parent e2d27a3754
commit c36c6ef125
3 changed files with 74 additions and 22 deletions

View File

@ -29,24 +29,27 @@ end
gImages.command = 'img <Suchbegriff>'
function gImages:action(msg, config)
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text
else
utilities.send_message(self, msg.chat.id, gImages.doc, true, msg.message_id, true)
return
end
end
function gImages:callback(callback, msg, self, config)
local input = callback.data
utilities.answer_callback_query(self, callback, 'Suche nochmal nach "'..input..'"')
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local img_url, mimetype = gImages:get_image(input)
print ('Checking if search contains blacklisted word: '..input)
if is_blacklisted(input) then
utilities.send_reply(self, msg, 'Vergiss es! ._.')
return
if mimetype == 'image/gif' then
local file = download_to_file(img_url, 'img.gif')
result = utilities.send_document(self, msg.chat.id, file, img_url, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal suchen","callback_data":"'..input..'"}]]}')
else
local file = download_to_file(img_url, 'img.png')
result = utilities.send_photo(self, msg.chat.id, file, img_url, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal suchen","callback_data":"'..input..'"}]]}')
end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
if not result then
utilities.send_reply(self, msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"'..input..'"}]]}')
return
end
end
function gImages:get_image(input)
local apikey = cred_data.google_apikey
local cseid = cred_data.google_cse_id
local BASE_URL = 'https://www.googleapis.com/customsearch/v1'
@ -71,14 +74,35 @@ function gImages:action(msg, config)
end
local i = math.random(jdat.queries.request[1].count)
local img_url = jdat.items[i].link
return jdat.items[i].link, jdat.items[i].mime
end
function gImages:action(msg, config, matches)
local input = utilities.input(msg.text)
if not input then
if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text
else
utilities.send_message(self, msg.chat.id, gImages.doc, true, msg.message_id, true)
return
end
end
if jdat.items[i].mime == 'image/gif' then
print ('Checking if search contains blacklisted word: '..input)
if is_blacklisted(input) then
utilities.send_reply(self, msg, 'Vergiss es! ._.')
return
end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local img_url, mimetype = gImages:get_image(input)
if mimetype == 'image/gif' then
local file = download_to_file(img_url, 'img.gif')
result = utilities.send_document(self, msg.chat.id, file, img_url, msg.message_id)
result = utilities.send_document(self, msg.chat.id, file, img_url, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal suchen","callback_data":"'..input..'"}]]}')
else
local file = download_to_file(img_url, 'img.png')
result = utilities.send_photo(self, msg.chat.id, file, img_url, msg.message_id)
result = utilities.send_photo(self, msg.chat.id, file, img_url, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal suchen","callback_data":"'..input..'"}]]}')
end
if not result then