diff --git a/otouto/plugins/gImages.lua b/otouto/plugins/gImages.lua index 484ed02..cd1f13d 100644 --- a/otouto/plugins/gImages.lua +++ b/otouto/plugins/gImages.lua @@ -50,29 +50,39 @@ function gImages:action(msg, config) local apikey = cred_data.google_apikey local cseid = cred_data.google_cse_id local BASE_URL = 'https://www.googleapis.com/customsearch/v1' - local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&safe=high'..'&q=' .. URL.escape(input) + local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&safe=high'..'&q=' .. URL.escape(input) .. '&fields=searchInformation(totalResults),queries(request(count)),items(link,mime,image(contextLink))' local jstr, res = HTTPS.request(url) + if res == 403 then + local jdat = JSON.decode(jstr) + utilities.send_reply(self, msg, 'Fehler '..jdat.error.code..': '..jdat.error.message..' ('..jdat.error.errors[1].reason..')', nil, msg.message_id) + return + end + if res ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) + utilities.send_reply(self, msg, config.errors.connection, true) return end local jdat = JSON.decode(jstr) if jdat.searchInformation.totalResults == '0' then - utilities.send_reply(self, msg, config.errors.results) + utilities.send_reply(self, msg, config.errors.results, true) return end local i = math.random(jdat.queries.request[1].count) local img_url = jdat.items[i].link - local file = download_to_file(img_url) - if string.ends(img_url, ".gif") then - utilities.send_document(self, msg.chat.id, file, img_url) - return + if jdat.items[i].mime == 'image/gif' then + local file = download_to_file(img_url, 'img.gif') + result = utilities.send_document(self, msg.chat.id, file, img_url, msg.message_id) else - utilities.send_photo(self, msg.chat.id, file, img_url) + local file = download_to_file(img_url, 'img.png') + result = utilities.send_photo(self, msg.chat.id, file, img_url, msg.message_id) + end + + if not result then + utilities.send_reply(self, msg, config.errors.connection, true) return end end diff --git a/otouto/plugins/youtube.lua b/otouto/plugins/youtube.lua index cc48638..c5c98a7 100644 --- a/otouto/plugins/youtube.lua +++ b/otouto/plugins/youtube.lua @@ -87,7 +87,7 @@ local function convertISO8601Time(duration) end function send_youtube_data(data, msg, self, link, sendpic) - local title = data.snippet.localized.title + local title = utilities.md_escape(data.snippet.localized.title) -- local description = data.snippet.localized.description local uploader = data.snippet.channelTitle local upload_date = makeOurDate(data.snippet.publishedAt)