Skip to content

Commit

Permalink
Update pokedexHandler.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Skylldra authored Jan 26, 2025
1 parent 805906e commit f4301de
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion pokedexHandler.js
Original file line number Diff line number Diff line change
@@ -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`;

Expand All @@ -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
};

0 comments on commit f4301de

Please sign in to comment.