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