Notify::YahooMessenger

を書いてみたけど既にあった。やっぱしorz


でももったいないから貼り付けてみる。

package Plagger::Plugin::Notify::YahooMessenger;
use strict;
use base qw( Plagger::Plugin );

use Net::YahooMessenger;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'plugin.init'  => \&initialize,
        'publish.feed' => \&notify,
    );
}

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

    for (qw/id password recipient_id/) {
        $self->conf->{$_} or $context->error("$_ is required");
    }
        
    $self->conf->{pre_login_url} ||= 'http://edit.my.yahoo.co.jp/config/';
    $self->conf->{hostname}      ||= 'cs.yahoo.co.jp';
    $self->conf->{charset}       ||= 'sjis';

    $self->{ym} = Net::YahooMessenger->new( %{$self->conf} );
    $self->{ym}->login or $context->error("Couldn't login Yahoo Messenger");

    $context->log(debug => 'Login success');
}

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

    $context->log(
        info => "Notifying "
                . $args->{feed}->title
                . " to Yahoo Messenger"
    );

    my $body = $self->templatize('ym_notify.tt', $args);

    Encode::_utf8_off($body) if Encode::is_utf8($body);
    Encode::from_to($body, 'utf-8', $self->conf->{charset})
        if $self->conf->{charset} ne 'utf-8';

    for my $line (split("\n", $body)) {
        $self->{ym}->send($self->conf->{recipient_id}, $line);
        sleep 1;
    }
}

1;

config.yaml

  - module: Notify::YahooMessenger
    config: 
      id:            Yahoo ID
      password:      パスワード
      recipient_id:  送信先のYahoo ID
      #pre_login_url: http://edit.my.yahoo.co.jp/config/
      #hostname:      cs.yahoo.co.jp
      #charset:       sjis

ほぼNotify::IRCのコピペ。
assetも使いまわし。


plugin.initでログインしてるので、
フィードの新着があろうとなかろうと
メッセンジャーが「オンラインになりました」と反応してしまうのがなんとも・・・