2017-11-08 18:00:44 +01:00
|
|
|
|
local nintendo_search = {}
|
|
|
|
|
|
|
|
|
|
nintendo_search.triggers = {
|
2017-11-09 14:45:15 +01:00
|
|
|
|
'^/nin (.+)',
|
|
|
|
|
'^/nintendo (.+)'
|
2017-11-08 18:00:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function nintendo_search:get_info(gametitle)
|
|
|
|
|
local url = 'https://search.nintendo-europe.com/de/select?q='..gametitle..'&fq=type%3AGAME%20AND%20*%3A*&rows=1&wt=json'
|
|
|
|
|
local res, code = https.request(url)
|
|
|
|
|
if code ~= 200 then return nil end
|
|
|
|
|
local data = json.decode(res).response.docs[1]
|
|
|
|
|
if not data then return 'Nichts gefunden!' end
|
|
|
|
|
|
2017-11-09 14:45:15 +01:00
|
|
|
|
local title = '<b>'..data.title..'</b>'
|
2017-11-08 18:00:44 +01:00
|
|
|
|
|
|
|
|
|
if data.publisher then
|
|
|
|
|
publish = ' von <b>'..data.publisher..'</b>'
|
|
|
|
|
else
|
|
|
|
|
publish = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if data.system_names_txt then
|
|
|
|
|
system = ' für <b>'..data.system_names_txt[1]..'</b>'
|
|
|
|
|
else
|
|
|
|
|
system = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if data.pretty_agerating_s == 'n. n. b.' then
|
|
|
|
|
fsk = ''
|
|
|
|
|
else
|
|
|
|
|
fsk = '\n<b>'..data.pretty_agerating_s..'</b>'
|
|
|
|
|
end
|
|
|
|
|
|
2017-11-09 14:45:15 +01:00
|
|
|
|
if data.players_to == 1 then
|
|
|
|
|
player = '\n<b>1 Spieler</b>'
|
|
|
|
|
else
|
|
|
|
|
player = '\n<b>1 bis '..data.players_to..' Spieler</b>'
|
|
|
|
|
end
|
|
|
|
|
|
2017-11-08 18:00:44 +01:00
|
|
|
|
local link = '\n<a href="https://www.nintendo.de'..data.url..'">Webseite besuchen</a>'
|
2017-11-09 14:45:15 +01:00
|
|
|
|
local description = '\n\n<i>'..string.sub(unescape(data.excerpt:gsub("%b<>", "")), 1, 300)..'</i>'
|
|
|
|
|
local release = '\n<b>Release:</b> '..data.pretty_date_s
|
2017-11-08 18:00:44 +01:00
|
|
|
|
|
|
|
|
|
if data.image_url_h2x1_s then
|
2018-01-25 14:34:42 +01:00
|
|
|
|
image_url = '<a href="https://brawlbot.tk/img.php?url=https:'..data.image_url_h2x1_s..'"> </a>'
|
2017-11-08 18:00:44 +01:00
|
|
|
|
else
|
2018-01-25 14:34:42 +01:00
|
|
|
|
image_url = '<a href="https://brawlbot.tk/img.php?url=https:'..data.image_url..'"> </a>'
|
2017-11-08 18:00:44 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-09 14:45:15 +01:00
|
|
|
|
local text = title..publish..system..image_url..fsk..player..release..link..description
|
2017-11-08 18:00:44 +01:00
|
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function nintendo_search:action(msg, config, matches)
|
|
|
|
|
local gametitle = matches[1]
|
|
|
|
|
local text = nintendo_search:get_info(gametitle)
|
|
|
|
|
if not text then
|
|
|
|
|
utilities.send_reply(msg, config.errors.results)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return nintendo_search
|