1 # WeeChat plugin 2 # http://www.0x11.net/notify-remote/remote-notification.pl 3 # 4 use Parse::IRC; 5 6 sub escape 7 { 8 # escaping of ' " ; < > etc must be done on the remote host 9 # they can't trust us anyways. 10 my $a = shift; 11 $a =~ s/\\/\\/mg; 12 $a =~ s/\n/\\n/mg; 13 return $a; 14 } 15 16 sub marshall 17 { 18 my ($app, $summary, $message) = @_; 19 20 print STDERR "\033[5i"; 21 22 my $buffer = "CATEGORY IRC\n"; 23 $buffer .= "SUBJECT ".escape($summary)."\n"; 24 $buffer .= "CONTENT ".escape($message)."\n"; 25 print STDERR $buffer; 26 27 print STDERR "\033[4i"; 28 } 29 30 my $app = 'Weechat (Curses)'; 31 my @messages = ( 32 [ nick => 'Changed Nick', '$nick has changed nick to $text' ], 33 [ join => 'Joined Room', '$nick has joined $text' ], 34 [ part => 'Left Room', '$nick has left $channel ($text)' ], 35 [ quit => 'Quit', '$nick has quit ($text)' ], 36 [ topic => 'Set Topic', '$nick sets topic in $channel to \'$text\'' ], 37 [ weechat_highlight => 'Highlight Mentioned in $channel', '$text' ], 38 [ weechat_pv => 'Private Message', '$nick: $text' ], 39 ); 40 my $notes; 41 push @$notes, $_->[1] foreach @messages; 42 43 my $version = '0.1'; 44 weechat::register 'remote-notification', $version, '', 45 'Send Weechat notifications to a remote host'; 46 47 for my $message (@messages){ 48 no strict 'refs'; # access symbol table 49 my $subname = join '', __PACKAGE__, '::handler_', $message->[0]; 50 *{$subname} = sub 51 { 52 my($ircmsg) = parse_irc $_[1]; 53 my($nick, undef) = split /!/, $ircmsg->{prefix}; 54 my($channel, $text); 55 $channel = shift @{$ircmsg->{params}} 56 if $message->[0] =~ /(part|pv|highlight|topic)/; 57 $text = shift @{$ircmsg->{params}}; 58 $text = escape($text); 59 60 # ignore nickchanges, joins, parts, quits 61 return if ($message->[0] =~ /^(nick|join|part|quit)$/); 62 63 marshall($app, eval qq("$message->[1]"), eval qq("$message->[2]"), 64 ($message->[0] =~ /(pv|highlight)/ ? 1 : 0)); 65 66 return weechat::PLUGIN_RC_OK; 67 }; 68 weechat::add_message_handler $message->[0], $subname; 69 } 70 71 __END__ 72 73 =head1 NAME 74 75 remote-notification.pl - Send Weechat notifications to a remote host 76 77 =head1 SYNOPSIS 78 79 # in Weechat console, do 80 /perl load /path/to/notify.pl 81 82 # or put script in .weechat/perl/autoload/ 83 84 =head1 DESCRIPTION 85 86 remote-notification.pl is a script plugin for Weechat that notifies on common IRC 87 messages (such as joins, highlights, and private messages) on a *remote* host. 88 89 It marshalls the notification in a escaped output to stderr which is 90 unmarshalled by the terminal application run on the remote host. 91 92 By adding the the printer escape codes (ESC[5i (turn printer on) and ESC[4i (turn printer off) 93 it is possible for terminal to interpret the output by its own script which 94 then can initiate notify-send or something similar. 95 The idea is based on L<http://jaredquinn.info/it-related/technical/unix/2007.09.25/libnotify-with-irssi-over-ssh/>. 96 97 This script itself is based on the growl-notify script plugin. 98 99 =head1 SEE ALSO 100 101 L<http://jaredquinn.info/it-related/technical/unix/2007.09.25/libnotify-with-irssi-over-ssh/> 102 103 =head1 AUTHORS 104 105 Benedikt Waldvogel, C<< bene at 0x11.net >> 106 Zak B. Elep, C<< zakame at spunge.org >> 107 108 =head1 COPYRIGHT AND LICENSE 109 110 Permission is hereby granted, free of charge, to any person obtaining a copy 111 of this software and associated documentation files (the "Software"), to deal 112 in the Software without restriction, including without limitation the rights 113 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 114 copies of the Software, and to permit persons to whom the Software is 115 furnished to do so, subject to the following conditions: 116 117 The above copyright notice and this permission notice shall be included in 118 all copies or substantial portions of the Software. 119 120 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 121 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 122 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 123 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 124 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 125 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 126 THE SOFTWARE. 127 128 =cut 129