This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Neues Plugin: Nintendo Game Suche

  • Loading branch information...
Akamaru committed Nov 8, 2017
1 parent 301e99f commit df66a4c0a3a600dcc3e5979df75699dd8b02a7cd
Showing with 60 additions and 0 deletions.
  1. +60 −0 miku/plugins/nintendo_search.lua
@@ -0,0 +1,60 @@
local nintendo_search = {}
nintendo_search.triggers = {
'/nin (.+)',
'/nintendo (.+)'
}
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
local title = data.title
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
local link = '\n<a href="https://www.nintendo.de'..data.url..'">Webseite besuchen</a>'
local description = string.sub(unescape(data.excerpt:gsub("%b<>", "")), 1, 300)
local release = data.pretty_date_s
if data.image_url_h2x1_s then
image_url = 'http://anditest.perseus.uberspace.de/img.php?url=https:'..data.image_url_h2x1_s
else
image_url = 'http://anditest.perseus.uberspace.de/img.php?url=https:'..data.image_url
end
local text = '<b>'..title..'</b>'..publish..system..'<a href="'..image_url..'"> </a>'..fsk..'\n'..'<b>Release:</b> '..release..link..'\n\n<i>'..description..'</i>'
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

0 comments on commit df66a4c

Please sign in to comment.