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)
|
-- vardump(callback)
|
||||||
|
|
||||||
if not callback.data:find(':') then
|
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
|
return
|
||||||
end
|
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
|
-- Check if plugin is disabled on this chat
|
||||||
if msg then
|
if msg then
|
||||||
if is_plugin_disabled_on_chat(plugin.name, 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
|
return
|
||||||
end
|
end
|
||||||
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)
|
plugin:callback(callback, msg, self, config, param)
|
||||||
return
|
return
|
||||||
else
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
-- NOTE: To enable InlineQuerys, send /setinline to @BotFather
|
-- NOTE: To enable InlineQuerys, send /setinline to @BotFather
|
||||||
|
@ -87,6 +87,11 @@ function creds_manager:rename_creds(var, newvar)
|
|||||||
end
|
end
|
||||||
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)
|
function creds_manager:action(msg, config, matches)
|
||||||
local receiver = msg.from.id
|
local receiver = msg.from.id
|
||||||
if not is_sudo(msg, config) then
|
if not is_sudo(msg, config) then
|
||||||
@ -100,7 +105,7 @@ function creds_manager:action(msg, config, matches)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if matches[1] == "/creds" then
|
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
|
return
|
||||||
elseif matches[1] == "/creds add" then
|
elseif matches[1] == "/creds add" then
|
||||||
local var = string.lower(string.sub(matches[2], 1, 50))
|
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
|
return text, image_url
|
||||||
end
|
end
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
function flickr:action(msg, config, matches)
|
function flickr:action(msg, config, matches)
|
||||||
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||||
local data = flickr:get_flickr_photo_data(matches[2])
|
local data = flickr:get_flickr_photo_data(matches[2])
|
||||||
if not data then utilities.send_reply(msg, config.errors.connection) return end
|
if not data then utilities.send_reply(msg, config.errors.connection) return end
|
||||||
local text, image_url, isgif = flickr:send_flickr_photo_data(data)
|
local text, image_url, isgif = flickr:send_flickr_photo_data(data)
|
||||||
@ -63,7 +64,7 @@ function flickr:action(msg, config, matches)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
utilities.send_reply(msg, text)
|
utilities.send_reply(msg, text, 'HTML')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,8 +2,8 @@ local flickr_search = {}
|
|||||||
|
|
||||||
function flickr_search:init(config)
|
function flickr_search:init(config)
|
||||||
if not cred_data.flickr_apikey then
|
if not cred_data.flickr_apikey then
|
||||||
print('Fehlender Key: flickr_apikey.')
|
print('Missing config value: flickr_apikey.')
|
||||||
print('flickr_search.lua wird nicht aktiviert.')
|
print('flickr_search.lua will not be enabled.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -17,30 +17,55 @@ flickr_search.command = 'flickr <Suchbegriff>'
|
|||||||
local apikey = cred_data.flickr_apikey
|
local apikey = cred_data.flickr_apikey
|
||||||
local BASE_URL = 'https://api.flickr.com/services/rest'
|
local BASE_URL = 'https://api.flickr.com/services/rest'
|
||||||
|
|
||||||
function flickr_search:get_flickr (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&extras=url_o&text='..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)
|
local b,c = https.request(url)
|
||||||
if c ~= 200 then return nil end
|
if c ~= 200 then return nil end
|
||||||
local photo = json.decode(b).photos.photo
|
local photo = json.decode(b).photos.photo
|
||||||
|
if not photo[1] then return nil end
|
||||||
|
|
||||||
-- truly randomize
|
-- truly randomize
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
-- random max json table size
|
-- random max json table size
|
||||||
local i = math.random(#photo)
|
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
|
end
|
||||||
|
|
||||||
function flickr_search:action(msg, config, matches)
|
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
|
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
|
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
|
return
|
||||||
else
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,7 +83,27 @@ function pixabay:get_pixabay(term)
|
|||||||
return image_url, full_url, page_url, user, tags
|
return image_url, full_url, page_url, user, tags
|
||||||
end
|
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)
|
function pixabay:action(msg, config, matches)
|
||||||
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
||||||
local term = matches[1]
|
local term = matches[1]
|
||||||
if matches[2] then
|
if matches[2] then
|
||||||
if redis:exists("telegram:cache:pixabay:"..matches[2]) == true then -- if cached
|
if redis:exists("telegram:cache:pixabay:"..matches[2]) == true then -- if cached
|
||||||
@ -96,17 +116,21 @@ function pixabay:action(msg, config, matches)
|
|||||||
else
|
else
|
||||||
url, full_url, page_url, user, tags = pixabay:get_pixabay_directlink(matches[2])
|
url, full_url, page_url, user, tags = pixabay:get_pixabay_directlink(matches[2])
|
||||||
end
|
end
|
||||||
|
callback_button = ''
|
||||||
else
|
else
|
||||||
url, full_url, page_url, user, tags = pixabay:get_pixabay(term)
|
url, full_url, page_url, user, tags = pixabay:get_pixabay(term)
|
||||||
|
callback_button = ',{"text":"Nochmal suchen","callback_data":"pixabay:'..URL.escape(matches[1])..'"}'
|
||||||
end
|
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)
|
utilities.send_reply(msg, config.errors.results)
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
utilities.send_typing(msg.chat.id, 'upload_photo')
|
|
||||||
local text = '"'..tags..'" von '..user
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user