diff --git a/app.js b/app.js index 933c44d..ff4e9d5 100644 --- a/app.js +++ b/app.js @@ -135,8 +135,13 @@ let kara = new Vue({ body: imageObject.body, bot: bot, src: imageObject.src + }); + setTimeout(() => { + this.scrollDown(); + }, 1000); + this.updateStorage(); }, botMessage(message) { @@ -437,17 +442,31 @@ let kara = new Vue({ this.meMessage(this.checkForCommands(message, 'me ')); } - if (this.checkForCommands(message, 'cat')) { - this.getRandomCat(); - } + let animals = [ + {animal: 'birb', emoji: '🐦'}, + {animal: 'dog', emoji: '🐶'}, + {animal: 'cat', emoji: '🐱'}, + {animal: 'fox', emoji: '🦊'}, + {animal: 'panda', emoji: '🐼'}, + {animal: 'red_panda', emoji: '🤩'}, + {animal: 'koala', emoji: '🐨'} + ]; - if (this.checkForCommands(message, 'shiba')) { - this.getRandomShiba(); - } + animals.forEach((animal) => { + if (this.checkForCommands(message, animal.animal + 'Img')) { + this.rsaRandomAnimalImage(animal.animal, animal.emoji); + } - if (this.checkForCommands(message, 'birb')) { - this.getRandomBirb(); - } + if (this.checkForCommands(message, animal.animal + 'Fact')) { + this.rsaRandomAnimalFact(animal.animal, animal.emoji); + } + }); + + animals.forEach((animal) => { + if (this.checkForCommands(message, animal.animal)) { + this.rsaRandomAnimalImage(animal.animal, animal.emoji); + } + }); if (this.checkForCommands(message, 'quiz')) { this.startQuiz(); @@ -546,66 +565,6 @@ let kara = new Vue({ this.updateStorage(); }, - getRandomCat() { - let vue = this; - let url = 'https://api.thecatapi.com/v1/images/search?apiKey=5666b3cc-a7a3-406f-904d-b13594780d7f'; - - axios.get(url) - .then(function (response) { - vue.addImageMessage({ - caption: '', - image: response.data[0].url - }, true); - setTimeout(() => { - vue.scrollDown(); - }, 1000) - }) - .catch(function (error) { - vue.botMessage("I can't find any images at the moment, sorry.. 😿"); - }) - - this.updateStorage(); - }, - getRandomShiba() { - let vue = this; - let url = 'http://shibe.online/api/shibes'; - - axios.get(url) - .then(function (response) { - vue.addImageMessage({ - caption: '', - image: response.data[0].url - }, true); - setTimeout(() => { - vue.scrollDown(); - }, 1000) - }) - .catch(function (error) { - vue.botMessage("I can't find any images at the moment, sorry.. 🐶"); - }) - - this.updateStorage(); - }, - getRandomBirb() { - let vue = this; - let url = '//random.birb.pw/tweet.json'; - - axios.get(url) - .then(function (response) { - vue.addImageMessage({ - caption: '', - image: 'https://random.birb.pw/img/' + response.data.file - }, true); - setTimeout(() => { - vue.scrollDown(); - }, 1000) - }) - .catch(function (error) { - vue.botMessage("I can't find any images at the moment, sorry.. 🐦"); - }) - - this.updateStorage(); - }, tellJoke(category) { let vue = this; let categorySet = false; @@ -739,6 +698,37 @@ let kara = new Vue({ this.updateStorage(); }, + // Some Random API Commands + rsaRandomAnimalImage(animal, emoji = '😄') { + let vue = this; + + axios.post('/api/curlJson', { + url: 'https://some-random-api.ml/img/' + animal + }) + .catch((error) => { + vue.botMessage("Sorry, i can't find any good pictures right now 🙁" + emoji); + }) + .then((response) => { + vue.addImageMessage({ + body: emoji, + src: response.data.link + }, true); + }) + }, + rsaRandomAnimalFact(animal, emoji = '😄') { + let vue = this; + + axios.post('/api/curlJson', { + url: 'https://some-random-api.ml/facts/' + animal + }) + .catch((error) => { + vue.botMessage("Sorry, i can't think of any good facts right now 🙁" + emoji); + }) + .then((response) => { + vue.botMessage(response.data.fact); + }) + }, + // LocalStorage getSavedData() { let savedName = localStorage.getItem('name');