8: meBot [code]


//funtions used (in order):
//searchIt (searches for a term among recent tweets)
//randomTweetGenerator (includes r value and number output)
//followedMe (mentions people who follow, random intervals)
//mentionsMe (replies when someone @iamlittleprick)



console.log('meBot is working today');

var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);


//begin searchIt funtion
setInterval(searchIt, 1000*60*60);
searchIt();

function searchIt(){
  var searches = {
    q: 'new media art',
    count: 1,
    lang: 'en'
  }
  // dev.twitter.com and get search/statuses

  T.get('search/tweets', searches, getSearches);

  function getSearches(err, data, response){
    var tweets = data.statuses;
    if (tweets != undefined) {
      for (var i = 0; i < tweets.length; i++){
      console.log("HERE'S WHAT THEY RECENTLY SAID ABOUT NEW MEDIA ART: " + tweets[i].text);
      }
    }
  }
}
//end searchIt function



//THIS ONE tweets randomly, with a random number
//begin randomTweetGenerator function
// randomTweetGenerator();
// var r2 = Math.floor(Math.random()*5;
// setInterval(randomTweetGenerator, 1000*60); //how often to tweet
//1000ms=1sec *60=1min *60=1hr
randomTweetGenerator();

var rr = Math.floor(Math.random()*(53));
setInterval(randomTweetGenerator, 1000*60*rr);

function randomTweetGenerator(){

  var begin = [
  "i've been thinking about getting",
  "i'd really like",
  "thinking about",
  "lusting over"
  ];

  var noun = [
    "cookies",
    "stickers",
    "friends",
    "dollars",
    "followers",
    "flowers",
    "teacups",
    "vacations",
    "kittens",
    "cats",
    "t-shirts",
    "stickers",
    "boardgames",
    "balls of yarn",
  ];

  var end = [
    "today.",
    "in the near future.",
    "right now.",
    "soon.",
    "with a friend.",
    "for you.",
    "for myself. #treatYoSelf"
  ]

 var codingHashtags = [
    "#coderProblems",
    "#codingThisBitch",
    "#programmerProblems",
    "#syntaxError",
    "#turnDownForWhat",
    "#goOutside",
  ];

  var nostalgicHashtags = [
    "#eveninmydreams",
    "#imnotevenjoking",
    "#nostalgic",
    "#thegoodoldays",
    "#thinkingTooMuch"
  ];

  var boredHashtags = [
    "#indecisive",
    "#bored",
    "#dontknowwhattodo",
    "#idontknow"
  ];


  begin1 = begin[Math.floor(Math.random()*begin.length)];
  noun1 = noun[Math.floor(Math.random()*noun.length)];
  end1 = end[Math.floor(Math.random()*end.length)];

  codingHashtags1 = codingHashtags[Math.floor(Math.random()*codingHashtags.length)];
  nostalgicHashtags1 = nostalgicHashtags[Math.floor(Math.random()*nostalgicHashtags.length)];
  boredHashtags1 = boredHashtags[Math.floor(Math.random()*boredHashtags.length)];

  var r = Math.floor(Math.random()*50) + 2;

  var myRandomTweet = [
    "i've thought about you " + r + " times since my last tweet. " + nostalgicHashtags1,
    "i've been coding a lot lately, and i'm currently averaging " + r + " EPH (expletives per hour). " + codingHashtags1,
    "i've wanted to go outside " + r + " times since my last tweet. alas, i sit under the fluorescents. " + codingHashtags1,
    begin1 + " " + r + " " + noun1 + " " + end1,
    begin1 + " " + noun1,
    "every once in a while i ask this question, and it's just to get to know you all a little better. here's the question: how did you stumble upon my account? #hideandseek",
    "what should i do tomorrow? " + boredHashtags1,
    "what should i do today? " + boredHashtags1,
    "what should i do this weekend? " + boredHashtags1,
    "hi :)"
    ];

  myRandomTweet1 = myRandomTweet[Math.floor(Math.random()*myRandomTweet.length)];


  console.log("....... randomTweetGenerator started");

    var replyTweet = {
      status: myRandomTweet1
    }

    T.post('statuses/update', replyTweet, replyTweeted);

    function replyTweeted(err, data, response){
      if (err){
      console.log("oh, nos... error on randomTweetGenerator tweet");
      }else{
      console.log("....... randomTweetGenerator posted " + myRandomTweet1);
      }
    }
} //end of randomTweetGenerator function





