| 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.entry' => \&update, |
|---|
| 13 |
'plugin.init' => \&initialize, |
|---|
| 14 |
); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
sub initialize { |
|---|
| 18 |
my($self, $context, $args) = @_; |
|---|
| 19 |
|
|---|
| 20 |
my $host = $self->conf->{daemon_host} || 'localhost', |
|---|
| 21 |
my $port = $self->conf->{daemon_port} || 9999; |
|---|
| 22 |
|
|---|
| 23 |
$self->{remote} = POE::Component::IKC::ClientLite::create_ikc_client( |
|---|
| 24 |
port => $port, |
|---|
| 25 |
ip => $host, |
|---|
| 26 |
name => 'Plagger' . $$, |
|---|
| 27 |
timeout => 5, |
|---|
| 28 |
); |
|---|
| 29 |
|
|---|
| 30 |
unless ($self->{remote}) { |
|---|
| 31 |
my $msg = q{unable to connect to plagger-ircbot process on } |
|---|
| 32 |
. "$host:$port" |
|---|
| 33 |
. q{, if you're not running plagger-ircbot, you should be able } |
|---|
| 34 |
. q{to start it with the same Notify::IRC config you passed to } |
|---|
| 35 |
. q{plagger. }; |
|---|
| 36 |
$context->log( error => $msg ); |
|---|
| 37 |
return; |
|---|
| 38 |
} |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
sub update { |
|---|
| 42 |
my($self, $context, $args) = @_; |
|---|
| 43 |
|
|---|
| 44 |
$context->log(info => "Notifying " . $args->{entry}->title . " to IRC"); |
|---|
| 45 |
|
|---|
| 46 |
my $body = $self->templatize('irc_notify.tt', $args); |
|---|
| 47 |
Encode::_utf8_off($body) if Encode::is_utf8($body); |
|---|
| 48 |
Encode::from_to($body, 'utf-8', $self->conf->{charset}) |
|---|
| 49 |
if $self->conf->{charset} && $self->conf->{charset} ne 'utf-8'; |
|---|
| 50 |
for my $line (split("\n", $body)) { |
|---|
| 51 |
$self->{remote}->post( 'notify_irc/update', $line ); |
|---|
| 52 |
} |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
1; |
|---|
| 56 |
|
|---|
| 57 |
__END__ |
|---|
| 58 |
|
|---|
| 59 |
=head1 NAME |
|---|
| 60 |
|
|---|
| 61 |
Plagger::Plugin::Notify::IRC - Notify feed updates to IRC |
|---|
| 62 |
|
|---|
| 63 |
=head1 SYNOPSIS |
|---|
| 64 |
|
|---|
| 65 |
- module: Notify::IRC |
|---|
| 66 |
config: |
|---|
| 67 |
daemon_port: 9999 |
|---|
| 68 |
nickname: plaggerbot |
|---|
| 69 |
server_host: chat.freenode.net |
|---|
| 70 |
server_port: 6667 |
|---|
| 71 |
server_channels: |
|---|
| 72 |
- #plagger-test |
|---|
| 73 |
charset: utf-8 |
|---|
| 74 |
announce: notice |
|---|
| 75 |
|
|---|
| 76 |
=head1 DESCRIPTION |
|---|
| 77 |
|
|---|
| 78 |
This plugin allows you to notify feed updates to IRC channels using |
|---|
| 79 |
POE based IRC client. This module uses IKC inter-kernel protocol to |
|---|
| 80 |
communicate with POE daemon. |
|---|
| 81 |
|
|---|
| 82 |
=head1 SETUP |
|---|
| 83 |
|
|---|
| 84 |
In order to make Notify::IRC run, you need to run I<plagger-ircbot> |
|---|
| 85 |
script first, before running the plagger main process. |
|---|
| 86 |
|
|---|
| 87 |
% ./bin/plagger-ircbot -c irc.yaml & |
|---|
| 88 |
|
|---|
| 89 |
I<plagger-ircbot> is a POE process that persistently connects to an |
|---|
| 90 |
IRC server, and this plugin uses POE IKC to talk to the bot process. |
|---|
| 91 |
|
|---|
| 92 |
=head1 AUTHOR |
|---|
| 93 |
|
|---|
| 94 |
Masayoshi Sekimura, Tatsuhiko Miyagawa |
|---|
| 95 |
|
|---|
| 96 |
This module and C<plagger-ircbot.pl> code is based on Ian Langworth's |
|---|
| 97 |
Kwiki::Notify::IRC module. |
|---|
| 98 |
|
|---|
| 99 |
=head1 SEE ALSO |
|---|
| 100 |
|
|---|
| 101 |
L<Plagger>, L<Kwiki::Notify::IRC>, L<POE::Component::IRC> |
|---|
| 102 |
|
|---|
| 103 |
=cut |
|---|
| 104 |
|
|---|