My Little Twitter Bot

It all started when @ndoto replied to one of my “eeyup” tweets saying that he wished there was a Big Macintosh Twitter bot that would reply with an “eeyup” if you sent a tweet containing “eeyup”.

For those who aren’t in the know, Big Macintosh is a character on the cartoon My Little Pony: Friendship is Magic. It’s a slight re-imagining of the original show, headed by the same creative mind behind Foster’s Home for Imaginary Friends – an awesome show with clever writing. Needless to say, that same maturity (but kid-appeal) carries over to the new My Little Pony. I suppose I should clarify that I’m not enough of a fan to call myself a brony, but I do think the show is about 20% cooler than most other things on television – and Big Macintosh is by far my favorite character. :)

I’ve always wanted to make a Twitter bot, so I jumped at the opportunity. In this post, I’d like to share some of the technical details, and decision making, that brought @BigMacinbot to life.

The first thing I had to decide was how I was going to interface with Twitter. From my experience with Trowl, I figured I could throw together a simple C# program, running on my home computer, using the Twitter library I had already created. The downside, though, is that if my internet connection went down, or my computer powered off, the bot would go quiet. So instead, I decided to write a PHP script, and host it on my remote server space. I’d also use cron to automatically run the script every five minutes. Finally, since I was already familiar with the Twitter API, I didn’t feel the need to write the API calls from scratch. I used a PHP Twitter library, tmhOAuth, that had everything I needed, and was simple to use.

With that decided, I turned my attention to how the bot, itself, would work. It seemed very simple at first: search Twitter, then send a reply to every tweet containing “eeyup”. As I kept thinking about it, though, I realized just how annoying that would be. If someone used that phrase often enough, they’d end up being spammed by the bot. The point of this was to have a bit of fun, not annoy people.

To confirm my suspicions, I created a very simple script that just did the “search Twitter” part, and emailed the results. I let this run over the course of a couple days and, indeed, more people than I expected used “eeyup” — and used it frequently. With this in mind, I started to create a set of rules that a tweet would have to pass through before the bot would send a reply:

Big Macintosh’s Rules of Agreement

  1. Tweet was sent within the last two hours.
  2. Not a retweet
  3. Tweet says “eeyup” somewhere. (Twitter name cannot contain “eeyup”.)
  4. User isn’t being ignored. If a user really doesn’t like Big Macinbot, they can reply with “nope”, and they’ll never receive another reply.
  5. The user has never received a reply from Big Macinbot, or they haven’t received a reply recently. The definition of “recently” is based on probability. If the last time the user received a reply was within two weeks, Big Macinbot looks to see how long ago it was. The closer to two weeks, the more likely a reply will be sent. After two weeks, a reply is definitely sent. Here is the code, for those interested:
   1: $diff = time() – $previous_reply_timestamp;

   2: $prob = ($diff / 1209600) * 100; // Number of seconds in two weeks.

   3:  

   4: $rand = rand(1,100);

   5:  

   6: if ($rand > 1 && $rand < $prob)

   7: {

   8:     return true;

   9: }

Coding these rules wasn’t too difficult – the trickiest part was building a simple database to keep track of users, and when their last reply was sent. Relying on a database makes the script a bit more complex, but the ability to stagger Big Macinbot’s replies makes it worthwhile.

After implementing this base functionality, I wondered what should happen if someone replied to Big Macinbot. Most other bots, as far as I knew, didn’t do anything if you replied or mentioned them. But I didn’t want to miss out on a chance to give this bot a little more personality – it would still respond with “eeyup”, but the interaction could be fun. Since I was already checking mentions for ignore requests, I just added another case that sent a reply back if it was a normal mention. To build upon the goal of adding some more personality, I actually have Big Macinbot choose from three random responses: Eeyup. / Eeyup! / … Eeeyup?

Another reason for the random responses is to try and get around Twitter’s “duplicate status” error – Twitter denies a status posting if it’s the same as your previous status. Unfortunately, it seems as though Twitter doesn’t just check your last status, like I thought, but all of your recent statuses. So right now, once someone exhausts the three random responses, Big Macinbot goes quiet due to Twitter errors.

At the beginning, though, I wasn’t even sure if anyone would bother replying. Everything else was in place, and seemed to be working, so it was time to move forward. On Saturday, January 14, 2012, Big Macinbot came to life.

The Reaction

I have to admit that about halfway through coding the bot – about the time that I was perfecting the Rules of Agreement – I wondered if I should keep going. I started to think that no one was going to like the bot; that everyone would block and it would be done within a week or two.

Well, all I can say is that Twitter bronies are awesome! Not only does everyone seem to love Big Macinbot, but they reply to and follow the bot on a regular basis. It has been fun seeing the reactions, and the general love for Big Macintosh. I’ve had the pleasure of discovering a few very nice folks, too, so that has been a wonderful bonus. :)

Because of Big Macinbot’s popularity, I’ve been making regular tweaks and updates to how he works, and I’m currently working on a suggestion to have Big Macinbot reply to everyone when being mentioned. I never expected him to gain such a following, but I’m really happy he did, because I think he’s a really fun bot! I just hope Twitter doesn’t suspend the account – I’ve tried to be light on Twitter’s resources, and follow best practices, so hopefully they’ll let him keep going. Eeyup!

I’d like to finish this post with some of my favorite reactions and replies to Big Macinbot. Thank you again to everypony for such a wonderful welcome to Twitter! If anyone has suggestions, or questions about what I wrote about here, please feel free to post a comment, or send me a message at @mageuzi! :)

Tagged , , , , , , ,

2 thoughts on “My Little Twitter Bot

  1. ZorkFox says:

    I use “Eeyup” in casual conversation, testing for random bronies that might be nearby—no luck so far—but I use it on Twitter with the express purpose of soliciting replies from @BigMacinbot. He really, really makes my day sometimes. -:)

    Thank you SO much!

  2. gabriel says:

    i highly doubt twitter will bann this bot

    https://twitter.com/urbandictionary

    heck urbandictionary runs a bot and it no doubt uses loads more twitter resources then this bot

Leave a Reply to gabriel Cancel reply

Your email address will not be published. Required fields are marked *