CallbackQuery für Cats!

This commit is contained in:
Andreas Bielawski 2016-10-05 19:29:15 +02:00
parent 4c1248f21d
commit d404941560

View File

@ -23,8 +23,8 @@ function cats:init(config)
*]]..config.cmd_pat..[[cat* _gif_: Postet eine zufällige, animierte Katze]] *]]..config.cmd_pat..[[cat* _gif_: Postet eine zufällige, animierte Katze]]
end end
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
local BASE_URL = 'http://thecatapi.com/api/images/get'
function cats:inline_callback(inline_query, config, matches) function cats:inline_callback(inline_query, config, matches)
if matches[1] == 'gif' then if matches[1] == 'gif' then
@ -59,16 +59,54 @@ function cats:inline_callback(inline_query, config, matches)
utilities.answer_inline_query(inline_query, results, 30) utilities.answer_inline_query(inline_query, results, 30)
end end
function cats:action(msg, config, matches) function cats:get_cat(gif)
if matches[1] == 'gif' then if gif then
local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey local url = BASE_URL..'?type=gif&apikey='..apikey
local file = download_to_file(url, 'miau.gif') file = download_to_file(url, 'miau.gif')
utilities.send_document(msg.chat.id, file, nil, msg.message_id)
else else
local url = 'http://thecatapi.com/api/images/get?type=jpg,png&apikey='..apikey local url = BASE_URL..'?type=jpg,png&apikey='..apikey
local file = download_to_file(url, 'miau.png') file = download_to_file(url, 'miau.png')
utilities.send_photo(msg.chat.id, file, nil, msg.message_id) end
return file
end
function cats:callback(callback, msg, self, config, input)
utilities.answer_callback_query(callback, 'Miau!')
utilities.send_typing(msg.chat.id, 'upload_photo')
if string.isempty(input) then
local file = cats:get_cat()
if not file then
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
return
end
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
else
local file = cats:get_cat(true)
if not file then
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
return
end
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
end end
end end
return cats function cats:action(msg, config, matches)
utilities.send_typing(msg.chat.id, 'upload_photo')
if matches[1] == 'gif' then
local file = cats:get_cat(true)
if not file then
utilities.send_reply(msg, config.errors.connection)
return
end
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
else
local file = cats:get_cat()
if not file then
utilities.send_reply(msg, config.errors.connection)
return
end
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
end
end
return cats