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
- Tweet was sent within the last two hours.
- Not a retweet
- Tweet says “eeyup” somewhere. (Twitter name cannot contain “eeyup”.)
- 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.
- 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:
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.
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! :)
— Chris P. Come here! (@tictac472_FTW) January 14, 2012
@BigMacinbot I LOVE YOU.
— Justin Bieber fan.ಌ(@HackedByBieber) January 15, 2012
@BigMacinbot :3 that made my day
— DMName (@SirDMName) January 15, 2012
— Lexy (@IndieLexy) January 20, 2012
@BigMacinbot I agree
— Please Stand By (@StandbyPlease) January 19, 2012
— Big Macintosh (@BigMacinbot) January 17, 2012
— Big Macintosh (@BigMacinbot) January 16, 2012
@BigMacinbot This conversation seems one-sided.
— Philip Kardefelt (@Terkup) January 17, 2012
— Big Macintosh (@BigMacinbot) January 16, 2012