- Ungültige InlineQuerys werden automatisch abgebrochen, der Ladekreis dreht sich so nicht mehr (das gilt auch für "nicht gefunden", etc.)
- IMDb-Plugin: Inline-Querys + Button
This commit is contained in:
parent
240ac301b9
commit
c21aa73459
@ -138,7 +138,7 @@ function bot:process_inline_query(inline_query, config) -- When an inline query
|
|||||||
|
|
||||||
if not config.enable_inline_for_everyone then
|
if not config.enable_inline_for_everyone then
|
||||||
local is_whitelisted = redis:get('whitelist:user#id'..inline_query.from.id)
|
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
|
end
|
||||||
|
|
||||||
if inline_query.query:match('"') then
|
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
|
for _, plugin in ipairs(self.plugins) do
|
||||||
match_inline_plugins(self, inline_query, config, plugin)
|
match_inline_plugins(self, inline_query, config, plugin)
|
||||||
end
|
end
|
||||||
|
utilities.answer_inline_query(self, inline_query)
|
||||||
end
|
end
|
||||||
|
|
||||||
function bot:run(config)
|
function bot:run(config)
|
||||||
|
@ -28,7 +28,7 @@ end
|
|||||||
|
|
||||||
function ninegag:inline_callback(inline_query, config)
|
function ninegag:inline_callback(inline_query, config)
|
||||||
local res, code = http.request(url)
|
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 gag = json.decode(res)
|
||||||
|
|
||||||
local results = '['
|
local results = '['
|
||||||
|
@ -27,8 +27,8 @@ function adfly:inline_callback(inline_query, config, matches)
|
|||||||
url = redis:get(hash)
|
url = redis:get(hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not url then return end
|
if not url then utilities.answer_inline_query(self, inline_query) return end
|
||||||
if url == 'NOTFOUND' then 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..'"}}]'
|
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)
|
utilities.answer_inline_query(self, inline_query, results, 3600, true)
|
||||||
|
@ -57,7 +57,7 @@ function bImages:inline_callback(inline_query, config, matches)
|
|||||||
results = bImages:getImages(query)
|
results = bImages:getImages(query)
|
||||||
end
|
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)
|
utilities.answer_inline_query(self, inline_query, results, 3600)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ function bitly:inline_callback(inline_query, config, matches)
|
|||||||
url = data.long_url
|
url = data.long_url
|
||||||
end
|
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..'"}}]'
|
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)
|
utilities.answer_inline_query(self, inline_query, results, 3600)
|
||||||
|
@ -30,8 +30,8 @@ function giphy:inline_callback(inline_query, config, matches)
|
|||||||
else
|
else
|
||||||
data = giphy:get_gifs(matches[2])
|
data = giphy:get_gifs(matches[2])
|
||||||
end
|
end
|
||||||
if not data then return end
|
if not data then utilities.answer_inline_query(self, inline_query) return end
|
||||||
if not data[1] then return end
|
if not data[1] then utilities.answer_inline_query(self, inline_query) return end
|
||||||
local results = '['
|
local results = '['
|
||||||
|
|
||||||
for n in pairs(data) do
|
for n in pairs(data) do
|
||||||
|
@ -25,7 +25,7 @@ end
|
|||||||
function googl:inline_callback(inline_query, config, matches)
|
function googl:inline_callback(inline_query, config, matches)
|
||||||
local shorturl = matches[1]
|
local shorturl = matches[1]
|
||||||
local text, longUrl = googl:send_googl_info(shorturl)
|
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..'"}}]'
|
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)
|
utilities.answer_inline_query(self, inline_query, results, 1)
|
||||||
|
@ -4,13 +4,59 @@ imdb.command = 'imdb <query>'
|
|||||||
|
|
||||||
function imdb:init(config)
|
function imdb:init(config)
|
||||||
imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table
|
imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table
|
||||||
|
imdb.inline_triggers = {
|
||||||
|
"^imdb (.+)"
|
||||||
|
}
|
||||||
imdb.doc = [[*
|
imdb.doc = [[*
|
||||||
]]..config.cmd_pat..[[imdb* _<Film>_
|
]]..config.cmd_pat..[[imdb* _<Film>_
|
||||||
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 = '<b>'..movie_info.Title.. ' ('..movie_info.Year..')</b> von '..movie_info.Director..'\\n'..string.gsub(movie_info.imdbRating, '%.', ',')..'/10 | '..movie_info.Runtime..' | '.. movie_info.Genre..'\\n<i>' .. movie_info.Plot .. '</i>'
|
||||||
|
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
|
end
|
||||||
|
|
||||||
function imdb:action(msg, config)
|
function imdb:action(msg, config)
|
||||||
|
|
||||||
local input = utilities.input(msg.text)
|
local input = utilities.input(msg.text)
|
||||||
if not input then
|
if not input then
|
||||||
if msg.reply_to_message and msg.reply_to_message.text then
|
if msg.reply_to_message and msg.reply_to_message.text then
|
||||||
@ -21,33 +67,29 @@ function imdb:action(msg, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local url = 'http://www.omdbapi.com/?t=' .. URL.escape(input)
|
local url = BASE_URL..'/?t='..URL.escape(input)
|
||||||
|
local jstr, res = https.request(url)
|
||||||
local jstr, res = http.request(url)
|
|
||||||
if res ~= 200 then
|
if res ~= 200 then
|
||||||
utilities.send_reply(self, msg, config.errors.connection)
|
utilities.send_reply(self, msg, config.errors.connection)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local jdat = json.decode(jstr)
|
local jdat = json.decode(jstr)
|
||||||
|
|
||||||
if jdat.Response ~= 'True' then
|
if jdat.Response ~= 'True' then
|
||||||
utilities.send_reply(self, msg, config.errors.results)
|
utilities.send_reply(self, msg, config.errors.results)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local output = '*' .. jdat.Title .. ' ('.. jdat.Year ..')* von '..jdat.Director..'\n'
|
local output = '<b>'..jdat.Title.. ' ('..jdat.Year..')</b> von '..jdat.Director..'\n'
|
||||||
output = output .. string.gsub(jdat.imdbRating, '%.', ',') ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
|
output = output..string.gsub(jdat.imdbRating, '%.', ',')..'/10 | '..jdat.Runtime..' | '.. jdat.Genre..'\n'
|
||||||
output = output .. '_' .. jdat.Plot .. '_\n'
|
output = output..'<i>' .. jdat.Plot .. '</i>'
|
||||||
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
|
if jdat.Poster ~= "N/A" then
|
||||||
local file = download_to_file(jdat.Poster)
|
local file = download_to_file(jdat.Poster)
|
||||||
utilities.send_photo(self, msg.chat.id, file)
|
utilities.send_photo(self, msg.chat.id, file)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return imdb
|
return imdb
|
@ -71,9 +71,9 @@ end
|
|||||||
|
|
||||||
function qr:inline_callback(inline_query, config, matches)
|
function qr:inline_callback(inline_query, config, matches)
|
||||||
local text = matches[1]
|
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')
|
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..'"},'
|
local results = '[{"type":"photo","id":"'..math.random(100000000000000000)..'","photo_url":"'..image_url..'","thumb_url":"'..image_url..'","photo_width":600,"photo_height":600,"caption":"'..text..'"},'
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ function tagesschau:inline_callback(inline_query, config, matches)
|
|||||||
local article = matches[1]
|
local article = matches[1]
|
||||||
local full_url = 'http://www.tagesschau.de/'..article..'.html'
|
local full_url = 'http://www.tagesschau.de/'..article..'.html'
|
||||||
local text, img_url, headline, shorttext = tagesschau:get_tagesschau_article(article)
|
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
|
if text:match('"') then
|
||||||
text = text:gsub('"', '\\"')
|
text = text:gsub('"', '\\"')
|
||||||
|
@ -167,15 +167,15 @@ function wikipedia:inline_callback(inline_query, config, matches)
|
|||||||
end
|
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 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)
|
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
|
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 = '['
|
local results = '['
|
||||||
for num in pairs(data.search) do
|
for num in pairs(data.search) do
|
||||||
local title = data.search[num].title
|
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
|
if num < #data.search then
|
||||||
results = results..','
|
results = results..','
|
||||||
end
|
end
|
||||||
|
@ -147,10 +147,10 @@ function youtube:inline_callback(inline_query, config, matches)
|
|||||||
local query = matches[1]
|
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 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)
|
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)
|
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 = ""
|
local video_ids = ""
|
||||||
-- We get all videoIds from search...
|
-- We get all videoIds from search...
|
||||||
|
Reference in New Issue
Block a user