From 61bb0066b04db93ab4e3b5ce1540ac39166fdafe Mon Sep 17 00:00:00 2001 From: JayWll Date: Sat, 25 Apr 2020 14:53:12 -0600 Subject: [PATCH] Moved tweet functionality out to alert.js --- nodeapp/src/alert.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/nodeapp/src/alert.js b/nodeapp/src/alert.js index 00e0e4c..40a69a2 100644 --- a/nodeapp/src/alert.js +++ b/nodeapp/src/alert.js @@ -4,6 +4,41 @@ require('dotenv').config({path: path.join(__dirname, '../../.env')}) const alert = (type) => { console.log('Alert triggered for type: ' + type) + + switch(type) { + // Water is needed + case 'wantwater': + const tweet = [ + 'I\'m getting pretty thirsty over here, @JayWll', + 'So. Very. Dry. You know I\'m a succulent not a cactus, right @JayWll? 🌵', + 'Hey @JayWll, water me. 🥛', + 'They say a man shall not live by bread alone, and a succulent won\'t live if you don\'t WATER ME @JAYWLL!!1! 🍞🚰💦', + '@JayWll seriously bro. A little water. That\'s all I ask.' + ] + break; + + // Water has been received + case 'gotwater': + const tweet = [ + 'Thanks to whoever watered me just now!! So moist.', + 'So refreshing! Thank you, mysterious stranger, for the life-giving liquidy sustenance.', + 'Whoever watered me (I\'m kind of guessing it was you, @Katheryn_mur), know that I appreciate it!' + ] + break; + } + + // Define options for the twitter API + const msg = new twit({ + consumer_key: process.env.CONSUMER_KEY, + consumer_secret: process.env.CONSUMER_SECRET, + access_token: process.env.ACCESS_TOKEN, + access_token_secret: process.env.ACCESS_TOKEN_SECRET + }) + + // Post a tweet + //msg.post('statuses/update', { status: tweet[Math.floor(Math.random() * tweet.length)] }) + console.log(tweet[Math.floor(Math.random() * tweet.length)]) + } } module.exports = alert