From f91e4a52abad7afcede9fa7d3a097bcee54ac17c Mon Sep 17 00:00:00 2001 From: awfuljack Date: Sat, 18 Jun 2016 02:43:29 -0400 Subject: [PATCH] lol --- Procfile | 1 + app.js | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++ config.json | 18 ++++++++ 3 files changed, 143 insertions(+) create mode 100644 Procfile create mode 100644 app.js create mode 100644 config.json diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..67fcc43 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +worker: node app.js \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..9f8dadd --- /dev/null +++ b/app.js @@ -0,0 +1,124 @@ +var Twit = require('twit') +var fs = require('fs') +var low = require('lowdb'); +var storage = require('lowdb/file-sync'); +var session = low('./config.json', {'storage': storage}); + +var T = new Twit({ + consumer_key: '', + consumer_secret: '', + access_token: '', + access_token_secret: '', + timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests. +}) + +// filter the public stream by english tweets containing `#apple` +// +var stream = T.stream('statuses/filter', { follow: '25073877, 1339835893, 216776631, 179932936' }) +stream.on('tweet', function (tweet) { + if (tweet.user.screen_name === 'realDonaldTrump') { + var b64content = fs.readFileSync('./pics/trump.gif', { encoding: 'base64' }) + var trumpmessages = session.object.trumpmessages; + var randomtrumpmessage = trumpmessages[Math.floor(Math.random() * trumpmessages.length)]; + +// first we must post the media to Twitter +T.post('media/upload', { media_data: b64content }, function (err, data, response) { + // now we can assign alt text to the media, for use by screen readers and + // other text-based presentations and interpreters + var mediaIdStr = data.media_id_string + var altText = "Small flowers in a planter on a sunny balcony, blossoming." + var meta_params = { media_id: mediaIdStr, alt_text: { text: altText } } + var nameID = tweet.id_str; + var name = tweet.user.screen_name; + + T.post('media/metadata/create', meta_params, function (err, data, response) { + if (!err) { + // now we can reference the media and post a tweet (media will attach to the tweet) + var params = {in_reply_to_status_id: nameID, status: '@' + name + ' ' + randomtrumpmessage, media_ids: [mediaIdStr] } + + T.post('statuses/update', params, function (err, data, response) { + console.log("Replied to Trump's Tweet with " + randomtrumpmessage) + }) + } + }) + }) +} + if (tweet.user.screen_name === 'HillaryClinton') { + var b64content = fs.readFileSync('./pics/hillary.gif', { encoding: 'base64' }) + var hillarymessages = session.object.hillarymessages; + var randomhillarymessage = hillarymessages[Math.floor(Math.random() * hillarymessages.length)]; +// first we must post the media to Twitter +T.post('media/upload', { media_data: b64content }, function (err, data, response) { + // now we can assign alt text to the media, for use by screen readers and + // other text-based presentations and interpreters + var mediaIdStr = data.media_id_string + var altText = "Small flowers in a planter on a sunny balcony, blossoming." + var meta_params = { media_id: mediaIdStr, alt_text: { text: altText } } + var nameID = tweet.id_str; + var name = tweet.user.screen_name; + + T.post('media/metadata/create', meta_params, function (err, data, response) { + if (!err) { + // now we can reference the media and post a tweet (media will attach to the tweet) + var params = {in_reply_to_status_id: nameID, status: '@' + name + " " + randomhillarymessage, media_ids: [mediaIdStr] } + + T.post('statuses/update', params, function (err, data, response) { + console.log("Replied to Hillary's Tweet with " + randomhillarymessage) + }) + } + }) + }) +} + if (tweet.user.screen_name === 'BernieSanders') { + var b64content = fs.readFileSync('./pics/bernie.gif', { encoding: 'base64' }) + var berniemessages = session.object.berniemessages; + var randomberniemessage = berniemessages[Math.floor(Math.random() * berniemessages.length)]; +// first we must post the media to Twitter +T.post('media/upload', { media_data: b64content }, function (err, data, response) { + // now we can assign alt text to the media, for use by screen readers and + // other text-based presentations and interpreters + var mediaIdStr = data.media_id_string + var altText = "Small flowers in a planter on a sunny balcony, blossoming." + var meta_params = { media_id: mediaIdStr, alt_text: { text: altText } } + var nameID = tweet.id_str; + var name = tweet.user.screen_name; + + T.post('media/metadata/create', meta_params, function (err, data, response) { + if (!err) { + // now we can reference the media and post a tweet (media will attach to the tweet) + var params = {in_reply_to_status_id: nameID, status: '@' + name + " " + randomberniemessage, media_ids: [mediaIdStr] } + + T.post('statuses/update', params, function (err, data, response) { + console.log("Replied to Bernie's Tweet") + }) + } + }) + }) +} + if (tweet.user.screen_name === 'HulkHogan') { + var b64content = fs.readFileSync('./pics/hulk.gif', { encoding: 'base64' }) + var hulkmessages = session.object.hulkmessages; + var randomhulkmessage = hulkmessages[Math.floor(Math.random() * hulkmessages.length)]; +// first we must post the media to Twitter +T.post('media/upload', { media_data: b64content }, function (err, data, response) { + // now we can assign alt text to the media, for use by screen readers and + // other text-based presentations and interpreters + var mediaIdStr = data.media_id_string + var altText = "Small flowers in a planter on a sunny balcony, blossoming." + var meta_params = { media_id: mediaIdStr, alt_text: { text: altText } } + var nameID = tweet.id_str; + var name = tweet.user.screen_name; + + T.post('media/metadata/create', meta_params, function (err, data, response) { + if (!err) { + // now we can reference the media and post a tweet (media will attach to the tweet) + var params = {in_reply_to_status_id: nameID, status: '@' + name + " " randomhulkmessage, media_ids: [mediaIdStr] } + + T.post('statuses/update', params, function (err, data, response) { + console.log("Replied to Hulk's Tweet") + }) + } + }) + }) +} +}) \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..6c8c9fd --- /dev/null +++ b/config.json @@ -0,0 +1,18 @@ +{ + "trumpmessages": [ + "Messages for Trump go here." + ], + "hillarymessages": [ + "Messages for Hillary go here." + ], + "berniemessages": [ + "Messages for Bernie go here." + ], + "hulkmessages": [ + "Messages for Hulk go here." + ] +} + + + +