| 1 |
package Plagger::Plugin::Notify::Tiarra; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use Encode; |
|---|
| 6 |
use IO::Socket::UNIX; |
|---|
| 7 |
use Time::HiRes; |
|---|
| 8 |
|
|---|
| 9 |
sub register { |
|---|
| 10 |
my($self, $context) = @_; |
|---|
| 11 |
$context->register_hook( |
|---|
| 12 |
$self, |
|---|
| 13 |
'publish.feed' => \&update, |
|---|
| 14 |
); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
sub update { |
|---|
| 18 |
my($self, $context, $args) = @_; |
|---|
| 19 |
|
|---|
| 20 |
$context->log(info => "Notifying " . $args->{feed}->title . " to IRC"); |
|---|
| 21 |
|
|---|
| 22 |
my $protocol = 'TIARRACONTROL/1.0'; |
|---|
| 23 |
|
|---|
| 24 |
my $request_template = <<END; |
|---|
| 25 |
NOTIFY System::SendMessage [% protocol %]\r |
|---|
| 26 |
Sender: [% sender %]\r |
|---|
| 27 |
Notice: [% use_notice %]\r |
|---|
| 28 |
Channel: [% channel %]\r |
|---|
| 29 |
Charset: [% charset %]\r |
|---|
| 30 |
Text: [% text %]\r |
|---|
| 31 |
\r |
|---|
| 32 |
END |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
my $charset = $self->conf->{charset} || 'UTF-8'; |
|---|
| 37 |
|
|---|
| 38 |
my $body = $self->templatize('irc_notify.tt', $args); |
|---|
| 39 |
|
|---|
| 40 |
for my $line (split("\n", $body)) { |
|---|
| 41 |
my $remote = IO::Socket::UNIX->new( |
|---|
| 42 |
Type => SOCK_STREAM, |
|---|
| 43 |
Peer => '/tmp/tiarra-control/' . $self->conf->{socketname}, |
|---|
| 44 |
); |
|---|
| 45 |
|
|---|
| 46 |
unless ($remote) { |
|---|
| 47 |
$context->log(error => "cannot open sock: $!"); |
|---|
| 48 |
return; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
my $out = $self->templatize(\$request_template, { |
|---|
| 52 |
protocol => $protocol, |
|---|
| 53 |
charset => $charset, |
|---|
| 54 |
channel => $self->conf->{channel}, |
|---|
| 55 |
sender => $self->conf->{sender} || "Plagger/$Plagger::VERSION (http://plagger.bulknews.net/)", |
|---|
| 56 |
use_notice => ($self->conf->{use_notice} ? 'yes' : 'no'), |
|---|
| 57 |
text => $line, |
|---|
| 58 |
}); |
|---|
| 59 |
Encode::_utf8_off($out) if Encode::is_utf8($out); |
|---|
| 60 |
Encode::from_to($out, 'utf-8', $charset) unless uc($charset) eq 'UTF-8'; |
|---|
| 61 |
$remote->print($out); |
|---|
| 62 |
|
|---|
| 63 |
my $resp = <$remote>; |
|---|
| 64 |
if ($resp !~ /$protocol 200 OK/) { |
|---|
| 65 |
$context->log(error => $resp); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
$remote->close; |
|---|
| 69 |
Time::HiRes::sleep( $self->conf->{send_interval} || 2 ); |
|---|
| 70 |
} |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
1; |
|---|
| 74 |
|
|---|
| 75 |
__END__ |
|---|
| 76 |
|
|---|
| 77 |
=head1 NAME |
|---|
| 78 |
|
|---|
| 79 |
Plagger::Plugin::Notify::Tiarra - Notify feed updates to Tiarra IRC Proxy |
|---|
| 80 |
|
|---|
| 81 |
=head1 SYNOPSIS |
|---|
| 82 |
|
|---|
| 83 |
- module: Notify::Tiarra |
|---|
| 84 |
config: |
|---|
| 85 |
socketname: foobar |
|---|
| 86 |
channel: #plagger-test |
|---|
| 87 |
use_notice: 1 |
|---|
| 88 |
|
|---|
| 89 |
=head1 DESCRIPTION |
|---|
| 90 |
|
|---|
| 91 |
This plugin allows you to notify feed updates to IRC channels using |
|---|
| 92 |
Tiarra IRC Proxy. This module uses Tiarra ControlPort feature and |
|---|
| 93 |
System::SendMessage module to send notify. |
|---|
| 94 |
|
|---|
| 95 |
=head1 AUTHOR |
|---|
| 96 |
|
|---|
| 97 |
Tatsuya Noda |
|---|
| 98 |
|
|---|
| 99 |
This module is based on Plagger::Plugin::Notify::IRC. |
|---|
| 100 |
|
|---|
| 101 |
=head1 SEE ALSO |
|---|
| 102 |
|
|---|
| 103 |
L<Plagger>, L<Plagger::Plugin::Notify::IRC> |
|---|
| 104 |
|
|---|
| 105 |
=cut |
|---|
| 106 |
|
|---|