Merge Upstream

This commit is contained in:
Akamaru 2016-10-03 23:40:14 +02:00
commit 32c62f80f1
27 changed files with 153 additions and 320 deletions

View File

@ -56,8 +56,7 @@ function ninegag:action(msg, config)
return
end
local file = download_to_file(url)
utilities.send_photo(msg.chat.id, file, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}')
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}')
end
return ninegag

View File

@ -103,8 +103,7 @@ function app_store:action(msg, config, matches)
utilities.send_reply(msg, output, 'HTML')
if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end
end
end

View File

@ -36,8 +36,7 @@ function br:action(msg, config, matches)
local text, image_url = br:get_br_article(article)
if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url, 'br_teaser.jpg')
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end
utilities.send_reply(msg, text, true)
end

View File

@ -147,9 +147,8 @@ function facebook:action(msg, config, matches)
local text, image_url = facebook:send_facebook_photo(photo_id, receiver)
if not image_url then return end
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url, 'photo.jpg')
utilities.send_reply(msg, text, 'HTML')
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
return
elseif matches[1] == 'video' or matches[2] == 'videos' then
if not matches[3] then

View File

@ -39,85 +39,6 @@ function gImages:is_blacklisted(msg)
return var
end
-- Yes, the callback is copied from below, but I can't think of another method :\
function gImages:callback(callback, msg, self, config, input)
if not msg then return end
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..URL.unescape(input)..'"')
utilities.send_typing(msg.chat.id, 'upload_photo')
local hash = 'telegram:cache:gImages'
local results = redis:smembers(hash..':'..string.lower(URL.unescape(input)))
if not results[1] then
print('doing web request')
results = gImages:get_image(input)
if results == 403 then
utilities.send_reply(msg, config.errors.quotaexceeded, true)
return
elseif not results then
utilities.send_reply(msg, config.errors.results, true)
return
end
gImages:cache_result(results, input)
end
-- Random image from table
local i = math.random(#results)
-- Thanks to Amedeo for this!
local failed = true
local nofTries = 0
while failed and nofTries < #results do
if results[i].image then
img_url = results[i].link
mimetype = results[i].mime
context = results[i].image.contextLink
else -- from cache
img_url = results[i]
mimetype = redis:hget(hash..':'..img_url, 'mime')
context = redis:hget(hash..':'..img_url, 'contextLink')
end
-- It's important to save the image with the right ending!
if mimetype == 'image/gif' then
file = download_to_file(img_url)
elseif mimetype == 'image/png' then
file = download_to_file(img_url)
elseif mimetype == 'image/jpeg' then
file = download_to_file(img_url)
else
file = nil
end
if not file then
nofTries = nofTries + 1
i = i+1
if i > #results then
i = 1
end
else
failed = false
end
end
if failed then
utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end
if mimetype == 'image/gif' then
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..input..'"}]]}')
else
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..input..'"}]]}')
end
if not result then
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages:'..input..'"}]]}')
return
end
end
function gImages:get_image(input)
local apikey = cred_data.google_apikey
local cseid = cred_data.google_cse_id
@ -154,23 +75,7 @@ function gImages:cache_result(results, text)
cache_data('gImages', string.lower(text), cache, 1209600, 'set')
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(msg.chat.id, gImages.doc, true, msg.message_id, true)
return
end
end
print ('Überprüfe, ob das Wort auf der Blackliste steht: '..input)
if gImages:is_blacklisted(input) then
utilities.send_reply(msg, 'Vergiss es!')
return
end
function gImages:send_image(msg, input)
utilities.send_typing(msg.chat.id, 'upload_photo')
local hash = 'telegram:cache:gImages'
@ -207,18 +112,15 @@ function gImages:action(msg, config, matches)
context = redis:hget(hash..':'..img_url, 'contextLink')
end
-- It's important to save the image with the right ending!
if mimetype == 'image/gif' then
file = download_to_file(img_url)
elseif mimetype == 'image/png' then
file = download_to_file(img_url)
elseif mimetype == 'image/jpeg' then
file = download_to_file(img_url)
res = utilities.send_document(msg.chat.id, img_url, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
elseif mimetype == 'image/png' or mimetype == 'image/jpeg' then
res = utilities.send_photo(msg.chat.id, img_url, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
else
file = nil
res = nil
end
if not file then
if not res then
nofTries = nofTries + 1
i = i+1
if i > #results then
@ -234,17 +136,38 @@ function gImages:action(msg, config, matches)
utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end
if mimetype == 'image/gif' then
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
else
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
end
end
if not result then
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}')
function gImages:callback(callback, msg, self, config, input)
if not msg then return end
local input = URL.unescape(input)
if gImages:is_blacklisted(input) then
utilities.answer_callback_query(callback, 'Wort steht auf der Blacklist!', true)
return
else
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
end
gImages:send_image(msg, input)
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(msg.chat.id, gImages.doc, true, msg.message_id, true)
return
end
end
print ('Checking if search contains blacklisted word: '..input)
if gImages:is_blacklisted(input) then
utilities.send_reply(msg, 'Vergiss es! ._.')
return
end
gImages:send_image(msg, input)
end
return gImages

View File

@ -39,85 +39,6 @@ function gImages_nsfw:is_blacklisted(msg)
return var
end
-- Yes, the callback is copied from below, but I can't think of another method :\
function gImages_nsfw:callback(callback, msg, self, config, input)
if not msg then return end
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..URL.unescape(input)..'"')
utilities.send_typing(msg.chat.id, 'upload_photo')
local hash = 'telegram:cache:gImages_nsfw'
local results = redis:smembers(hash..':'..string.lower(URL.unescape(input)))
if not results[1] then
print('doing web request')
results = gImages_nsfw:get_image(input)
if results == 403 then
utilities.send_reply(msg, config.errors.quotaexceeded, true)
return
elseif not results then
utilities.send_reply(msg, config.errors.results, true)
return
end
gImages_nsfw:cache_result(results, input)
end
-- Random image from table
local i = math.random(#results)
-- Thanks to Amedeo for this!
local failed = true
local nofTries = 0
while failed and nofTries < #results do
if results[i].image then
img_url = results[i].link
mimetype = results[i].mime
context = results[i].image.contextLink
else -- from cache
img_url = results[i]
mimetype = redis:hget(hash..':'..img_url, 'mime')
context = redis:hget(hash..':'..img_url, 'contextLink')
end
-- It's important to save the image with the right ending!
if mimetype == 'image/gif' then
file = download_to_file(img_url)
elseif mimetype == 'image/png' then
file = download_to_file(img_url)
elseif mimetype == 'image/jpeg' then
file = download_to_file(img_url)
else
file = nil
end
if not file then
nofTries = nofTries + 1
i = i+1
if i > #results then
i = 1
end
else
failed = false
end
end
if failed then
utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end
if mimetype == 'image/gif' then
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..input..'"}]]}')
else
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..input..'"}]]}')
end
if not result then
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages_nsfw:'..input..'"}]]}')
return
end
end
function gImages_nsfw:get_image(input)
local apikey = cred_data.google_apikey
local cseid = cred_data.google_cse_id
@ -154,23 +75,7 @@ function gImages_nsfw:cache_result(results, text)
cache_data('gImages_nsfw', string.lower(text), cache, 1209600, 'set')
end
function gImages_nsfw: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(msg.chat.id, gImages_nsfw.doc, true, msg.message_id, true)
return
end
end
print ('Überprüfe, ob das Wort auf der Blackliste steht: '..input)
if gImages_nsfw:is_blacklisted(input) then
utilities.send_reply(msg, 'Vergiss es!')
return
end
function gImages_nsfw:send_image(msg, input)
utilities.send_typing(msg.chat.id, 'upload_photo')
local hash = 'telegram:cache:gImages_nsfw'
@ -207,18 +112,15 @@ function gImages_nsfw:action(msg, config, matches)
context = redis:hget(hash..':'..img_url, 'contextLink')
end
-- It's important to save the image with the right ending!
if mimetype == 'image/gif' then
file = download_to_file(img_url)
elseif mimetype == 'image/png' then
file = download_to_file(img_url)
elseif mimetype == 'image/jpeg' then
file = download_to_file(img_url)
res = utilities.send_document(msg.chat.id, img_url, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
elseif mimetype == 'image/png' or mimetype == 'image/jpeg' then
res = utilities.send_photo(msg.chat.id, img_url, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
else
file = nil
res = nil
end
if not file then
if not res then
nofTries = nofTries + 1
i = i+1
if i > #results then
@ -234,17 +136,38 @@ function gImages_nsfw:action(msg, config, matches)
utilities.send_reply(msg, 'Fehler beim Herunterladen eines Bildes.', true)
return
end
if mimetype == 'image/gif' then
result = utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
else
result = utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
end
if not result then
utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages_nsfw:'..URL.escape(input)..'"}]]}')
return
end
end
return gImages_nsfw
function gImages_nsfw:callback(callback, msg, self, config, input)
if not msg then return end
local input = URL.unescape(input)
if gImages_nsfw:is_blacklisted(input) then
utilities.answer_callback_query(callback, 'Wort steht auf der Blacklist!', true)
return
else
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
end
gImages_nsfw:send_image(msg, input)
end
function gImages_nsfw: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(msg.chat.id, gImages_nsfw.doc, true, msg.message_id, true)
return
end
end
print ('Checking if search contains blacklisted word: '..input)
if gImages_nsfw:is_blacklisted(input) then
utilities.send_reply(msg, 'Vergiss es! ._.')
return
end
gImages_nsfw:send_image(msg, input)
end
return gImages_nsfw

View File

@ -15,8 +15,7 @@ function gMaps:get_staticmap(area, lat, lon)
local base_api = "https://maps.googleapis.com/maps/api"
local url = base_api .. "/staticmap?size=600x300&zoom=12&center="..URL.escape(area).."&markers=color:red"..URL.escape("|"..area)
local file = download_to_file(url)
return file
return url
end
function gMaps:inline_callback(inline_query, config, matches)

View File

@ -47,8 +47,7 @@ function games:send_game_photo(result, self, msg)
local i = 0
for k, v in pairs(images) do
i = i+1
local file = download_to_file(v, 'game'..i..'.jpg')
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, v, nil, msg.message_id)
end
end

View File

@ -13,14 +13,13 @@ function gfycat:send_gfycat_video(name, msg)
if code ~= 200 then return "HTTP-FEHLER" end
local data = json.decode(res).gfyItem
utilities.send_typing(msg.chat.id, 'upload_video')
local file = download_to_file(data.webmUrl)
if file == nil then
send_reply(msg, 'Fehler beim Herunterladen von '..name)
return
local file = download_to_file(data.mp4Url)
if tonumber(data.mp4Size) > 20971520 then
file = download_to_file(data.mp4Url)
else
utilities.send_video(msg.chat.id, file, nil, msg.message_id)
return
file = data.mp4Url
end
utilities.send_video(msg.chat.id, file, nil, msg.message_id)
end
function gfycat:action(msg, config, matches)

View File

@ -45,8 +45,7 @@ function gps:action(msg, config, matches)
for i in ipairs(zooms) do
local zoom = zooms[i]
local url = "https://maps.googleapis.com/maps/api/staticmap?zoom=" .. zoom .. "&size=600x300&maptype=hybrid&center=" .. lat .. "," .. lon .. "&markers=color:red%7Clabel:•%7C" .. lat .. "," .. lon
local file = download_to_file(url, 'zoom_'..i..'.png')
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, url, nil, msg.message_id)
end
utilities.send_location(msg.chat.id, lat, lon, msg.message_id)

