February 27, 2006

Plagger::Plugin::Publish::MSAgent

plagger-msagent.gif

MSAgent.pm。ほぼ Publish::Speech::Win32 のコピペ。こんどは Microsoft Agent でアニメーションとかもさせてます。キモは、

sub feed {
    my($self, $context, $args) = @_;

    my $character = $self->conf->{character} || 'Merlin';
    my $agent = Win32::MSAgent->new($character);

    my $char = $agent->Characters($character);
    $char->SoundEffectsOn(1);
    $char->Show();

    $char->MoveTo(300,300);
    sleep(5);

    if (my $animation = $self->conf->{animation}) {
        $char->Play($animation);
    }
    ...
    $self->speak( $char, encode($encoding, $args->{feed}->title_text) );

    for my $entry ($args->{feed}->entries) {
        my $stuff = $entry->title_text . $entry->body_text;
        for my $message (split /\n/, $stuff) {
            $self->speak( $char, encode($encoding, $message) );
        }
    }
}

sub speak {
    my($self, $character, $message) = @_;
    my $request = $character->Speak($message);

    my $i = 0;
    while (($request->Status == 2) || ($request->Status == 4)) {
        $character->Stop($request) if $i >10; sleep(1);  $i++;
    }
}

アニメーションは config で指定しますが、フィードの内容によってインテリジェントに振舞えるとカッコイイなあ。というわけで、SNMP の通知など、アラートでなごみたい方はどうぞ。

Posted by miyagawa at February 27, 2006 10:56 AM | Permalink | Comments (0) | TrackBack(0)
Comments
Trackbacks
TrackBack URL for this entry: http://blog.bulknews.net/mt3/mt-tb.cgi/1908
Post a comment