local pokedex = {} pokedex.command = 'pokedex ' function pokedex:init(config) 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* __: Sucht Pokémon im Pokedex (nur englisch) ]] end 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 = '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 if not pokemon.species:isempty() then text = text..'\nSpezies: '..pokemon.species end return text, pokemon.pkdx_id end function pokedex:action(msg, config) local query = utilities.input_from_msg(msg) if not query then utilities.send_reply(msg, pokedex.doc, true) return end utilities.send_typing(msg.chat.id, 'typing') local text, id = pokedex:get_pkmn(query) local image = 'http://pokeapi.co/media/img/'..id..'.png' 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, image, nil, msg.message_id) utilities.send_reply(msg, text, 'HTML') end return pokedex