View File

@ -90,12 +90,10 @@ function imdb:action(msg, config)
output = output..string.gsub(jdat.imdbRating, '%.', ',')..'/10 | '..jdat.Runtime..' | '.. jdat.Genre..'\n'
output = output..'<i>' .. jdat.Plot .. '</i>'
utilities.send_reply(msg, output, 'HTML', '{"inline_keyboard":[[{"text":"IMDb-Seite aufrufen","url":"http://imdb.com/title/'.. jdat.imdbID..'"}]]}')
if jdat.Poster ~= "N/A" then
local file = download_to_file(jdat.Poster)
utilities.send_photo(msg.chat.id, file)
utilities.send_photo(msg.chat.id, jdat.Poster)
end
utilities.send_reply(msg, output, 'HTML', '{"inline_keyboard":[[{"text":"IMDb-Seite aufrufen","url":"http://imdb.com/title/'.. jdat.imdbID..'"}]]}')
end
return imdb

View File

@ -43,9 +43,9 @@ function media:action(msg, config, matches)
if ext == 'gif' then
result = utilities.send_document(receiver, file, nil, msg.message_id)
elseif ext == 'ogg' then
result = utilities.send_voice(receiver, file, msg.message_id)
result = utilities.send_voice(receiver, file, nil, msg.message_id)
elseif mime_type == 'audio' then
result = utilities.send_audio(receiver, file, msg.message_id)
result = utilities.send_audio(receiver, file, nil, msg.message_id)
elseif mime_type == 'video' then
result = utilities.send_video(receiver, file, nil, msg.message_id)
else

