2015-05-23 16:37:42 +02:00
|
|
|
do
|
|
|
|
|
2015-05-24 14:54:03 +02:00
|
|
|
local images_enabled = true;
|
|
|
|
|
|
|
|
local function get_sprite(path)
|
|
|
|
local url = "http://pokeapi.co/"..path
|
|
|
|
local b,c = http.request(url)
|
|
|
|
local data = json:decode(b)
|
|
|
|
local image = data.image
|
|
|
|
return image
|
|
|
|
end
|
|
|
|
|
|
|
|
local function callback(extra)
|
|
|
|
send_msg(extra.receiver, extra.text, ok_cb, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function send_pokemon(query, receiver)
|
2015-05-23 16:37:42 +02:00
|
|
|
local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/"
|
2016-02-06 14:49:44 +01:00
|
|
|
local res,code = http.request(url)
|
|
|
|
if code ~= 200 then return "Kein Pokémon gefunden" end
|
|
|
|
local pokemon = json:decode(res)
|
2015-05-23 16:37:42 +02:00
|
|
|
|
2016-02-06 14:49:44 +01:00
|
|
|
if not pokemon then
|
|
|
|
return 'Kein Pokémon gefunden.'
|
2015-05-23 16:37:42 +02:00
|
|
|
end
|
2015-05-24 14:54:03 +02:00
|
|
|
|
2016-02-07 14:11:53 +01:00
|
|
|
local text = 'Pokédex ID: '..pokemon.pkdx_id
|
|
|
|
..'\nName: '..pokemon.name
|
|
|
|
..'\nTyp: '..pokemon.types[1].name
|
|
|
|
..'\nGewicht: '..pokemon.height..' kg'
|
|
|
|
..'\nGröße: '..pokemon.weight..' cm'
|
|
|
|
..'\nGeschwindigkeit: '..pokemon.speed
|
|
|
|
..'\nSpezies: '..pokemon.species
|
|
|
|
--[[if pokemon.evolutions then
|
|
|
|
text = text..'\nEntwickelt sich zu '..pokemon.evolutions[1].to
|
|
|
|
end]]
|
2016-02-06 14:49:44 +01:00
|
|
|
|
2015-05-24 14:54:03 +02:00
|
|
|
local image = nil
|
|
|
|
|
|
|
|
if images_enabled and pokemon.sprites and pokemon.sprites[1] then
|
|
|
|
local sprite = pokemon.sprites[1].resource_uri
|
|
|
|
image = get_sprite(sprite)
|
|
|
|
end
|
|
|
|
|
|
|
|
if image then
|
2016-02-06 14:49:44 +01:00
|
|
|
local image = "http://pokeapi.co"..image
|
|
|
|
local cb_extra = {
|
|
|
|
receiver=receiver,
|
|
|
|
url=image
|
2015-05-24 14:54:03 +02:00
|
|
|
}
|
2016-02-06 14:49:44 +01:00
|
|
|
send_msg(receiver, text, send_photo_from_url_callback, cb_extra)
|
2015-05-24 14:54:03 +02:00
|
|
|
else
|
|
|
|
return text
|
|
|
|
end
|
2015-05-23 16:37:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function run(msg, matches)
|
2015-05-24 14:54:03 +02:00
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
local query = URL.escape(matches[1])
|
2016-02-06 14:49:44 +01:00
|
|
|
local query = string.lower(query)
|
2015-05-24 14:54:03 +02:00
|
|
|
return send_pokemon(query, receiver)
|
2015-05-23 16:37:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-05-23 17:23:57 +02:00
|
|
|
description = "Pokedex für Telegram",
|
2015-05-24 14:54:03 +02:00
|
|
|
usage = {"/pokedex [Name/ID]","/pokemon [Name/ID]","/pkmn [Name/ID]"},
|
|
|
|
patterns = {"^/pokedex (.*)$","^/pokemon (.+)$","^/pkmn (.+)$"},
|
2015-05-23 16:37:42 +02:00
|
|
|
run = run
|
2015-05-24 14:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end
|