2016-04-11 06:04:47 +02:00
|
|
|
local pokedex = {}
|
|
|
|
|
2016-08-25 00:30:25 +02:00
|
|
|
pokedex.command = 'pokedex <Name (englisch/ID>'
|
2016-05-27 05:28:44 +02:00
|
|
|
|
|
|
|
function pokedex:init(config)
|
2016-08-25 00:30:25 +02:00
|
|
|
pokedex.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('pokedex', true):t('dex', true):t('pkmn', true).table
|
|
|
|
pokedex.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[pokedex* _<Name oder ID>_: Sucht Pokémon im Pokedex (nur englisch)
|
|
|
|
]]
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-25 00:30:25 +02:00
|
|
|
function pokedex:get_sprite(path)
|
|
|
|
local url = "http://pokeapi.co/"..path
|
|
|
|
local b, c = http.request(url)
|
|
|
|
if c ~= 200 then return nil end
|
|
|
|
local data = json.decode(b)
|
|
|
|
local image = data.image
|
|
|
|
return image
|
|
|
|
end
|
2016-01-08 14:44:37 +01:00
|
|
|
|
2016-08-25 00:30:25 +02:00
|
|
|
function pokedex:get_pkmn(query)
|
|
|
|
local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/"
|
|
|
|
local res, code = http.request(url)
|
|
|
|
if code ~= 200 then return nil end
|
|
|
|
local pokemon = json.decode(res)
|
|
|
|
if not pokemon then return nil end
|
|
|
|
|
|
|
|
local text = '<b>Pokédex ID:</b> '..pokemon.pkdx_id
|
|
|
|
..'\n<b>Name:</b> '..pokemon.name
|
|
|
|
..'\n<b>Typ:</b> '..pokemon.types[1].name
|
|
|
|
..'\n<b>Gewicht:</b> '..pokemon.height..' kg'
|
|
|
|
..'\n<b>Größe:</b> '..pokemon.weight..' cm'
|
|
|
|
..'\n<b>Geschwindigkeit:</b> '..pokemon.speed
|
|
|
|
if not pokemon.species:isempty() then
|
|
|
|
text = text..'\n<b>Spezies:</b> '..pokemon.species
|
|
|
|
end
|
|
|
|
|
|
|
|
return text, pokemon.pkdx_id
|
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-08-25 00:30:25 +02:00
|
|
|
function pokedex:action(msg, config)
|
|
|
|
local input = utilities.input_from_msg(msg)
|
|
|
|
if not input then
|
|
|
|
utilities.send_reply(msg, pokedex.doc, true)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
utilities.send_typing(msg.chat.id, 'typing')
|
|
|
|
local text, id = pokedex:get_pkmn(input)
|
|
|
|
if not text then
|
|
|
|
utilities.send_reply(msg, config.errors.result)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
|
|
|
utilities.send_photo(msg.chat.id, download_to_file('http://pokeapi.co/media/img/'..id..'.png'), nil, msg.message_id)
|
|
|
|
utilities.send_reply(msg, text, 'HTML')
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return pokedex
|