View File

@ -211,8 +211,7 @@ function mal:action(msg, config, matches)
local text, image_url = mal:send_anime_data(anime_info)
if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end
utilities.send_reply(msg, text, true)
return
@ -226,8 +225,7 @@ function mal:action(msg, config, matches)
local text, image_url = mal:send_manga_data(manga_info)
if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end
utilities.send_reply(msg, text, true)
return

View File

@ -105,9 +105,8 @@ function pixabay:action(msg, config, matches)
return
else
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(url)
local text = '"'..tags..'" von '..user
utilities.send_photo(msg.chat.id, file, 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 notwendig)","url":"'..full_url..'"}]]}')
return
end
end

View File

@ -90,7 +90,7 @@ function plugin_manager:reload_plugins(self, config, plugin_name, status)
if plugin_name then
return 'Plugin '..plugin_name..' wurde '..status
else
return 'Plugins neu geladen'
return 'Plugins neu geladen ✔️'
end
end
@ -106,31 +106,31 @@ function plugin_manager:enable_plugin(self, config, plugin_name)
redis:sadd('telegram:enabled_plugins', plugin_name)
print(plugin_name..' saved to redis set telegram:enabled_plugins')
-- Reload the plugins
return plugin_manager:reload_plugins(self, config, plugin_name, 'aktiviert')
return plugin_manager:reload_plugins(self, config, plugin_name, 'aktiviert ✔️')
else
return 'Plugin '..plugin_name..' existiert nicht'
return 'Plugin '..plugin_name..' existiert nicht'
end
end
function plugin_manager:disable_plugin(self, config, name, chat)
-- Check if plugins exists
if not plugin_manager:plugin_exists(name) then
return 'Plugin '..name..' existiert nicht'
return 'Plugin '..name..' existiert nicht'
end
local k = plugin_manager:plugin_enabled(name)
-- Check if plugin is enabled
if not k then
return 'Plugin '..name..' ist nicht aktiviert'
return 'Plugin '..name..' ist nicht aktiviert'
end
-- Disable and reload
redis:srem('telegram:enabled_plugins', name)
print(name..' saved to redis set telegram:enabled_plugins')
return plugin_manager:reload_plugins(self, config, name, 'deaktiviert')
return plugin_manager:reload_plugins(self, config, name, 'deaktiviert ✔️')
end
function plugin_manager:disable_plugin_on_chat(msg, plugin)
if not plugin_manager:plugin_exists(plugin) then
return "Plugin existiert nicht!"
return "Plugin existiert nicht!"
end
if not msg.chat then
@ -143,15 +143,15 @@ function plugin_manager:disable_plugin_on_chat(msg, plugin)
if disabled ~= 'true' then
print('Setting '..plugin..' in redis hash '..hash..' to true')
redis:hset(hash, plugin, true)
return 'Plugin '..plugin..' für diesen Chat deaktiviert.'
return 'Plugin '..plugin..' für diesen Chat deaktiviert. ✔️'
else
return 'Plugin '..plugin..' wurde für diesen Chat bereits deaktiviert.'
return 'Plugin '..plugin..' wurde für diesen Chat bereits deaktiviert. ✔️'
end
end
function plugin_manager:reenable_plugin_on_chat(msg, plugin)
if not plugin_manager:plugin_exists(plugin) then
return "Plugin existiert nicht!"
return "Plugin existiert nicht!"
end
if not msg.chat then
@ -161,14 +161,14 @@ function plugin_manager:reenable_plugin_on_chat(msg, plugin)
end
local disabled = redis:hget(hash, plugin)
if disabled == nil then return 'Es gibt keine deaktivierten Plugins für disen Chat.' end
if disabled == nil then return 'Es gibt keine deaktivierten Plugins für disen Chat.' end
if disabled == 'true' then
print('Setting '..plugin..' in redis hash '..hash..' to false')
redis:hset(hash, plugin, false)
return 'Plugin '..plugin..' wurde für diesen Chat reaktiviert.'
return 'Plugin '..plugin..' wurde für diesen Chat reaktiviert. ✔️'
else
return 'Plugin '..plugin..' ist nicht deaktiviert.'
return 'Plugin '..plugin..' ist nicht deaktiviert. ✔️'
end
end

