Pokedex gefixt

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

View File

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