TiarraでTwitterをUpdateするモジュール

IRCの独り言を拾うときに使うと良いと思います。

package User::Twitter;
use strict;
use warnings;
use base qw(Module);
use Multicast;
use Net::Twitter;

sub message_arrived {
    my ($this,$msg,$sender) = @_;
    my @result = ($msg);

    # サーバーからのメッセージか?
    if ($sender->isa('IrcIO::Client')) {
        # PRIVMSGか?
        if ($msg->command eq 'PRIVMSG') {
            my $msg_prefix = substr($msg->param(1), 0, length($this->config->prefix));
            my $msg_body = substr($msg->param(1), length($this->config->prefix));
            if ($msg_prefix eq $this->config->prefix) {
                my $twit = Net::Twitter->new(username => $this->config->username, password => $this->conf\
ig->password);
                $twit->update($msg_body);
            }
        }
    }

    return @result;
}

1;

=pod
info: Twitterを自動で更新
default: off

prefix: :=
username: foo@example.com
password: ********
=cut

見よう見まねです。Userに入れるべきかどうかも怪しいですが、あんまり細かいこと気にしない方が良いです。

:=咳をしても一人

みたいに、configのprefixから始まる発言をするとTwitterに代入(違)されます。

prefixの比較方法がスマートじゃないですが、Perlとかよく知らないので勘弁してください。