root/trunk/plagger/lib/Plagger/Plugin/Notify/IRC.pm

Revision 216 (checked in by miyagawa, 15 years ago)

rename some of Publish modules to Notify, to be clear

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Notify::IRC;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Encode;
6 use POE::Component::IKC::ClientLite;
7
8 sub register {
9     my($self, $context) = @_;
10     $context->register_hook(
11         $self,
12         'publish.feed' => \&update,
13     );
14 }
15
16 sub update {
17     my($self, $context, $args) = @_;
18
19     my $remote = POE::Component::IKC::ClientLite::create_ikc_client(
20         port    => $self->conf->{daemon_port} || 9999,
21         ip      => $self->conf->{daemon_host} || 'localhost',
22         name    => "Plagger$$",
23         timeout => 5,
24     );
25
26     unless ($remote) {
27         $context->log(error => $POE::Component::IKC::ClientLite::error);
28         return;
29     }
30
31     $context->log(info => "Notifying " . $args->{feed}->title . " to IRC");
32
33     my $body = $self->templatize($context, $args->{feed});
34     Encode::_utf8_off($body) if Encode::is_utf8($body);
35     Encode::from_to($body, 'utf-8', $self->conf->{charset})
36         if $self->conf->{charset} && $self->conf->{charset} ne 'utf-8';
37     for my $line (split("\n", $body)) {
38         $remote->post( 'notify_irc/update', $line );
39     }
40 }
41
42 sub templatize {
43     my($self, $context, $feed) = @_;
44     my $tt = $context->template();
45     $tt->process('irc_notify.tt', {
46         feed => $feed,
47     }, \my $out) or $context->error($tt->error);
48     $out;
49 }
50
51 1;
52
53 __END__
54
55 =head1 NAME
56
57 Plagger::Plugin::Notify::IRC - Notify feed updates to IRC
58
59 =head1 SYNOPSIS
60
61   - module: Notify::IRC
62     config:
63       daemon_port: 9999
64       nickname: plaggerbot
65       server_host: chat.freenode.net
66       server_port: 6667
67       server_channels:
68         - #plagger-test
69       charset: iso-2022-jp
70       announce: notice
71
72 =head1 DESCRIPTION
73
74 This plugin allows you to notify feed updates to IRC channels using
75 POE based IRC client. This module uses IKC inter-kernal protocol to
76 communicate with POE daemon.
77
78 =head1 AUTHOR
79
80 Masayoshi Sekimura, Tatsuhiko Miyagawa
81
82 This module and C<plagger-ircbot.pl> code is based on Ian Langworth's
83 Kwiki::Notify::IRC module.
84
85 =head1 SEE ALSO
86
87 L<Plagger>, L<Kwiki::Notify::IRC>, L<POE::Component::IRC>
88
89 =cut
90
Note: See TracBrowser for help on using the browser.