aboutsummaryrefslogtreecommitdiff
path: root/src/commands/jokes.js
diff options
context:
space:
mode:
authorIndrajith K L2021-03-27 21:57:16 +0530
committerIndrajith K L2021-03-27 21:57:16 +0530
commite3dba82cf3cdbdf5c0aad3d308013695a2074ecf (patch)
tree83b1b0f5f968ca3f4c260a068fe364821e68176a /src/commands/jokes.js
parent6048206733b3d6bb9ffbacb3e54f4bef88777585 (diff)
downloadlul-bot-e3dba82cf3cdbdf5c0aad3d308013695a2074ecf.tar.gz
lul-bot-e3dba82cf3cdbdf5c0aad3d308013695a2074ecf.tar.bz2
lul-bot-e3dba82cf3cdbdf5c0aad3d308013695a2074ecf.zip
Code Refactoring
* Adds Config for commands * Moved Casual Messages to language.json
Diffstat (limited to 'src/commands/jokes.js')
-rw-r--r--src/commands/jokes.js28
1 files changed, 28 insertions, 0 deletions
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