| 1 |
package Plagger::Plugin::Notify::Colloquy; |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
use base qw( Plagger::Plugin ); |
|---|
| 5 |
use Data::Dumper; |
|---|
| 6 |
use Encode; |
|---|
| 7 |
|
|---|
| 8 |
sub register { |
|---|
| 9 |
my ( $self, $context ) = @_; |
|---|
| 10 |
$context->register_hook( $self, 'publish.entry' => \&update, ); |
|---|
| 11 |
} |
|---|
| 12 |
|
|---|
| 13 |
sub update { |
|---|
| 14 |
my ( $self, $context, $args ) = @_; |
|---|
| 15 |
|
|---|
| 16 |
$context->log( |
|---|
| 17 |
info => "Notifying " . $args->{entry}->title . " to Colloquy" ); |
|---|
| 18 |
|
|---|
| 19 |
for my $entry ( $args->{feed}->entries ) { |
|---|
| 20 |
my ( $header_line, $body_line ) = $self->colloquy_templatize($entry); |
|---|
| 21 |
|
|---|
| 22 |
Encode::_utf8_off($header_line) if Encode::is_utf8($header_line); |
|---|
| 23 |
Encode::from_to( $header_line, 'utf-8', $self->conf->{charset} ) |
|---|
| 24 |
if $self->conf->{charset} && $self->conf->{charset} ne 'utf-8'; |
|---|
| 25 |
|
|---|
| 26 |
foreach my $chan ( @{$self->conf->{channels}} ) { |
|---|
| 27 |
system( 'osascript', 'bin/colloquy_tell.scpt', $header_line, |
|---|
| 28 |
$body_line, $chan ) == 0 |
|---|
| 29 |
or Plagger->context->error("$!"); |
|---|
| 30 |
sleep(1); |
|---|
| 31 |
} |
|---|
| 32 |
} |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
sub colloquy_templatize { |
|---|
| 36 |
my ( $self, $entry ) = @_; |
|---|
| 37 |
my ( $header_line, $body_line ); |
|---|
| 38 |
if ( $entry->title ) { |
|---|
| 39 |
$header_line = $entry->title_text . ": "; |
|---|
| 40 |
} |
|---|
| 41 |
if ( $entry->author ) { |
|---|
| 42 |
$header_line .= "(" . $entry->author . ")"; |
|---|
| 43 |
} |
|---|
| 44 |
$body_line = $entry->permalink; |
|---|
| 45 |
return ( $header_line, $body_line ); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
1; |
|---|
| 49 |
|
|---|
| 50 |
__END__ |
|---|
| 51 |
|
|---|
| 52 |
=head1 NAME |
|---|
| 53 |
|
|---|
| 54 |
Plagger::Plugin::Notify::Colloquy - Notify feed updates to IRC via Colloquy |
|---|
| 55 |
|
|---|
| 56 |
=head1 SYNOPSIS |
|---|
| 57 |
|
|---|
| 58 |
- module: Notify::Colloquy |
|---|
| 59 |
config: |
|---|
| 60 |
channels: |
|---|
| 61 |
- #tirnanog |
|---|
| 62 |
- #plagger |
|---|
| 63 |
charset: iso-8859-1 |
|---|
| 64 |
|
|---|
| 65 |
=head1 DESCRIPTION |
|---|
| 66 |
|
|---|
| 67 |
This plugin allows you to notify feed updates to an IRC channel using |
|---|
| 68 |
the Colloquy client. |
|---|
| 69 |
|
|---|
| 70 |
=head1 AUTHOR |
|---|
| 71 |
|
|---|
| 72 |
Franck Cuny |
|---|
| 73 |
|
|---|
| 74 |
=head1 SEE ALSO |
|---|
| 75 |
|
|---|
| 76 |
L<Plagger> |
|---|
| 77 |
|
|---|
| 78 |
=cut |
|---|