View File

@ -109,8 +109,7 @@ function qr:action(msg, config, matches)
local image_url = qr:qr(text, color, back)
if not image_url then utilities.send_reply(msg, config.errors.connection) return end
local file = download_to_file(image_url, 'qr.png')
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end
return qr

View File

@ -9,8 +9,7 @@ speedtest.triggers = {
function speedtest:action(msg, config, matches)
local url = 'http://www.speedtest.net/result/'..matches[1]..'.png'
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, url, nil, msg.message_id)
end
return speedtest

View File

@ -16,26 +16,24 @@ function spotify:get_track_data(track)
end
function spotify:send_track_data(data, msg)
local name = data.name
local album = data.album.name
local artist = data.artists[1].name
local preview = data.preview_url
local milliseconds = data.duration_ms
local name = data.name
local album = data.album.name
local artist = data.artists[1].name
local preview = data.preview_url
local milliseconds = data.duration_ms
-- convert s to mm:ss
local totalseconds = math.floor(milliseconds / 1000)
local duration = makeHumanTime(totalseconds)
-- convert s to mm:ss
local totalseconds = math.floor(milliseconds / 1000)
local duration = makeHumanTime(totalseconds)
local text = '*'..name..'* von *'..artist..'* aus dem Album *'..album..'* _('..duration..')_'
if preview then
utilities.send_typing(msg.chat.id, 'upload_audio')
local file = download_to_file(preview, name..'.mp3')
utilities.send_audio(msg.chat.id, file, msg.message_id, totalseconds, artist, name)
return
else
utilities.send_reply(msg, text, true)
return
end
local text = '<b>'..name..'</b> von <b>'..artist..'</b> aus dem Album <b>'..album..'</b> <i>('..duration..')</i>'
if preview then
utilities.send_typing(msg.chat.id, 'upload_audio')
local file = download_to_file(preview, name..'.mp3')
utilities.send_audio(msg.chat.id, file, 'Aus dem Album "'..album..'"\nLänge: '..duration, msg.message_id, 30, artist, name)
else
utilities.send_reply(msg, text, 'HTML')
end
end
function spotify:action(msg, config, matches)

