Merge Upstream
This commit is contained in:
commit
2b8c3656f1
@ -114,7 +114,7 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
||||
-- vardump(callback)
|
||||
|
||||
if not callback.data:find(':') then
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Parameter.')
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Parameter.', true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -168,7 +168,7 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
||||
-- Check if plugin is disabled on this chat
|
||||
if msg then
|
||||
if is_plugin_disabled_on_chat(plugin.name, msg) then
|
||||
utilities.answer_callback_query(callback, 'Plugin wurde in diesem Chat deaktiviert.')
|
||||
utilities.answer_callback_query(callback, 'Plugin wurde in diesem Chat deaktiviert.', true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -177,13 +177,13 @@ function bot:on_callback_receive(callback, msg, config) -- whenever a new callba
|
||||
plugin:callback(callback, msg, self, config, param)
|
||||
return
|
||||
else
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Plugin unterstützt keine Callbacks.')
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Plugin unterstützt keine Callbacks.', true)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Plugin gefunden.')
|
||||
utilities.answer_callback_query(callback, 'Ungültiger CallbackQuery: Kein Plugin gefunden.', true)
|
||||
end
|
||||
|
||||
-- NOTE: To enable InlineQuerys, send /setinline to @BotFather
|
||||
|
@ -87,6 +87,11 @@ function creds_manager:rename_creds(var, newvar)
|
||||
end
|
||||
end
|
||||
|
||||
function creds_manager:callback(callback, msg, self, config)
|
||||
utilities.answer_callback_query(callback)
|
||||
utilities.delete_message(msg.chat.id, msg.message_id)
|
||||
end
|
||||
|
||||
function creds_manager:action(msg, config, matches)
|
||||
local receiver = msg.from.id
|
||||
if not is_sudo(msg, config) then
|
||||
@ -100,7 +105,7 @@ function creds_manager:action(msg, config, matches)
|
||||
end
|
||||
|
||||
if matches[1] == "/creds" then
|
||||
utilities.send_reply(msg, creds_manager:list_creds())
|
||||
utilities.send_reply(msg, creds_manager:list_creds(), false, '{"inline_keyboard":[[{"text":"Keys verbergen","callback_data":"creds:"}]]}')
|
||||
return
|
||||
elseif matches[1] == "/creds add" then
|
||||
local var = string.lower(string.sub(matches[2], 1, 50))
|
||||
|
@ -43,11 +43,12 @@ function flickr:send_flickr_photo_data(data)
|
||||
return text, image_url
|
||||
end
|
||||
else
|
||||
return '"'..title..'", aufgenommen '..taken..' von '..username..' ('..data.views..' Aufrufe)\nBild konnte nicht gedownloadet werden (Keine Berechtigung)'
|
||||
return '<b>'..title..'</b>, aufgenommen '..taken..' von <b>'..username..'</b> <i>('..data.views..' Aufrufe)</i>\nBild konnte nicht gedownloadet werden (Keine Berechtigung)'
|
||||
end
|
||||
end
|
||||
|
||||
function flickr:action(msg, config, matches)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local data = flickr:get_flickr_photo_data(matches[2])
|
||||
if not data then utilities.send_reply(msg, config.errors.connection) return end
|
||||
local text, image_url, isgif = flickr:send_flickr_photo_data(data)
|
||||
@ -63,7 +64,7 @@ function flickr:action(msg, config, matches)
|
||||
return
|
||||
end
|
||||
else
|
||||
utilities.send_reply(msg, text)
|
||||
utilities.send_reply(msg, text, 'HTML')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -2,8 +2,8 @@ local flickr_search = {}
|
||||
|
||||
function flickr_search:init(config)
|
||||
if not cred_data.flickr_apikey then
|
||||
print('Fehlender Key: flickr_apikey.')
|
||||
print('flickr_search.lua wird nicht aktiviert.')
|
||||
print('Missing config value: flickr_apikey.')
|
||||
print('flickr_search.lua will not be enabled.')
|
||||
return
|
||||
end
|
||||
|
||||
@ -17,30 +17,55 @@ flickr_search.command = 'flickr <Suchbegriff>'
|
||||
local apikey = cred_data.flickr_apikey
|
||||
local BASE_URL = 'https://api.flickr.com/services/rest'
|
||||
|
||||
function flickr_search:get_flickr (term)
|
||||
local url = BASE_URL..'/?method=flickr.photos.search&api_key='..apikey..'&format=json&nojsoncallback=1&privacy_filter=1&safe_search=3&extras=url_o&text='..term
|
||||
function flickr_search:get_flickr(term)
|
||||
local url = BASE_URL..'/?method=flickr.photos.search&api_key='..apikey..'&format=json&nojsoncallback=1&privacy_filter=1&safe_search=3&media=photos&sort=relevance&is_common=true&per_page=20&extras=url_l,url_o&text='..term
|
||||
local b,c = https.request(url)
|
||||
if c ~= 200 then return nil end
|
||||
local photo = json.decode(b).photos.photo
|
||||
if not photo[1] then return nil end
|
||||
|
||||
-- truly randomize
|
||||
math.randomseed(os.time())
|
||||
-- random max json table size
|
||||
local i = math.random(#photo)
|
||||
local link_image = photo[i].url_o
|
||||
return link_image
|
||||
|
||||
local link_image = photo[i].url_l or photo[i].url_o
|
||||
local orig_image = photo[i].url_o or link_image
|
||||
local title = photo[i].title
|
||||
if title:len() > 200 then
|
||||
title = title:sub(1, 197) .. '...'
|
||||
end
|
||||
|
||||
return link_image, title, orig_image
|
||||
end
|
||||
|
||||
function flickr_search:callback(callback, msg, self, config, input)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local input = URL.unescape(input)
|
||||
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
|
||||
local url, title, orig = flickr_search:get_flickr(input)
|
||||
|
||||
if not url then utilities.answer_callback_query(callback, 'Konnte nicht mit Flickr verbinden :(', true) return end
|
||||
|
||||
if string.ends(url, ".gif") then
|
||||
utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}')
|
||||
return
|
||||
else
|
||||
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
function flickr_search:action(msg, config, matches)
|
||||
local url = flickr_search:get_flickr(matches[1])
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local url, title, orig = flickr_search:get_flickr(matches[1])
|
||||
if not url then utilities.send_reply(msg, config.errors.results) return end
|
||||
|
||||
local file = download_to_file(url)
|
||||
|
||||
if string.ends(url, ".gif") then
|
||||
utilities.send_document(msg.chat.id, file, url)
|
||||
utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}')
|
||||
return
|
||||
else
|
||||
utilities.send_photo(msg.chat.id, file, url)
|
||||
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
@ -83,7 +83,27 @@ function pixabay:get_pixabay(term)
|
||||
return image_url, full_url, page_url, user, tags
|
||||
end
|
||||
|
||||
function pixabay:callback(callback, msg, self, config, input)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local input = URL.unescape(input)
|
||||
|
||||
local url, full_url, page_url, user, tags = pixabay:get_pixabay(input)
|
||||
|
||||
if not url then
|
||||
utilities.answer_callback_query(callback, 'Verbindung mit Pixabay fehlgeschlagen :(', true)
|
||||
return
|
||||
elseif url == 'NOPIX' then
|
||||
utilities.answer_callback_query(callback, 'Keine Ergebnisse gefunden!', true)
|
||||
return
|
||||
else
|
||||
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
|
||||
local text = '"'..tags..'" von '..user
|
||||
utilities.send_photo(msg.chat.id, url, text, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..page_url..'"},{"text":"Volles Bild (Login)","url":"'..full_url..'"},{"text":"Nochmal suchen","callback_data":"pixabay:'..URL.escape(input)..'"}]]}')
|
||||
end
|
||||
end
|
||||
|
||||
function pixabay:action(msg, config, matches)
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local term = matches[1]
|
||||
if matches[2] then
|
||||
if redis:exists("telegram:cache:pixabay:"..matches[2]) == true then -- if cached
|
||||
@ -96,17 +116,21 @@ function pixabay:action(msg, config, matches)
|
||||
else
|
||||
url, full_url, page_url, user, tags = pixabay:get_pixabay_directlink(matches[2])
|
||||
end
|
||||
callback_button = ''
|
||||
else
|
||||
url, full_url, page_url, user, tags = pixabay:get_pixabay(term)
|
||||
callback_button = ',{"text":"Nochmal suchen","callback_data":"pixabay:'..URL.escape(matches[1])..'"}'
|
||||
end
|
||||
|
||||
if url == 'NOPIX' then
|
||||
if not url then
|
||||
utilities.send_reply(msg, config.errors.connection)
|
||||
return
|
||||
elseif url == 'NOPIX' then
|
||||
utilities.send_reply(msg, config.errors.results)
|
||||
return
|
||||
else
|
||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||
local text = '"'..tags..'" von '..user
|
||||
utilities.send_photo(msg.chat.id, url, text, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..page_url..'"},{"text":"Volles Bild (Login notwendig)","url":"'..full_url..'"}]]}')
|
||||
utilities.send_photo(msg.chat.id, url, text, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..page_url..'"},{"text":"Volles Bild (Login)","url":"'..full_url..'"}'..callback_button..']]}')
|
||||
return
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user