diff --git a/otouto/bot.lua b/otouto/bot.lua index 9319265..fc12984 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -138,7 +138,7 @@ function bot:process_inline_query(inline_query, config) -- When an inline query if not config.enable_inline_for_everyone then local is_whitelisted = redis:get('whitelist:user#id'..inline_query.from.id) - if not is_whitelisted then return end + if not is_whitelisted then utilities.answer_inline_query(self, inline_query) return end end if inline_query.query:match('"') then @@ -147,6 +147,7 @@ function bot:process_inline_query(inline_query, config) -- When an inline query for _, plugin in ipairs(self.plugins) do match_inline_plugins(self, inline_query, config, plugin) end + utilities.answer_inline_query(self, inline_query) end function bot:run(config) @@ -219,8 +220,8 @@ function match_inline_plugins(self, inline_query, config, plugin) if not success then print(result) end + end end - end end function match_plugins(self, msg, config, plugin) diff --git a/otouto/plugins/9gag.lua b/otouto/plugins/9gag.lua index 7ea4e27..e372403 100644 --- a/otouto/plugins/9gag.lua +++ b/otouto/plugins/9gag.lua @@ -28,7 +28,7 @@ end function ninegag:inline_callback(inline_query, config) local res, code = http.request(url) - if code ~= 200 then return end + if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end local gag = json.decode(res) local results = '[' diff --git a/otouto/plugins/adfly.lua b/otouto/plugins/adfly.lua index cbe23e3..349e72a 100644 --- a/otouto/plugins/adfly.lua +++ b/otouto/plugins/adfly.lua @@ -27,8 +27,8 @@ function adfly:inline_callback(inline_query, config, matches) url = redis:get(hash) end - if not url then return end - if url == 'NOTFOUND' then return end + if not url then utilities.answer_inline_query(self, inline_query) return end + if url == 'NOTFOUND' then utilities.answer_inline_query(self, inline_query) return end local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Verlängerte URL","description":"'..url..'","url":"'..url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..url..'"}}]' utilities.answer_inline_query(self, inline_query, results, 3600, true) diff --git a/otouto/plugins/bImages.lua b/otouto/plugins/bImages.lua index f6c3aa4..6819e74 100644 --- a/otouto/plugins/bImages.lua +++ b/otouto/plugins/bImages.lua @@ -57,7 +57,7 @@ function bImages:inline_callback(inline_query, config, matches) results = bImages:getImages(query) end - if not results then return end + if not results then utilities.answer_inline_query(self, inline_query) return end utilities.answer_inline_query(self, inline_query, results, 3600) end diff --git a/otouto/plugins/bitly.lua b/otouto/plugins/bitly.lua index fbbd227..5f9bf23 100644 --- a/otouto/plugins/bitly.lua +++ b/otouto/plugins/bitly.lua @@ -38,7 +38,7 @@ function bitly:inline_callback(inline_query, config, matches) url = data.long_url end - if not url then return end + if not url then utilities.answer_inline_query(self, inline_query) return end local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Verlängerte URL","description":"'..url..'","url":"'..url..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..url..'"}}]' utilities.answer_inline_query(self, inline_query, results, 3600) diff --git a/otouto/plugins/giphy.lua b/otouto/plugins/giphy.lua index 3177cf3..dda1ed4 100644 --- a/otouto/plugins/giphy.lua +++ b/otouto/plugins/giphy.lua @@ -30,8 +30,8 @@ function giphy:inline_callback(inline_query, config, matches) else data = giphy:get_gifs(matches[2]) end - if not data then return end - if not data[1] then return end + if not data then utilities.answer_inline_query(self, inline_query) return end + if not data[1] then utilities.answer_inline_query(self, inline_query) return end local results = '[' for n in pairs(data) do diff --git a/otouto/plugins/googl.lua b/otouto/plugins/googl.lua index 35eb08e..f0872aa 100644 --- a/otouto/plugins/googl.lua +++ b/otouto/plugins/googl.lua @@ -25,7 +25,7 @@ end function googl:inline_callback(inline_query, config, matches) local shorturl = matches[1] local text, longUrl = googl:send_googl_info(shorturl) - if not longUrl then return end + if not longUrl then utilities.answer_inline_query(self, inline_query) return end local results = '[{"type":"article","id":"'..math.random(100000000000000000)..'","title":"Verlängerte URL","description":"'..longUrl..'","url":"'..longUrl..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/generic/internet.jpg","thumb_width":165,"thumb_height":150,"hide_url":true,"input_message_content":{"message_text":"'..text..'"}}]' utilities.answer_inline_query(self, inline_query, results, 1) diff --git a/otouto/plugins/imdb.lua b/otouto/plugins/imdb.lua index 4fc7f81..3905cd0 100644 --- a/otouto/plugins/imdb.lua +++ b/otouto/plugins/imdb.lua @@ -4,50 +4,92 @@ imdb.command = 'imdb ' function imdb:init(config) imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table + imdb.inline_triggers = { + "^imdb (.+)" + } imdb.doc = [[* ]]..config.cmd_pat..[[imdb* __ -Sucht _Film_ bei IMDB]] +Sucht _Film_ bei IMDb]] +end + +local BASE_URL = 'https://www.omdbapi.com' + +function imdb:get_imdb_info(id) + local url = BASE_URL..'/?i='..id + local res, code = https.request(url) + if code ~= 200 then return end + local movie_info = json.decode(res) + return movie_info +end + +function imdb:inline_callback(inline_query, config, matches) + local query = matches[1] + local url = BASE_URL..'/?s='..URL.escape(query) + local res, code = https.request(url) + if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end + local data = json.decode(res) + if data.Response ~= "True" then utilities.answer_inline_query(self, inline_query) return end + + local results = '[' + for num in pairs(data.Search) do + if num > 5 then + break; + end + local imdb_id = data.Search[num].imdbID + local movie_info = imdb:get_imdb_info(imdb_id) + local title = movie_info.Title + local year = movie_info.Year + local description = movie_info.Plot + local text = ''..movie_info.Title.. ' ('..movie_info.Year..') von '..movie_info.Director..'\\n'..string.gsub(movie_info.imdbRating, '%.', ',')..'/10 | '..movie_info.Runtime..' | '.. movie_info.Genre..'\\n' .. movie_info.Plot .. '' + local text = text:gsub('"', '\\"') + + if movie_info.Poster == "N/A" then + img_url = 'https://anditest.perseus.uberspace.de/inlineQuerys/imdb/logo.jpg' + else + img_url = movie_info.Poster + end + results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..title..' ('..year..')","description":"'..description..'","url":"http://imdb.com/title/'..imdb_id..'","hide_url":true,"thumb_url":"'..img_url..'","reply_markup":{"inline_keyboard":[[{"text":"IMDb-Seite aufrufen","url":"http://imdb.com/title/'..imdb_id..'"}]]},"input_message_content":{"message_text":"'..text..'","parse_mode":"HTML"}},' + end + + local results = results:sub(0, -2) + local results = results..']' + utilities.answer_inline_query(self, inline_query, results, 10000) end function imdb:action(msg, config) - - 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(self, msg.chat.id, imdb.doc, true, msg.message_id, true) - return - end + 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(self, msg.chat.id, imdb.doc, true, msg.message_id, true) + return end + end + + local url = BASE_URL..'/?t='..URL.escape(input) + local jstr, res = https.request(url) + if res ~= 200 then + utilities.send_reply(self, msg, config.errors.connection) + return + end - local url = 'http://www.omdbapi.com/?t=' .. URL.escape(input) + local jdat = json.decode(jstr) + if jdat.Response ~= 'True' then + utilities.send_reply(self, msg, config.errors.results) + return + end - local jstr, res = http.request(url) - if res ~= 200 then - utilities.send_reply(self, msg, config.errors.connection) - return - end + local output = ''..jdat.Title.. ' ('..jdat.Year..') von '..jdat.Director..'\n' + output = output..string.gsub(jdat.imdbRating, '%.', ',')..'/10 | '..jdat.Runtime..' | '.. jdat.Genre..'\n' + output = output..'' .. jdat.Plot .. '' - local jdat = json.decode(jstr) - - if jdat.Response ~= 'True' then - utilities.send_reply(self, msg, config.errors.results) - return - end - - local output = '*' .. jdat.Title .. ' ('.. jdat.Year ..')* von '..jdat.Director..'\n' - output = output .. string.gsub(jdat.imdbRating, '%.', ',') ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n' - output = output .. '_' .. jdat.Plot .. '_\n' - output = output .. '[IMDB-Seite besuchen](http://imdb.com/title/' .. jdat.imdbID .. ')' - - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_reply(self, 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(self, msg.chat.id, file) - end - + if jdat.Poster ~= "N/A" then + local file = download_to_file(jdat.Poster) + utilities.send_photo(self, msg.chat.id, file) + end end -return imdb +return imdb \ No newline at end of file diff --git a/otouto/plugins/qr.lua b/otouto/plugins/qr.lua index 2c607d4..1a5c437 100644 --- a/otouto/plugins/qr.lua +++ b/otouto/plugins/qr.lua @@ -71,9 +71,9 @@ end function qr:inline_callback(inline_query, config, matches) local text = matches[1] - if string.len(text) > 200 then return end + if string.len(text) > 200 then utilities.answer_inline_query(self, inline_query) return end local image_url = qr:qr(text, nil, nil, 'jpg') - if not image_url then return end + if not image_url then utilities.answer_inline_query(self, inline_query) return end local results = '[{"type":"photo","id":"'..math.random(100000000000000000)..'","photo_url":"'..image_url..'","thumb_url":"'..image_url..'","photo_width":600,"photo_height":600,"caption":"'..text..'"},' diff --git a/otouto/plugins/tagesschau.lua b/otouto/plugins/tagesschau.lua index f6da7ab..3d7ee23 100644 --- a/otouto/plugins/tagesschau.lua +++ b/otouto/plugins/tagesschau.lua @@ -42,7 +42,7 @@ function tagesschau:inline_callback(inline_query, config, matches) local article = matches[1] local full_url = 'http://www.tagesschau.de/'..article..'.html' local text, img_url, headline, shorttext = tagesschau:get_tagesschau_article(article) - if text == 'HTTP-Fehler' or text == 'Artikel nicht gefunden!' then return end + if text == 'HTTP-Fehler' or text == 'Artikel nicht gefunden!' then utilities.answer_inline_query(self, inline_query) return end if text:match('"') then text = text:gsub('"', '\\"') diff --git a/otouto/plugins/wikipedia.lua b/otouto/plugins/wikipedia.lua index 44131ac..9db790b 100644 --- a/otouto/plugins/wikipedia.lua +++ b/otouto/plugins/wikipedia.lua @@ -167,15 +167,15 @@ function wikipedia:inline_callback(inline_query, config, matches) end local url = 'https://'..lang..'.wikipedia.org/w/api.php?action=query&list=search&srsearch='..URL.escape(query)..'&format=json&prop=extracts&srprop=snippet' local res, code = https.request(url) - if code ~= 200 then return end + if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end local data = json.decode(res).query - if data.searchinfo.totalhits == 0 then return end + if data.searchinfo.totalhits == 0 then utilities.answer_inline_query(self, inline_query) return end local results = '[' for num in pairs(data.search) do local title = data.search[num].title - results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..title..'","description":"'..wikipedia:snip_snippet(data.search[num].snippet)..'","url":"https://'..lang..'.wikipedia.org/wiki/'..URL.escape(title)..'","thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/wiki/logo.jpg","thumb_width":95,"thumb_height":86,"input_message_content":{"message_text":"https://'..lang..'.wikipedia.org/wiki/'..URL.escape(title)..'","disable_web_page_preview":true}}' + results = results..'{"type":"article","id":"'..math.random(100000000000000000)..'","title":"'..title..'","description":"'..wikipedia:snip_snippet(data.search[num].snippet)..'","url":"https://'..lang..'.wikipedia.org/wiki/'..URL.escape(title)..'","hide_url":true,"thumb_url":"https://anditest.perseus.uberspace.de/inlineQuerys/wiki/logo.jpg","thumb_width":95,"thumb_height":86,"input_message_content":{"message_text":"https://'..lang..'.wikipedia.org/wiki/'..URL.escape(title)..'","disable_web_page_preview":true}}' if num < #data.search then results = results..',' end diff --git a/otouto/plugins/youtube.lua b/otouto/plugins/youtube.lua index 4e38169..cfdc676 100644 --- a/otouto/plugins/youtube.lua +++ b/otouto/plugins/youtube.lua @@ -147,10 +147,10 @@ function youtube:inline_callback(inline_query, config, matches) local query = matches[1] local url = BASE_URL..'/search?part=snippet&key='..apikey..'&maxResults=10&type=video&q='..URL.escape(query)..'&fields=items(id(videoId),snippet(publishedAt,title,thumbnails,channelTitle))' local res,code = https.request(url) - if code ~= 200 then return end + if code ~= 200 then utilities.answer_inline_query(self, inline_query) return end local data = json.decode(res) - if not data.items[1] then return end + if not data.items[1] then utilities.answer_inline_query(self, inline_query) return end local video_ids = "" -- We get all videoIds from search...