View File

@ -51,7 +51,7 @@ function steam:action(msg, config, matches)
local text, image_url = steam:send_steam_data(data, msg)
utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, download_to_file(image_url, matches[1]..'.jpg'), nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
utilities.send_reply(msg, text, true)
end

View File

@ -64,8 +64,7 @@ function tagesschau:action(msg, config, matches)
local text, image_url = tagesschau:get_tagesschau_article(article)
if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end
utilities.send_reply(msg, text, 'HTML')
end

View File

@ -69,8 +69,7 @@ function tv:send_tv_data(result, msg)
if xml.find(result, 'banner') then
local image_url = 'http://www.thetvdb.com/banners/'..xml.find(result, 'banner')[1]
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end
utilities.send_reply(msg, text, true)
end

View File

@ -163,12 +163,10 @@ function twitter:action(msg, config, matches)
-- send the parts
utilities.send_reply(msg, text, 'HTML')
for k, v in pairs(images) do
local file = download_to_file(v)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, v, nil, msg.message_id)
end
for k, v in pairs(videos) do
local file = download_to_file(v)
utilities.send_video(msg.chat.id, file, nil, msg.message_id)
utilities.send_video(msg.chat.id, v, nil, msg.message_id)
end
end

View File

@ -169,12 +169,22 @@ function twitter_send:twitter_verify_credentials(oauth_token, oauth_token_secret
location = ''
end
if response.url and response.location ~= '' then
url = ' | '..twitter_send:resolve_url(response.url)..'\n'
url = ' | '..response.url..'\n'
elseif response.url and response.location == '' then
url = twitter_send:resolve_url(response.url)..'\n'
url = response.url..'\n'
else
url = '\n'
end
-- replace short url
if response.entities.url then
for k, v in pairs(response.entities.url.urls) do
local short = v.url
local long = v.expanded_url
local long = long:gsub('%%', '%%%%')
url = url:gsub(short, long)
end
end
local body = description..'\n'..location..url
@ -338,15 +348,14 @@ function twitter_send:action(msg, config, matches)
if matches[1] == 'verify' then
local text, pp_url = twitter_send:twitter_verify_credentials(oauth_token, oauth_token_secret)
local file = download_to_file(pp_url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, pp_url, nil, msg.message_id)
utilities.send_reply(msg, text)
return
end
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
if not can_send_tweet(msg) then
if not can_send_tweet(msg) and not is_sudo(msg, config) then
utilities.send_reply(msg, '*Du darfst keine Tweets senden.* Entweder wurdest du noch gar nicht freigeschaltet oder ausgeschlossen.', true)
return
else

View File

@ -90,15 +90,14 @@ function twitter_user:action(msg, config, matches)
local pic_url = string.gsub(response.profile_image_url_https, "normal", "400x400")
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(pic_url)
local text = header..body..footer
if string.len(text) > 199 then -- can only send captions with < 200 characters
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
utilities.send_photo(msg.chat.id, pic_url, nil, msg.message_id)
utilities.send_reply(msg, text)
return
else
utilities.send_photo(msg.chat.id, file, text, msg.message_id)
utilities.send_photo(msg.chat.id, pic_url, text, msg.message_id)
return
end
end

View File

@ -25,8 +25,7 @@ function vine:send_vine_data(data)
if data.explicitContent == 1 then
text = text..' (🔞 NSFW 🔞)'
end
local file = download_to_file(video_url, data.shortId..'.mp4')
return text, file
return text, video_url
end
function vine:action(msg, config, matches)
@ -34,8 +33,8 @@ function vine:action(msg, config, matches)
if not data then utilities.send_reply(msg, config.errors.connection) return end
utilities.send_typing(msg.chat.id, 'upload_video')
local text, file = vine:send_vine_data(data)
utilities.send_video(msg.chat.id, file, text, msg.message_id)
local text, video_url = vine:send_vine_data(data)
utilities.send_video(msg.chat.id, video_url, text, msg.message_id)
end
return vine

View File

@ -136,8 +136,7 @@ function send_youtube_data(data, msg, self, link, sendpic)
if blocked then
text = text..'\nACHTUNG, In Deutschland gesperrt!'
end
local file = download_to_file(image_url)
utilities.send_photo(msg.chat.id, file, text, msg.message_id)
utilities.send_photo(msg.chat.id, image_url, text, msg.message_id)
else
utilities.send_reply(msg, text, 'HTML')
end

View File

@ -128,12 +128,13 @@ function utilities.send_photo(chat_id, file, text, reply_to_message_id, reply_ma
end
-- https://core.telegram.org/bots/api#sendaudio
function utilities.send_audio(chat_id, file, reply_to_message_id, duration, performer, title)
function utilities.send_audio(chat_id, file, text, reply_to_message_id, duration, performer, title)
if not file then return false end
local output = bindings.request(
'sendAudio',
{
chat_id = chat_id,
caption = text or nil,
duration = duration or nil,
performer = performer or nil,
title = title or nil,
@ -198,12 +199,13 @@ end
-- NOTE: Voice messages are .ogg files encoded with OPUS
-- https://core.telegram.org/bots/api#sendvoice
function utilities.send_voice(chat_id, file, reply_to_message_id, duration)
function utilities.send_voice(chat_id, file, text, reply_to_message_id, duration)
if not file then return false end
local output = bindings.request(
'sendVoice',
{
chat_id = chat_id,
caption = text or nil,
duration = duration or nil,
reply_to_message_id = reply_to_message_id
},