about summary refs log tree commit diff stats
path: root/html/matt-chat
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-01-05 20:44:43 -0500
committerelioat <elioat@tilde.institute>2025-01-05 20:44:43 -0500
commit8d107ac58023981750de62d480385ab3549880e7 (patch)
treeeff76f74c11aa593e846ed8aea2c3bd888995015 /html/matt-chat
parent6e60722b275c55841a25f8a46c25002c6b875a52 (diff)
downloadtour-8d107ac58023981750de62d480385ab3549880e7.tar.gz
*
Diffstat (limited to 'html/matt-chat')
-rw-r--r--html/matt-chat/index.html3
-rw-r--r--html/matt-chat/pokemon.js157
2 files changed, 159 insertions, 1 deletions
diff --git a/html/matt-chat/index.html b/html/matt-chat/index.html
index 10779b9..8ccc9be 100644
--- a/html/matt-chat/index.html
+++ b/html/matt-chat/index.html
@@ -1068,7 +1068,8 @@ Available commands:\n
   /context - Show the current conversation's context
   /clear - Clear the chat history
   /help - Show this message
-  /theme [theme-name] - Switch theme (available: ${Object.keys(AVAILABLE_THEMES).join(', ')})
+  /theme [theme-name] - Switch theme (available themes: ${Object.keys(AVAILABLE_THEMES).join(', ')})
+      without a theme name, this will show all available themes, too
             `;
             addMessage(helpMessage, "bot");
         }
diff --git a/html/matt-chat/pokemon.js b/html/matt-chat/pokemon.js
new file mode 100644
index 0000000..e707e7b
--- /dev/null
+++ b/html/matt-chat/pokemon.js
@@ -0,0 +1,157 @@
+// Pokemon API functionality using functional programming approach
+
+// Base URL for the PokeAPI
+const POKE_API_BASE = 'https://pokeapi.co/api/v2';
+
+// Utility function to fetch data from the API
+const fetchPokeData = async (endpoint) => {
+    try {
+        const response = await fetch(`${POKE_API_BASE}${endpoint}`);
+        if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
+        return await response.json();
+    } catch (error) {
+        console.error('Error fetching Pokemon data:', error);
+        throw error;
+    }
+};
+
+// Function to get Pokemon basic info
+const getPokemonInfo = async (pokemonName) => {
+    try {
+        const data = await fetchPokeData(`/pokemon/${pokemonName.toLowerCase()}`);
+        return {
+            name: data.name,
+            id: data.id,
+            types: data.types.map(type => type.type.name),
+            abilities: data.abilities.map(ability => ({
+                name: ability.ability.name,
+                isHidden: ability.is_hidden
+            })),
+            stats: data.stats.map(stat => ({
+                name: stat.stat.name,
+                value: stat.base_stat
+            })),
+            height: data.height / 10, // Convert to meters
+            weight: data.weight / 10, // Convert to kilograms
+            sprite: data.sprites.front_default
+        };
+    } catch (error) {
+        throw new Error(`Could not find Pokemon: ${pokemonName}`);
+    }
+};
+
+// Function to get ability details
+const getAbilityInfo = async (abilityName) => {
+    try {
+        const data = await fetchPokeData(`/ability/${abilityName.toLowerCase()}`);
+        return {
+            name: data.name,
+            effect: data.effect_entries.find(e => e.language.name === 'en')?.effect || 'No effect description available.',
+            pokemon: data.pokemon.map(p => p.pokemon.name)
+        };
+    } catch (error) {
+        throw new Error(`Could not find ability: ${abilityName}`);
+    }
+};
+
+// Function to get move details
+const getMoveInfo = async (moveName) => {
+    try {
+        const data = await fetchPokeData(`/move/${moveName.toLowerCase()}`);
+        return {
+            name: data.name,
+            type: data.type.name,
+            power: data.power,
+            accuracy: data.accuracy,
+            pp: data.pp,
+            effect: data.effect_entries.find(e => e.language.name === 'en')?.effect || 'No effect description available.'
+        };
+    } catch (error) {
+        throw new Error(`Could not find move: ${moveName}`);
+    }
+};
+
+const getEvolutionInfo = async (pokemonName) => {
+    const data = await fetchPokeData(`/pokemon-species/${pokemonName.toLowerCase()}`);
+    return data.evolution_chain;
+};
+
+// Function to format Pokemon info into a readable message
+const formatPokemonInfo = (info) => {
+    const spriteImage = info.sprite ? `<img src="${info.sprite}" alt="${info.name} sprite" style="width: 100px; height: auto;" />` : '';
+    return `
+🔍 Pokemon: ${info.name.toUpperCase()} (#${info.id})
+📊 Types: ${info.types.join(', ')}
+💪 Abilities: ${info.abilities.map(a => `${a.name}${a.isHidden ? ' (Hidden)' : ''}`).join(', ')}
+📈 Stats:
+${info.stats.map(s => `  ${s.name}: ${s.value}`).join('\n')}
+📏 Height: ${info.height}m
+⚖️ Weight: ${info.weight}kg
+${spriteImage}
+    `.trim();
+};
+
+// Function to format ability info into a readable message
+const formatAbilityInfo = (info) => {
+    return `
+🔰 Ability: ${info.name.toUpperCase()}
+📝 Effect: ${info.effect}
+✨ Pokemon with this ability: ${info.pokemon.join(', ')}
+    `.trim();
+};
+
+// Function to format move info into a readable message
+const formatMoveInfo = (info) => {
+    return `
+⚔️ Move: ${info.name.toUpperCase()}
+🎯 Type: ${info.type}
+💥 Power: ${info.power || 'N/A'}
+🎲 Accuracy: ${info.accuracy || 'N/A'}
+🔄 PP: ${info.pp}
+📝 Effect: ${info.effect}
+    `.trim();
+};
+
+const formatEvolutionInfo = (info) => {
+    return `
+🔗 Evolution Chain: ${info.name.toUpperCase()}
+    `.trim();
+};
+
+// Main handler for Pokemon commands
+const handlePokemonCommand = async (args) => {
+    if (!args.length) {
+        return "Usage: /pokemon [pokemon|ability|move] [name]";
+    }
+
+    const [type, ...nameArgs] = args;
+    const name = nameArgs.join(' ').replace(/\s+/g, '-'); // Replace spaces with hyphens
+
+    if (!name) {
+        return "Please provide a name to search for.";
+    }
+
+    try {
+        switch (type.toLowerCase()) {
+            case 'pokemon':
+                const pokemonInfo = await getPokemonInfo(name);
+                return formatPokemonInfo(pokemonInfo);
+            case 'ability':
+                const abilityInfo = await getAbilityInfo(name);
+                return formatAbilityInfo(abilityInfo);
+            case 'move':
+                const moveInfo = await getMoveInfo(name);
+                return formatMoveInfo(moveInfo);
+            case 'evolution-chain':
+                const evolutionInfo = await getEvolutionInfo(name);
+                return formatEvolutionInfo(evolutionInfo);
+            default:
+                return "Invalid type. Use: pokemon, ability, or move.";
+        }
+    } catch (error) {
+        return `Error: ${error.message}`;
+    }
+};
+
+// Export the handler for use in main application
+export { handlePokemonCommand }; 
\ No newline at end of file