From e3dba82cf3cdbdf5c0aad3d308013695a2074ecf Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 27 Mar 2021 21:57:16 +0530 Subject: Code Refactoring * Adds Config for commands * Moved Casual Messages to language.json --- src/commands/jokes.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/commands/jokes.js (limited to 'src/commands/jokes.js') diff --git a/src/commands/jokes.js b/src/commands/jokes.js new file mode 100644 index 0000000..578e51b --- /dev/null +++ b/src/commands/jokes.js @@ -0,0 +1,28 @@ +const fetch = require('node-fetch'); + +function randomJokes(message) { + message.channel.startTyping(); + getJokes().then(response => { + message.channel.stopTyping(); + if (response) { + message.channel.startTyping(); + message.reply(response.setup); + setTimeout(() => { + message.channel.stopTyping(); + message.reply(`||${response.punchline}||`); + }, 5000); + } + }); +} + +async function getJokes() { + return fetch(`https://official-joke-api.appspot.com/jokes/random`) + .then(res => res.json()) +} + + +module.exports = { + execute(client,message, args) { + randomJokes(message); + } +} \ No newline at end of file -- cgit v1.2.3