# WeeChat plugin
# http://www.0x11.net/notify-remote/remote-notification.pl
#
use Parse::IRC;
sub escape
{
# escaping of ' " ; < > etc must be done on the remote host
# they can't trust us anyways.
my $a = shift;
$a =~ s/\\/\\/mg;
$a =~ s/\n/\\n/mg;
return $a;
}
sub marshall
{
my ($app, $summary, $message) = @_;
print STDERR "\033[5i";
my $buffer = "CATEGORY IRC\n";
$buffer .= "SUBJECT ".escape($summary)."\n";
$buffer .= "CONTENT ".escape($message)."\n";
print STDERR $buffer;
print STDERR "\033[4i";
}
my $app = 'Weechat (Curses)';
my @messages = (
[ nick => 'Changed Nick', '$nick has changed nick to $text' ],
[ join => 'Joined Room', '$nick has joined $text' ],
[ part => 'Left Room', '$nick has left $channel ($text)' ],
[ quit => 'Quit', '$nick has quit ($text)' ],
[ topic => 'Set Topic', '$nick sets topic in $channel to \'$text\'' ],
[ weechat_highlight => 'Highlight Mentioned in $channel', '$text' ],
[ weechat_pv => 'Private Message', '$nick: $text' ],
);
my $notes;
push @$notes, $_->[1] foreach @messages;
my $version = '0.1';
weechat::register 'remote-notification', $version, '',
'Send Weechat notifications to a remote host';
for my $message (@messages){
no strict 'refs'; # access symbol table
my $subname = join '', __PACKAGE__, '::handler_', $message->[0];
*{$subname} = sub
{
my($ircmsg) = parse_irc $_[1];
my($nick, undef) = split /!/, $ircmsg->{prefix};
my($channel, $text);
$channel = shift @{$ircmsg->{params}}
if $message->[0] =~ /(part|pv|highlight|topic)/;
$text = shift @{$ircmsg->{params}};
$text = escape($text);
# ignore nickchanges, joins, parts, quits
return if ($message->[0] =~ /^(nick|join|part|quit)$/);
marshall($app, eval qq("$message->[1]"), eval qq("$message->[2]"),
($message->[0] =~ /(pv|highlight)/ ? 1 : 0));
return weechat::PLUGIN_RC_OK;
};
weechat::add_message_handler $message->[0], $subname;
}
__END__
=head1 NAME
remote-notification.pl - Send Weechat notifications to a remote host
=head1 SYNOPSIS
# in Weechat console, do
/perl load /path/to/notify.pl
# or put script in .weechat/perl/autoload/
=head1 DESCRIPTION
remote-notification.pl is a script plugin for Weechat that notifies on common IRC
messages (such as joins, highlights, and private messages) on a *remote* host.
It marshalls the notification in a escaped output to stderr which is
unmarshalled by the terminal application run on the remote host.
By adding the the printer escape codes (ESC[5i (turn printer on) and ESC[4i (turn printer off)
it is possible for terminal to interpret the output by its own script which
then can initiate notify-send or something similar.
The idea is based on L.
This script itself is based on the growl-notify script plugin.
=head1 SEE ALSO
L
=head1 AUTHORS
Benedikt Waldvogel, C<< bene at 0x11.net >>
Zak B. Elep, C<< zakame at spunge.org >>
=head1 COPYRIGHT AND LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=cut