Pokedex gefixt

This commit is contained in:
Akamaru 2016-02-06 14:49:44 +01:00
parent 67c036c96c
commit 91be51cbd5

View File

@ -16,20 +16,21 @@ end
local function send_pokemon(query, receiver) local function send_pokemon(query, receiver)
local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/" local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/"
local b,c = http.request(url) local res,code = http.request(url)
local pokemon = json:decode(b) if code ~= 200 then return "Kein Pokémon gefunden" end
local pokemon = json:decode(res)
if pokemon == nil then if not pokemon then
return 'Kein Pokemon gefunden.' return 'Kein Pokémon gefunden.'
end end
local text = 'Pokédex ID: ' .. pokemon.pkdx_id local text = 'Pokédex ID: ' .. pokemon.pkdx_id
..'\nName: ' .. pokemon.name ..'\nName: ' .. pokemon.name
..'\nGewicht: ' .. pokemon.weight ..'\nGewicht: ' .. pokemon.weight
..'\nGröße: ' .. pokemon.height ..'\nGröße: ' .. pokemon.height
..'\nSpeed: ' .. pokemon.speed ..'\nGeschwindigkeit: ' .. pokemon.speed
..'\nSpezies: ' .. pokemon.species ..'\nSpezies: ' .. pokemon.species
local image = nil local image = nil
if images_enabled and pokemon.sprites and pokemon.sprites[1] then if images_enabled and pokemon.sprites and pokemon.sprites[1] then
@ -38,12 +39,12 @@ local function send_pokemon(query, receiver)
end end
if image then if image then
image = "http://pokeapi.co"..image local image = "http://pokeapi.co"..image
local extra = { local cb_extra = {
receiver = receiver, receiver=receiver,
text = text url=image
} }
send_photo_from_url(receiver, image, callback, extra) send_msg(receiver, text, send_photo_from_url_callback, cb_extra)
else else
return text return text
end end
@ -52,6 +53,7 @@ end
local function run(msg, matches) local function run(msg, matches)
local receiver = get_receiver(msg) local receiver = get_receiver(msg)
local query = URL.escape(matches[1]) local query = URL.escape(matches[1])
local query = string.lower(query)
return send_pokemon(query, receiver) return send_pokemon(query, receiver)
end end