CallbackQuery für Cats!

This commit is contained in:
Andreas Bielawski 2016-10-05 19:29:15 +02:00
parent 4c1248f21d
commit d404941560
1 changed files with 48 additions and 10 deletions

View File

@ -23,8 +23,8 @@ function cats:init(config)
*]]..config.cmd_pat..[[cat* _gif_: Postet eine zufällige, animierte Katze]]
end
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)
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)
end
function cats:action(msg, config, matches)
if matches[1] == 'gif' then
local url = 'http://thecatapi.com/api/images/get?type=gif&apikey='..apikey
local file = download_to_file(url, 'miau.gif')
utilities.send_document(msg.chat.id, file, nil, msg.message_id)
function cats:get_cat(gif)
if gif then
local url = BASE_URL..'?type=gif&apikey='..apikey
file = download_to_file(url, 'miau.gif')
else
local url = 'http://thecatapi.com/api/images/get?type=jpg,png&apikey='..apikey
local file = download_to_file(url, 'miau.png')
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
local url = BASE_URL..'?type=jpg,png&apikey='..apikey
file = download_to_file(url, 'miau.png')
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
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