From 2a3cbeab6dab09d67e896c060f391e1306a8ea2f Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Mon, 3 Oct 2016 21:56:32 +0200 Subject: [PATCH] =?UTF-8?q?-=20Fixe=20Gfycat=20-=20Mehr=20Verbesserungen?= =?UTF-8?q?=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 },