Kevin Nelson Marshall
Other entries:
« I still say it's lame...

I know I've been harsh on Twitter lately, but I have to admit that little by little I'm coming around to some of the cool things that you can do with it. One of those 'cool' things is to build bots.

I spent a little time today really digging into the details of just what you really need to do to build a Twitter bot. As it turns out it's VERY simple in lots of different languages! In fact, I built two very simple test bots already - one in Ruby and one in Perl. Both took only about 5 lines of actual code to some useful stuff!

Having jumped over the 'getting started' hump, I figured it was time to start building out a real Twitter bot. And what would be a better idea than to make my first 'real' bot a BotFu Twitter bot? The idea being that you'll eventually be able to send your BotFu game commands to twitter...and of course get your BotFu reactions via Twitter (think BotFu fight and playing via Twitter -- see Twitter can be used for cool things after all; who knew?!).

Anyway, the first problem that needed to be tackled (after the problem of having the idea and mapping out the basics of said idea) is how to get my bot's Twitter account to automatically follow anyone who follows it. Twitter requires that you are followed by an account before you can send a private Tweet to that account - so if I want to be able to send something like "d BotFu rnc" to the BotFu Twitter bot, BotFu first has to be following me.

So real quick here's the steps I'm taking to make this auto-follow happen...

1. Set up a Twitter account.

2. Within the settings area of your new account on Twitter there is a section called 'notices', make sure that you have 'Email when someone starts following me' checked and click save.

3. Set your email account up so that new emails get passed to the following Perl script (you'll of course need to be able to do this with your email provider or email software -- mine luckily supports this type of thing):

# Perl program to make the BotFu Twitter account follow a user
use Net::Twitter;

# your Twitter account information
my $username = "YOURUSERNAME";
my $password = "YOURPASSWORD";

# get the user we are going to start following from the subject line of the email sent:
if ($ARGV[0] =~ /(.+) is now following you on Twitter!/) {
  # the user we want to follow should be the first match!
  $user = $1;
  my $twit = Net::Twitter->new(username => $username, password => $password);
  # just in case we were following them already, we'll stop (before we start)
  $t1 = $twit->stop_following($user);
  # now we can start following the user
  $t2 = $twit->follow($user);
}



That's all there is to it...now when someone decides to "follow BotFu", the BotFu Twitter bot will return the favor and follow them as well. Which of course means that the user will then be able to send 'direct' messages to the BotFu Twitter bot...and that's the first key to the whole idea!

The next step is also key though and that's the part of having our Twitter bot listen for direct commands and pass them off to the BotFu games as needed, responding appropriately of course...but I'll save the gory details of that for another post or two...

posted by Kevin Marshall on 2008-04-19 00:00:00+00


Subscribe to my RSS feed »

BotFu feed with RSS reader

BotFu feed by Email


Search All Posts »


Kevin Marshall - Who's That?

I'm just your basic programmer. I can't spell to save my life, I'm not the greatest story teller, and I often ramble on about nothing. This blog showcases all of that!

If you're bored drop me an email at info at falicon.com or view my outdated resume.


Stalk Kevin on »

bit.ly
Delicious
Digg
Disqus
Facebook
Flickr
FriendFeed
Github
Last.fm
LinkedIn
StumbleUpon
Twitter (@falicon)

Archives by Category »

(28) Code »
(8) ColdFusion »
(15) Database »
(10) Factor »
(3) Falcons »
(320) General »
(13) JavaScript »
(18) Perl »
(17) PHP »
(20) Ruby »

Archives by Month »

(2) August 2010 »
(3) July 2010 »
(13) June 2010 »
(8) May 2010 »
(2) April 2010 »
(2) March 2010 »
(5) January 2010 »
(2) October 2009 »
(6) August 2009 »
(11) July 2009 »
(2) May 2009 »
(3) April 2009 »
(2) March 2009 »
(7) February 2009 »
(9) January 2009 »
(14) December 2008 »
(5) November 2008 »
(12) October 2008 »
(13) September 2008 »
(16) August 2008 »
(23) July 2008 »
(20) June 2008 »
(24) May 2008 »
(23) April 2008 »
(27) March 2008 »
(28) February 2008 »
(26) January 2008 »
(7) December 2007 »

Published Works »

Beginning Amazon's SimpleDB (Apress in dev.)
Pro Active Record (Apress 2007)
Web Services with Rails (O'Reilly 2006).

Contributed To »

Ruby Cookbook (O'Reilly 2006)
SQL Cookbook (O'Reilly 2005)
Various Reviews published in Computing Reviews

Free Code I've Created »

SimpleDB library in Python 3.0



This blog is powered by KickAssCode.