8ball |
- 8ball // Define a new neuron called "8ball"
brain.set('8ball', {
// Define a function that returns a random 8ball response
eightBall: async function() {
// Extract the user's question from the input text
const question = this.input.text.slice(7);
// Make a request to the "https://8ball.delegator.com/" API to get a random 8ball response
const response = await fetch(`https://8ball.delegator.com/magic/JSON/${encodeURIComponent(question)}`);
// Parse the response JSON and extract the answer
const data = await response.json();
const answer = data.magic.answer;
// Return the 8ball answer as the output text
return answer;
},
});
// Set up the "8ball" neuron to trigger when the user enters "!8ball" in their message
brain.addNeuron('8ball', '!8ball', 'eightBall');
|