diff --git a/pokedexHandler.js b/pokedexHandler.js index f258bd9..61b53ad 100644 --- a/pokedexHandler.js +++ b/pokedexHandler.js @@ -1,5 +1,6 @@ const fetch = require('node-fetch'); +// Bestehende Funktion async function sendToPokedex(username, pokemon, isCaught, isShiny) { const pokedexUrl = `https://pokedex-dt48.onrender.com/catch`; @@ -24,4 +25,31 @@ async function sendToPokedex(username, pokemon, isCaught, isShiny) { } } -module.exports = { sendToPokedex }; +// Neue Funktion, die zusätzlich genutzt werden kann +async function handlePokedexInteraction(username, pokemon, isCaught, isShiny) { + const pokedexUrl = `https://pokedex-dt48.onrender.com/catch`; + + try { + const response = await fetch(pokedexUrl, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + username, + pokemonId: pokemon.id, + caught: isCaught === '◓Gefangen◓', + shiny: !!isShiny + }) + }); + + return await response.text(); // Antwort des Pokédex-Backends zurückgeben + } catch (error) { + console.error('Fehler beim Senden an das Pokédex-Backend:', error); + throw new Error('Kommunikation mit dem Pokédex-Backend fehlgeschlagen.'); + } +} + +// Exporte aller Funktionen +module.exports = { + sendToPokedex, // Bestehende Funktion + handlePokedexInteraction // Neue Funktion +};