Plagger::Plugin::CustomFeed::ChatBotUsi
Feedを作るプラグインです。
誰かテストしてください(ぉ
package Plagger::Plugin::CustomFeed::ChatBotUsi; use strict; use base qw( Plagger::Plugin ); use Encode; use URI; use XMLRPC::Lite; $XML::Feed::RSS::PREFERRED_PARSER = 'XML::RSS::LibXML'; our $XML_RPC_URL = 'http://usikun.dip.jp/rpc'; sub register { my($self, $context) = @_; $context->register_hook( $self, 'subscription.load' => \&load, ); } sub load { my($self, $context) = @_; my @contnts[2]; # 0:title, 1:body $context->log(info => "Creating ChatBot Usi Feed start."); my $rpc = XMLRPC::Lite->new; $rpc->proxy($XML_RPC_URL); for (my $idx=0; $idx<@contnts; $idx++) { my $res = $rpc->call('ChatBot.talk', XMLRPC::Data->type('string', $self->conf->{apikey}), XMLRPC::Data->type('string', $self->conf->{name}), XMLRPC::Data->type('string', $self->conf->{friend}), XMLRPC::Data->type('string', $contnts[0]), ); if (my $fault = $res->fault){ for (keys %{$fault}){ $context->log(warn => "ChatBot Usi API talk failed : $_ => " . $fault->{$_}); } return; } else { $contnts[$idx] = $res->result->{'message'}; $contnts[$idx] =~ s/</</ig;</ppp> $contnts[$idx] =~ s/>/>/ig; $contnts[$idx] =~ s/"/"/ig; } } my $feed = Plagger::Feed->new; $feed->type('chatbotusi'); $feed->title('うし@人工無脳'); $feed->link('http://usikun.dip.jp/'); { my $itemtitle = $contnts[0]; my $itemurl = 'http://usikun.dip.jp/'; my $dcdate = Plagger::Date->now; my $desc = $contnts[1]; my $entry = Plagger::Entry->new; $entry->title($itemtitle); $entry->link($itemurl); $entry->date($dcdate); $entry->body($desc); $feed->add_entry($entry); } $context->update->add($feed); $context->log(info => "Creating ChatBot Usi Feed end."); } 1; __END__ =head1 NAME Plagger::Plugin::CustomFeed::ChatBotUsi - Custom feed by ChatBot Usikun API Talk =head1 SYNOPSIS - module: CustomFeed::ChatBotUsi config: apikey: XXXXXXXXXXXXXXXXXX name: your name friend: your friend name =head1 DESCRIPTION XXX Write the description for CustomFeed::ChatBotUsi =head1 CONFIG XXX Document configuration variables if any. =head1 AUTHOR UnderDone =cut