//THIS FUNCTION is anytime someone follows me
//begin followedMe function

var streamFollow = T.stream('user');

streamFollow.on('follow', followedMe);


function followedMe(eventMsg){
  var name = eventMsg.source.name;
  var screenName = eventMsg.source.screen_name;
  var followedReply = [
    "how are you?",
    "what are you up to?",
    "what's up?",
    "thanks for the follow!",
    "thanks for the follow!!",
    "thanks for the follow! :)",
    "where are you from?",
    "what brings you around these parts?",
    "how did you stumble upon my account?",
    "what do you like to do for fun?",
    ":)",
    ":) :) :)",
    "thanks for following me :)",
    "thanks for following :)",
    "thanks for the follow",
    "followed me! yay! :)"
  ];

  var followedReplyBegin = [
    "hi ",
    "hi! ",
    "hi, ",
    "",
    "",
    "",
    "",
    "",
    "",
    "hey, it's ",
    "well, hello there ",
    "look who we have here :) "

  ];

  var followedReply1 = followedReply[Math.floor(Math.random()*followedReply.length)];
  var followedReplyBegin1 = followedReplyBegin[Math.floor(Math.random()*followedReplyBegin.length)];

  console.log("....... followedMe // i've been followed by " + screenName);
  // tweetBack("hi @" + screenName + " " + reply1);

  function delayedTweetBack(s) {
    tweetBack(s);
  }

  var tweetString = followedReplyBegin1 + "@" + screenName + " " + followedReply1;

  var r = Math.floor(Math.random()*37);

  setTimeout(delayedTweetBack, (1000*60*r), tweetString);

  function tweetBack(txt){

    var replyTweet = {
    status: txt
    }

  T.post('statuses/update', replyTweet, replyTweeted);

    function replyTweeted(err, data, response){
      if (err){
        console.log("followedMe FAILED");
      }else{
        console.log("followedMe // " + tweetString);
      }
    }
  }
} //end of followed funtion




//THIS FUNTION IS: thanks for the mention
//begin mentionsMe

var streamMentions = T.stream('user');

streamMentions.on('tweet', mentionsMe);

function mentionsMe(eventMsg){
  // var fs = require('fs');
  // var json = JSON.stringify(eventMsg,null,2);
  // fs.writeFile("tweet.json", json);

  var replyto = eventMsg.in_reply_to_screen_name;
  var text = eventMsg.text;
  var from = eventMsg.user.screen_name;

  var reply = [
    "really?",
    "so....what are you up to?",
    "nice :)",
    "...um",
    "not today..",
    "i think so",
    "huh?",
    "i see..",
    "what do you think?",
    "yeah, same here",
    "only on wednesdays lol",
    ":)",
    "well, well, well...",
    "according to the prophecy",
    "yeah..",
    "of course",
    "i'm sorry",
    "oh, really??",
    "thanks",
    ":D",
    "i'm not so sure",
    "what are your thoughts?"
  ];

  var reply1 = reply[Math.floor(Math.random()*reply.length)];

  if (replyto === 'iamlittleprick'){
    console.log(from + " says: " + text);


    function delayedTweetBack(s) {
      tweetBack(s);
    }

    var tweetString = "@" + from + " " + reply1;

    var r = Math.floor(Math.random()*23);

    setTimeout(delayedTweetBack, (1000*60*r), tweetString);

    function tweetBack(txt){

      var replyTweet = {
      status: txt
      }

  T.post('statuses/update', replyTweet, replyTweeted);

    function replyTweeted(err, data, response){
      if (err){
        console.log("mentionsMe FAILED");
        }else{
        console.log("....... yay!! mentionsMe works");
      }
    }
  }
}
} //end of mentionsMe function

Comments are closed.