From bc6727275c50202a9ab9ff551cb809d4542a3468 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Thu, 29 Sep 2016 14:57:54 -0400 Subject: [PATCH 1/3] whoops --- otouto/plugins/gImages.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/otouto/plugins/gImages.lua b/otouto/plugins/gImages.lua index 0d0a16f..a3747de 100644 --- a/otouto/plugins/gImages.lua +++ b/otouto/plugins/gImages.lua @@ -1,5 +1,9 @@ - -- You need a Google API key and a Google Custom Search Engine set up to use this, in config.google_api_key and config.google_cse_key, respectively. - -- You must also sign up for the CSE in the Google Developer Console, and enable image results. +--[[ + You need a Google API key and a Google Custom Search Engine set up to use + this, in config.google_api_key and config.google_cse_key, respectively. You + must also sign up for the CSE in the Google Developer Console, and enable + image results. +]] -- local gImages = {} @@ -59,9 +63,9 @@ function gImages:action(msg, config) if msg.text_lower:match(gImages.nsfw_trigger) then - utilities.send_message(msg, '*NSFW*\n'..output, true, msg.message_id, true) + utilities.send_message(msg.chat.id, '*NSFW*\n'..output, true, msg.message_id, true) else - utilities.send_message(msg, output, false, msg.message_id, true) + utilities.send_message(msg.chat.id, output, false, msg.message_id, true) end end From 7f45f4d736eff6a749bb17b6ab51dcf7c414891b Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Mon, 3 Oct 2016 20:19:20 +0200 Subject: [PATCH 2/3] - gImages: Stark verbessert, keine Code-Duplikation mehr + Bilder werden nicht mehr heruntergeladen, sondern direkt an den TG-Server gesendet (3. Oktober Update) - Einige Plugins nutzen jetzt Bilder-URLs, anstatt die Datei selbst herunterzuladen (3. Oktober Update) --- otouto/plugins/9gag.lua | 3 +- otouto/plugins/ap.lua | 3 +- otouto/plugins/app_store.lua | 3 +- otouto/plugins/br.lua | 3 +- otouto/plugins/gImages.lua | 155 +++++++++------------------------ otouto/plugins/games.lua | 3 +- otouto/plugins/myanimelist.lua | 6 +- otouto/plugins/tagesschau.lua | 3 +- 8 files changed, 47 insertions(+), 132 deletions(-) diff --git a/otouto/plugins/9gag.lua b/otouto/plugins/9gag.lua index 89f1aec..1062d55 100644 --- a/otouto/plugins/9gag.lua +++ b/otouto/plugins/9gag.lua @@ -53,8 +53,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 diff --git a/otouto/plugins/ap.lua b/otouto/plugins/ap.lua index 95a1ef0..7e36b7f 100644 --- a/otouto/plugins/ap.lua +++ b/otouto/plugins/ap.lua @@ -30,8 +30,7 @@ function ap:action(msg, config, matches) if pic then local pic = pic:gsub('-small', '-big') - local photo = download_to_file('http://hosted.ap.org'..pic) - utilities.send_photo(msg.chat.id, photo, nil, msg.message_id) + utilities.send_photo(msg.chat.id, 'http://hosted.ap.org'..pic, nil, msg.message_id) end utilities.send_reply(msg, article, 'HTML') end diff --git a/otouto/plugins/app_store.lua b/otouto/plugins/app_store.lua index 3b9fb6f..ec53b91 100644 --- a/otouto/plugins/app_store.lua +++ b/otouto/plugins/app_store.lua @@ -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 diff --git a/otouto/plugins/br.lua b/otouto/plugins/br.lua index 046a017..daedb01 100644 --- a/otouto/plugins/br.lua +++ b/otouto/plugins/br.lua @@ -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 diff --git a/otouto/plugins/gImages.lua b/otouto/plugins/gImages.lua index d7c1433..58bc43b 100644 --- a/otouto/plugins/gImages.lua +++ b/otouto/plugins/gImages.lua @@ -36,85 +36,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, 'img.gif') - elseif mimetype == 'image/png' then - file = download_to_file(img_url, 'img.png') - elseif mimetype == 'image/jpeg' then - file = download_to_file(img_url, 'img.jpg') - 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 -- 100 requests is RIDICULOUS, Google! local cseid = cred_data.google_cse_id @@ -151,23 +72,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 ('Checking if search contains blacklisted word: '..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' @@ -204,18 +109,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, 'img.gif') - elseif mimetype == 'image/png' then - file = download_to_file(img_url, 'img.png') - elseif mimetype == 'image/jpeg' then - file = download_to_file(img_url, 'img.jpg') + 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 @@ -231,17 +133,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 - - if not result then - utilities.send_reply(msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"gImages:'..URL.escape(input)..'"}]]}') - return - end end -return gImages +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 \ No newline at end of file diff --git a/otouto/plugins/games.lua b/otouto/plugins/games.lua index ddbe85f..8829fea 100644 --- a/otouto/plugins/games.lua +++ b/otouto/plugins/games.lua @@ -51,8 +51,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 diff --git a/otouto/plugins/myanimelist.lua b/otouto/plugins/myanimelist.lua index 4b11627..b4970ab 100644 --- a/otouto/plugins/myanimelist.lua +++ b/otouto/plugins/myanimelist.lua @@ -197,8 +197,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 @@ -212,8 +211,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 diff --git a/otouto/plugins/tagesschau.lua b/otouto/plugins/tagesschau.lua index 2eb61d6..76f258f 100644 --- a/otouto/plugins/tagesschau.lua +++ b/otouto/plugins/tagesschau.lua @@ -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 From 2a3cbeab6dab09d67e896c060f391e1306a8ea2f Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Mon, 3 Oct 2016 21:56:32 +0200 Subject: [PATCH 3/3] =?UTF-8?q?-=20Fixe=20Gfycat=20-=20Mehr=20Verbesserung?= =?UTF-8?q?en=20f=C3=BCr=20das=203.=20Oktober=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/facebook.lua | 3 +-- otouto/plugins/gMaps.lua | 3 +-- otouto/plugins/gfycat.lua | 11 +++++------ otouto/plugins/golem.lua | 3 +-- otouto/plugins/gps.lua | 3 +-- otouto/plugins/heise.lua | 3 +-- otouto/plugins/imdb.lua | 6 ++---- otouto/plugins/media.lua | 4 ++-- otouto/plugins/pixabay.lua | 3 +-- otouto/plugins/plugins.lua | 26 ++++++++++++------------- otouto/plugins/qr.lua | 3 +-- otouto/plugins/speedtest.lua | 3 +-- otouto/plugins/spotify.lua | 34 ++++++++++++++++----------------- otouto/plugins/steam.lua | 2 +- otouto/plugins/thetvdb.lua | 3 +-- otouto/plugins/twitter.lua | 6 ++---- otouto/plugins/twitter_send.lua | 19 +++++++++++++----- otouto/plugins/twitter_user.lua | 5 ++--- otouto/plugins/vine.lua | 7 +++---- otouto/plugins/youtube.lua | 3 +-- otouto/utilities.lua | 6 ++++-- 21 files changed, 74 insertions(+), 82 deletions(-) diff --git a/otouto/plugins/facebook.lua b/otouto/plugins/facebook.lua index a7ab106..c17f73b 100644 --- a/otouto/plugins/facebook.lua +++ b/otouto/plugins/facebook.lua @@ -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 diff --git a/otouto/plugins/gMaps.lua b/otouto/plugins/gMaps.lua index d1decb1..fbd9932 100644 --- a/otouto/plugins/gMaps.lua +++ b/otouto/plugins/gMaps.lua @@ -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¢er="..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) diff --git a/otouto/plugins/gfycat.lua b/otouto/plugins/gfycat.lua index 93c087e..00fa519 100644 --- a/otouto/plugins/gfycat.lua +++ b/otouto/plugins/gfycat.lua @@ -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) diff --git a/otouto/plugins/golem.lua b/otouto/plugins/golem.lua index cb42282..731e7ae 100644 --- a/otouto/plugins/golem.lua +++ b/otouto/plugins/golem.lua @@ -54,8 +54,7 @@ function golem:action(msg, config, matches) 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) end diff --git a/otouto/plugins/gps.lua b/otouto/plugins/gps.lua index 79d4379..db1aa06 100644 --- a/otouto/plugins/gps.lua +++ b/otouto/plugins/gps.lua @@ -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¢er=" .. 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) diff --git a/otouto/plugins/heise.lua b/otouto/plugins/heise.lua index a1b2c3d..a5f5e21 100644 --- a/otouto/plugins/heise.lua +++ b/otouto/plugins/heise.lua @@ -34,8 +34,7 @@ function heise:action(msg, config, matches) if not text then return end if image_url then utilities.send_typing(msg.chat.id, 'upload_photo') - local file = download_to_file(image_url, 'heise_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 diff --git a/otouto/plugins/imdb.lua b/otouto/plugins/imdb.lua index 1be8daa..f91af16 100644 --- a/otouto/plugins/imdb.lua +++ b/otouto/plugins/imdb.lua @@ -90,12 +90,10 @@ function imdb:action(msg, config) output = output..string.gsub(jdat.imdbRating, '%.', ',')..'/10 | '..jdat.Runtime..' | '.. jdat.Genre..'\n' output = output..'' .. jdat.Plot .. '' - 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 \ No newline at end of file diff --git a/otouto/plugins/media.lua b/otouto/plugins/media.lua index 44423ee..ce5ef1f 100644 --- a/otouto/plugins/media.lua +++ b/otouto/plugins/media.lua @@ -42,9 +42,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 diff --git a/otouto/plugins/pixabay.lua b/otouto/plugins/pixabay.lua index 0e4f916..5083205 100644 --- a/otouto/plugins/pixabay.lua +++ b/otouto/plugins/pixabay.lua @@ -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 diff --git a/otouto/plugins/plugins.lua b/otouto/plugins/plugins.lua index e231eb7..a294d9c 100644 --- a/otouto/plugins/plugins.lua +++ b/otouto/plugins/plugins.lua @@ -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 diff --git a/otouto/plugins/qr.lua b/otouto/plugins/qr.lua index c21762e..24a6d75 100644 --- a/otouto/plugins/qr.lua +++ b/otouto/plugins/qr.lua @@ -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 diff --git a/otouto/plugins/speedtest.lua b/otouto/plugins/speedtest.lua index f384d73..ebba378 100644 --- a/otouto/plugins/speedtest.lua +++ b/otouto/plugins/speedtest.lua @@ -8,8 +8,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 \ No newline at end of file diff --git a/otouto/plugins/spotify.lua b/otouto/plugins/spotify.lua index 81f7ac4..55195f9 100644 --- a/otouto/plugins/spotify.lua +++ b/otouto/plugins/spotify.lua @@ -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 = ''..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, '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) diff --git a/otouto/plugins/steam.lua b/otouto/plugins/steam.lua index af2296f..2faf581 100644 --- a/otouto/plugins/steam.lua +++ b/otouto/plugins/steam.lua @@ -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 diff --git a/otouto/plugins/thetvdb.lua b/otouto/plugins/thetvdb.lua index 0759ee7..bbaef66 100644 --- a/otouto/plugins/thetvdb.lua +++ b/otouto/plugins/thetvdb.lua @@ -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 diff --git a/otouto/plugins/twitter.lua b/otouto/plugins/twitter.lua index 36b9a01..03ce14f 100644 --- a/otouto/plugins/twitter.lua +++ b/otouto/plugins/twitter.lua @@ -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 diff --git a/otouto/plugins/twitter_send.lua b/otouto/plugins/twitter_send.lua index 325d35e..8cc7601 100644 --- a/otouto/plugins/twitter_send.lua +++ b/otouto/plugins/twitter_send.lua @@ -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 diff --git a/otouto/plugins/twitter_user.lua b/otouto/plugins/twitter_user.lua index af23591..75b73ce 100644 --- a/otouto/plugins/twitter_user.lua +++ b/otouto/plugins/twitter_user.lua @@ -88,15 +88,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 diff --git a/otouto/plugins/vine.lua b/otouto/plugins/vine.lua index 963173c..ce122ab 100644 --- a/otouto/plugins/vine.lua +++ b/otouto/plugins/vine.lua @@ -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 diff --git a/otouto/plugins/youtube.lua b/otouto/plugins/youtube.lua index d3f26a8..621e4b4 100644 --- a/otouto/plugins/youtube.lua +++ b/otouto/plugins/youtube.lua @@ -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 diff --git a/otouto/utilities.lua b/otouto/utilities.lua index bfda145..5d9200f 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -127,12 +127,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, @@ -197,12 +198,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 },