Blog

Archive for March, 2009

QUAKE LIVE Twitter IRC Bot

Friday, March 13th, 2009

On #quakelive on QuakeNet, there is a bot named QLTwitter that spits out text everytime the QUAKE LIVE Twitter account is updated. I’ve gotten a few requests for the code, so figure I’d publicly release it.

It has a couple of dependencies, all of which are available in Debian packages. Specifically, it requires POE, its IRC client module, and JSON modules. It is basic, but it works, and can easily be changed to broadcast tweets from any other account.

use warnings;
use strict;

use POE;
use POE::Component::IRC;
use JSON;
use LWP::Simple;
use Time::HiRes qw(time);

my ($irc) = POE::Component::IRC->spawn();
my $currStatus = '';
my $updateDelay = 120;
sub CHANNEL { "#quakelive" }

POE::Session->create(
    inline_states => {
       _start     => \&bot_start,
       irc_001    => \&on_connect,
       tick       => \&checkTweet
    },
);

sub bot_start {
    $irc->call(register => "all");
    $irc->call(connect =>
          { Nick => 'QLTwitter',
            Username => 'QLTwitter',
            Ircname  => 'QLTwitterBot by sponge',
            Server   => 'us.quakenet.org',
            Port     => '6667',
          }
    );
}

sub on_connect {
	$irc->call(privmsg => 'Q@CServe.quakenet.org', 'AUTH sponge ------');
	$irc->call(join => CHANNEL);
	$irc->call(privmsg => CHANNEL, 'QLTwitterBot is LARGE and IN CHARGE!');
	$_[KERNEL]->delay( tick => $updateDelay);
	checkTweet();
}

sub checkTweet {
	eval {
		my $json = get 'http://twitter.com/statuses/user_timeline/quakelive.json';
		my @statuses = from_json($json);
		my $curr = $statuses[0][0]->{'text'};
		if ($currStatus ne $curr) {
			$irc->call(privmsg => CHANNEL, "New QUAKE LIVE Twitter update: $curr");
			$currStatus = $curr;
		}
	};
	eval { $_[KERNEL]->delay( tick => $updateDelay); }
}

$poe_kernel->run();
exit 0;

New Server

Monday, March 9th, 2009

If you are reading this (which is kind of silly since if you’re not reading this you’ll have no idea this is there) then you’re reading d8d on the new server! Have been spending a couple of hours tonight getting all my stuff off our old server which is very likely ready to die any moment now. Anyway, hopefully all goes well, and time permitting, there’s been a few things I’ve been meaning to blog about.