From c43f8b1beec5859277cc37e072e1b62ef726e98f Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 06:35:33 +0100 Subject: added notifyquit.pl, stolen (um, borrowed) from vague@#irssi and made moar better. --- quit-notify/notifyquit.pl | 169 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 quit-notify/notifyquit.pl (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl new file mode 100644 index 0000000..0a9132a --- /dev/null +++ b/quit-notify/notifyquit.pl @@ -0,0 +1,169 @@ +### +# +# Parts of the script pertaining to uberprompt borrowed from +# shabble (shabble!#irssi/@Freenode), thanks for letting me steal from you :P +# +### + +use strict; +use warnings; + +our $VERSION = "0.2"; +our %IRSSI = ( + authors => "Jari Matilainen", + contact => 'vague!#irssi@freenode', + name => "notifyquit", + description => "Notify if user has left the channel", + license => "Public Domain", + url => "http://vague.se" + ); + +my $active = 0; +my $permit_pending = 0; +my $pending_input = {}; + + +sub script_is_loaded { + return exists($Irssi::Script::{shift . '::'}) ; +} + +if (not script_is_loaded('uberprompt')) { + + print "This script requires 'uberprompt.pl' in order to work. " + . "Attempting to load it now..."; + + Irssi::signal_add('script error', 'load_uberprompt_failed'); + Irssi::command("script load uberprompt.pl"); + + unless(script_is_loaded('uberprompt')) { + load_uberprompt_failed("File does not exist"); + } + app_init(); +} else { + app_init(); +} + +sub load_uberprompt_failed { + Irssi::signal_remove('script error', 'load_prompt_failed'); + + print "Script could not be loaded. Script cannot continue. " + . "Check you have uberprompt.pl installed in your scripts directory and " + . "try again. Otherwise, it can be fetched from: "; + print "https://github.com/shabble/irssi-scripts/raw/master/" + . "prompt_info/uberprompt.pl"; + + die "Script Load Failed: " . join(" ", @_); +} + +sub extract_nick { + my ($str) = @_; + + my $completion_char + = quotemeta(Irssi::settings_get_str("completion_char")); + + # from BNF grammar at http://www.irchelp.org/irchelp/rfc/chapter2.html + # special := '-' | '[' | ']' | '\' | '`' | '^' | '{' | '}' + + my $pattern = qr/^( [[:alpha:]] # starts with a letter + (?: [[:alpha:]] # then letter + | \d # or number + | [\[\]\\`^\{\}-]) # or special char + *? ) # any number of times + $completion_char/x; # followed by completion char. + + if ($str =~ m/$pattern/) { + print "Matched: $1"; + return $1; + } else { + return undef; + } + +} + +sub sig_send_text { + my ($data, $server, $witem) = @_; + + return unless($witem); + + return unless $witem->{type} eq 'CHANNEL'; + + # shouldn't need escaping, but it doesn't hurt to be paranoid. + my $target_nick = extract_nick($data); + + if ($target_nick) { + if (not $witem->nick_find($target_nick)) { + + return if $target_nick =~ m/^https?/i + + if ($permit_pending) { + + $pending_input = {}; + $permit_pending = 0; + Irssi::signal_continue(@_); + + } else { + my $text + = "$target_nick isn't in this channel, send anyway? [Y/n]"; + $pending_input + = { + text => $data, + server => $server, + win_item => $witem, + }; + + Irssi::signal_stop; + require_confirmation($text) + } + } + } +} + +sub sig_gui_keypress { + my ($key) = @_; + + return if not $active; + + my $char = chr($key); + + # Enter, y, or Y. + if ($char =~ m/^y?$/i) { + $permit_pending = 1; + Irssi::signal_stop; + Irssi::signal_emit('send text', + $pending_input->{text}, + $pending_input->{server}, + $pending_input->{win_item}); + $active = 0; + set_prompt(''); + + } elsif ($char =~ m/^n?$/i or $key == 3 or $key == 7) { + # we support n, N, Ctrl-C, and Ctrl-G for no. + + Irssi::signal_stop; + set_prompt(''); + + $permit_pending = 0; + $active = 0; + $pending_input = {}; + + } else { + Irssi::signal_stop; + return; + } +} + +sub app_init { + Irssi::signal_add_first("send text" => \&sig_send_text); + Irssi::signal_add_first('gui key pressed' => \&sig_gui_keypress); +} + +sub require_confirmation { + $active = 1; + set_prompt(shift); +} + +sub set_prompt { + my $msg = shift; + $msg = ': ' . $msg if length $msg; + Irssi::signal_emit('change prompt', $msg, 'UP_INNER'); +} -- cgit v1.2.3 From 53e5b8a29f33714f0e9ff0fbdbb22e81efdb8481 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 06:50:03 +0100 Subject: notifyquit: fix stupid syntax error in regex. --- quit-notify/notifyquit.pl | 62 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index 0a9132a..606e08a 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -10,13 +10,13 @@ use warnings; our $VERSION = "0.2"; our %IRSSI = ( - authors => "Jari Matilainen", - contact => 'vague!#irssi@freenode', - name => "notifyquit", - description => "Notify if user has left the channel", - license => "Public Domain", - url => "http://vague.se" - ); + authors => "Jari Matilainen", + contact => 'vague!#irssi@freenode', + name => "notifyquit", + description => "Notify if user has left the channel", + license => "Public Domain", + url => "http://vague.se" + ); my $active = 0; my $permit_pending = 0; @@ -24,7 +24,7 @@ my $pending_input = {}; sub script_is_loaded { - return exists($Irssi::Script::{shift . '::'}) ; + return exists($Irssi::Script::{shift . '::'}); } if (not script_is_loaded('uberprompt')) { @@ -65,11 +65,11 @@ sub extract_nick { # special := '-' | '[' | ']' | '\' | '`' | '^' | '{' | '}' my $pattern = qr/^( [[:alpha:]] # starts with a letter - (?: [[:alpha:]] # then letter - | \d # or number - | [\[\]\\`^\{\}-]) # or special char - *? ) # any number of times - $completion_char/x; # followed by completion char. + (?: [[:alpha:]] # then letter + | \d # or number + | [\[\]\\`^\{\}-]) # or special char + *? ) # any number of times + $completion_char/x; # followed by completion char. if ($str =~ m/$pattern/) { print "Matched: $1"; @@ -93,27 +93,27 @@ sub sig_send_text { if ($target_nick) { if (not $witem->nick_find($target_nick)) { - return if $target_nick =~ m/^https?/i + return if $target_nick =~ m/^https?/i; - if ($permit_pending) { + if ($permit_pending) { - $pending_input = {}; - $permit_pending = 0; - Irssi::signal_continue(@_); + $pending_input = {}; + $permit_pending = 0; + Irssi::signal_continue(@_); - } else { - my $text - = "$target_nick isn't in this channel, send anyway? [Y/n]"; - $pending_input - = { - text => $data, - server => $server, - win_item => $witem, - }; + } else { + my $text + = "$target_nick isn't in this channel, send anyway? [Y/n]"; + $pending_input + = { + text => $data, + server => $server, + win_item => $witem, + }; - Irssi::signal_stop; - require_confirmation($text) - } + Irssi::signal_stop; + require_confirmation($text) + } } } } @@ -163,7 +163,7 @@ sub require_confirmation { } sub set_prompt { - my $msg = shift; + my ($msg) = @_; $msg = ': ' . $msg if length $msg; Irssi::signal_emit('change prompt', $msg, 'UP_INNER'); } -- cgit v1.2.3 From 8fed96c49f7831240b207480694ea498275724d5 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 07:18:23 +0100 Subject: notifyquit: flippy-floppy some logic for clarity. --- quit-notify/notifyquit.pl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index 606e08a..07a6066 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -27,8 +27,9 @@ sub script_is_loaded { return exists($Irssi::Script::{shift . '::'}); } -if (not script_is_loaded('uberprompt')) { - +if (script_is_loaded('uberprompt')) { + app_init(); +} else { print "This script requires 'uberprompt.pl' in order to work. " . "Attempting to load it now..."; @@ -39,8 +40,6 @@ if (not script_is_loaded('uberprompt')) { load_uberprompt_failed("File does not exist"); } app_init(); -} else { - app_init(); } sub load_uberprompt_failed { -- cgit v1.2.3 From 9b4f3c204419e20bcb470b8aa04a6ffb4e35fdfb Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 07:26:42 +0100 Subject: Bah. more fixing of script_is_loaded. --- quit-notify/notifyquit.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index 07a6066..bcccf87 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -24,7 +24,7 @@ my $pending_input = {}; sub script_is_loaded { - return exists($Irssi::Script::{shift . '::'}); + return exists($Irssi::Script::{$_[0] . '::'}); } if (script_is_loaded('uberprompt')) { -- cgit v1.2.3 From 74090c6816f373a870522559a01c64a89d00958c Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 1 Apr 2011 07:40:17 +0100 Subject: notifyquit: kill the debug print that sneaked past. --- quit-notify/notifyquit.pl | 1 - 1 file changed, 1 deletion(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index bcccf87..501ce88 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -71,7 +71,6 @@ sub extract_nick { $completion_char/x; # followed by completion char. if ($str =~ m/$pattern/) { - print "Matched: $1"; return $1; } else { return undef; -- cgit v1.2.3 From 77570a1f815b8f239711e165439194c11c46206e Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 8 Apr 2011 20:52:15 +0100 Subject: notifyquit: add 'ftp' to the blacklist since it's a common prefix which is (hopefully) unlikely to be a nick. --- quit-notify/notifyquit.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index 501ce88..6201c73 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -91,7 +91,7 @@ sub sig_send_text { if ($target_nick) { if (not $witem->nick_find($target_nick)) { - return if $target_nick =~ m/^https?/i; + return if $target_nick =~ m/^(?:https?)|ftp/i; if ($permit_pending) { -- cgit v1.2.3 From 1ba6da105bce0a73dc7889cd3791149fab84a1ae Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 21 Apr 2011 22:39:53 +0100 Subject: notifyquit: added notifyquit_exceptions setting, which takes a space separated list of regular expressions in the form /regex/. If any of the regexen match, the message will be allowed to proceed without the confirmation step. Defaults are: /^https?/ /^ftp/ --- quit-notify/notifyquit.pl | 98 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 18 deletions(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index 6201c73..c2737dc 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -21,7 +21,7 @@ our %IRSSI = ( my $active = 0; my $permit_pending = 0; my $pending_input = {}; - +my @match_exceptions; sub script_is_loaded { return exists($Irssi::Script::{$_[0] . '::'}); @@ -78,6 +78,20 @@ sub extract_nick { } +sub check_nick_exemptions { + my ($nick) = @_; + foreach my $except (@match_exceptions) { + print "Testing nick $nick against $except"; + if ($nick =~ $except) { + print "FAiled match $except"; + return 0; # fail + } + } + print "match ok"; + + return 1; +} + sub sig_send_text { my ($data, $server, $witem) = @_; @@ -91,27 +105,28 @@ sub sig_send_text { if ($target_nick) { if (not $witem->nick_find($target_nick)) { - return if $target_nick =~ m/^(?:https?)|ftp/i; + #return if $target_nick =~ m/^(?:https?)|ftp/i; + return unless check_nick_exemptions($target_nick); - if ($permit_pending) { + if ($permit_pending) { - $pending_input = {}; - $permit_pending = 0; - Irssi::signal_continue(@_); + $pending_input = {}; + $permit_pending = 0; + Irssi::signal_continue(@_); - } else { - my $text - = "$target_nick isn't in this channel, send anyway? [Y/n]"; - $pending_input - = { - text => $data, - server => $server, - win_item => $witem, - }; + } else { + my $text + = "$target_nick isn't in this channel, send anyway? [Y/n]"; + $pending_input + = { + text => $data, + server => $server, + win_item => $witem, + }; - Irssi::signal_stop; - require_confirmation($text) - } + Irssi::signal_stop; + require_confirmation($text) + } } } } @@ -151,10 +166,57 @@ sub sig_gui_keypress { } sub app_init { + Irssi::signal_add('setup changed' => \&sig_setup_changed); Irssi::signal_add_first("send text" => \&sig_send_text); Irssi::signal_add_first('gui key pressed' => \&sig_gui_keypress); + Irssi::settings_add_str($IRSSI{name}, 'notifyquit_exceptions', '/^https?/ /^ftp/'); + + # horrible name, but will serve. + Irssi::command_bind('notifyquit_show_exceptions', \&cmd_show_exceptions); + + + sig_setup_changed(); + +} + +sub cmd_show_exceptions { + + foreach my $e (@match_exceptions) { + print "Exception: $e"; + } } +sub sig_setup_changed { + + my $except_str = Irssi::settings_get_str('notifyquit_exceptions'); + my @except_list = split( m{(?:^|(?<=/))\s+(?:(?=/)|$)}, $except_str); + + @match_exceptions = (); + + foreach my $except (@except_list) { + + print "Exception regex str: $except"; + $except =~ s|^/||; + $except =~ s|/$||; + + next if $except =~ m/^\s*$/; + + my $regex; + + eval { + $regex = qr/$except/i; + }; + + if ($@ or not defined $regex) { + print "Regex failed to parse: \"$except\": $@"; + } else { + print "Adding match exception: $regex"; + push @match_exceptions, $regex; + } + } +} + + sub require_confirmation { $active = 1; set_prompt(shift); -- cgit v1.2.3 From 41faea8a07e5b921711c6eabc28b5bb19b6d19e5 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 21 Apr 2011 23:12:49 +0100 Subject: * quit-notify/README.pod: added documentation for notifyquit, and generated readme file. --- quit-notify/notifyquit.pl | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index c2737dc..a8d7f3f 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -1,3 +1,93 @@ +=pod + +=head1 NAME + +notifyquit.pl + +=head1 DESCRIPTION + +A script intended to alert people to the fact that their conversation partners +have quit or left the channel, especially useful in high-traffic channels, or +where you have C ignored. + +=head1 INSTALLATION + +This script requires that you have first installed and loaded F + +Uberprompt can be downloaded from: + +L + +and follow the instructions at the top of that file or its README for installation. + +If uberprompt.pl is available, but not loaded, this script will make one +attempt to load it before giving up. This eliminates the need to precisely +arrange the startup order of your scripts. + +Copy into your F<~/.irssi/scripts/> directory and load with +C>. + +=head1 SETUP + +This script provides a single setting: + +C, which defaults to "C" + +The setting is a space-separated list of regular expressions in the format +C. If the extracted nickname matches any of these patterns, it isa +assumed to be a false-positive match, and is sent to the channel with no +further confirmation. + +=head1 USAGE + +When responding to users in a channel in the format C<$theirnick: some message> +(where the C<:> is not necessarily a colon, but the value of your +C setting), this script will check that the nickname still +exists in the channel, and will prompt you for confirmation if they have +since left. + +It is intended for use for people who ignore C, etc, and +try to respond to impatient people, or those with a bad connection. + +To send the message once prompted, either hit C, or C. Pressing C +will abort sending, but leave the message in your input buffer just in case +you want to keep it. + +=head1 AUTHORS + +Original Copyright E 2011 Jari Matilainen Cvague!#irssi@freenodeE> + +Some extra bits +Copyright E 2011 Tom Feist Cshabble+irssi@metavore.orgE> + +=head1 LICENCE + +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. + +=head1 BUGS + +I + +Please report any problems to L +or moan about it in C<#irssi@Freenode>. + +=head1 TODO + +=over 4 + +=item * Keep a watchlist of nicks in the channel, and only act to confirm if +they quit shortly before/during you typing a response. + +=back + +=cut + ### # # Parts of the script pertaining to uberprompt borrowed from -- cgit v1.2.3 From 288758fd2ae991b6269500030af9ed522d66084e Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 21 Apr 2011 23:41:57 +0100 Subject: notifyquit: removed debug prints. --- quit-notify/notifyquit.pl | 5 ----- 1 file changed, 5 deletions(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index a8d7f3f..a37e258 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -171,13 +171,10 @@ sub extract_nick { sub check_nick_exemptions { my ($nick) = @_; foreach my $except (@match_exceptions) { - print "Testing nick $nick against $except"; if ($nick =~ $except) { - print "FAiled match $except"; return 0; # fail } } - print "match ok"; return 1; } @@ -285,7 +282,6 @@ sub sig_setup_changed { foreach my $except (@except_list) { - print "Exception regex str: $except"; $except =~ s|^/||; $except =~ s|/$||; @@ -300,7 +296,6 @@ sub sig_setup_changed { if ($@ or not defined $regex) { print "Regex failed to parse: \"$except\": $@"; } else { - print "Adding match exception: $regex"; push @match_exceptions, $regex; } } -- cgit v1.2.3 From 78b2c73b728acf9f9ff3c02a76652f081f7060ee Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Fri, 22 Apr 2011 02:32:56 +0100 Subject: notifyquit: maybe implemented todo item re: keeping watchlist of channel occupants to minimise false-positive matches. Needs testing though. --- quit-notify/notifyquit.pl | 162 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 157 insertions(+), 5 deletions(-) (limited to 'quit-notify/notifyquit.pl') diff --git a/quit-notify/notifyquit.pl b/quit-notify/notifyquit.pl index a37e258..eb08d88 100644 --- a/quit-notify/notifyquit.pl +++ b/quit-notify/notifyquit.pl @@ -7,7 +7,7 @@ notifyquit.pl =head1 DESCRIPTION A script intended to alert people to the fact that their conversation partners -have quit or left the channel, especially useful in high-traffic channels, or +have quit or left the channel, especially useful in high-traffic channels, or where you have C ignored. =head1 INSTALLATION @@ -84,6 +84,11 @@ or moan about it in C<#irssi@Freenode>. =item * Keep a watchlist of nicks in the channel, and only act to confirm if they quit shortly before/during you typing a response. +keep track of the most recent departures, and upon sending, see if one of them +is your target. If so, prompt for confirmation. + +So, add them on quit/kick/part, and remove them after a tiemout. + =back =cut @@ -97,6 +102,7 @@ they quit shortly before/during you typing a response. use strict; use warnings; +use Data::Dumper; our $VERSION = "0.2"; our %IRSSI = ( @@ -111,7 +117,9 @@ our %IRSSI = ( my $active = 0; my $permit_pending = 0; my $pending_input = {}; +my $verbose = 0; my @match_exceptions; +my $watchlist = {}; sub script_is_loaded { return exists($Irssi::Script::{$_[0] . '::'}); @@ -171,10 +179,13 @@ sub extract_nick { sub check_nick_exemptions { my ($nick) = @_; foreach my $except (@match_exceptions) { + _debug("Testing nick $nick against $except"); if ($nick =~ $except) { + _debug( "FAiled match $except"); return 0; # fail } } + _debug("match ok"); return 1; } @@ -190,7 +201,8 @@ sub sig_send_text { my $target_nick = extract_nick($data); if ($target_nick) { - if (not $witem->nick_find($target_nick)) { + if (check_watchlist($target_nick, $witem, $server) + and not $witem->nick_find($target_nick)) { #return if $target_nick =~ m/^(?:https?)|ftp/i; return unless check_nick_exemptions($target_nick); @@ -212,7 +224,7 @@ sub sig_send_text { }; Irssi::signal_stop; - require_confirmation($text) + require_confirmation($text); } } } @@ -252,18 +264,141 @@ sub sig_gui_keypress { } } + +sub add_to_watchlist { + my ($nick, $channel, $server) = @_; + my $tag = $server->{tag}; + _debug("Adding $nick to $channel/$tag"); + + $watchlist->{$tag}->{$channel}->{$nick} = time(); +} + +sub check_watchlist { + my ($nick, $channel, $server) = @_; + my $tag = $server->{tag}; + + my $check = exists ($watchlist->{$tag}->{$channel}->{$nick}); + _debug("Check for $nick in $channel/$tag is " .( $check ? 'true' : 'false')); + + return $check; +} + +sub remove_from_watchlist { + my ($nick, $channel, $server) = @_; + my $tag = $server->{tag}; + + if (exists($watchlist->{$tag}->{$channel}->{$nick})) { + delete($watchlist->{$tag}->{$channel}->{$nick}); + _debug("Deleted $nick from $channel/$tag"); + } +} + +sub start_watchlist_expire_timer { + my ($nick, $channel, $server, $callback) = @_; + + my $tag = $server->{tag}; + my $timeout = Irssi::settings_get_time('notifyquit_timeout'); + + Irssi::timeout_add_once($timeout, + $callback, + { nick => $nick, + channel => $channel, + server => $server, + }); +} + +sub sig_message_quit { + my ($server, $nick, $address, $reason) = @_; + + my $tag = $server->{tag}; + + _debug( "$nick quit from $tag"); + add_to_watchlist($nick, "***", $server); + + my $quit_cb = sub { + + # remove from all channels. + foreach my $chan (keys %{ $watchlist->{$tag} }) { + # if (exists $chan->{$nick}) { + # delete $watchlist->{$tag}->{$chan}->{$nick}; + # } + remove_from_watchlist($nick, $chan, $server) + } + }; + + start_watchlist_expire_timer($nick, '***', $server, $quit_cb); + +} + +sub sig_message_part { + my ($server, $channel, $nick, $address, $reason) = @_; + + my $tag = $server->{tag}; + + _debug( "$nick parted from $channel/$tag"); + add_to_watchlist($nick, $channel, $server); + my $part_cb = sub { + remove_from_watchlist($nick, $channel, $server); + }; + + start_watchlist_expire_timer($nick, $channel, $server, $part_cb); + +} + +sub sig_message_kick { + my ($server, $channel, $nick, $kicker, $address, $reason) = @_; + _debug( "$nick kicked from $channel by $kicker"); + + my $tag = $server->{tag}; + add_to_watchlist($nick, $channel, $server); + + my $kick_cb = sub { + remove_from_watchlist($nick, $channel, $server); + }; + + start_watchlist_expire_timer($nick, $channel, $server, $kick_cb); +} + +sub sig_message_nick { + my ($server, $newnick, $oldnick, $address) = @_; + my $tag = $server->{tag}; + + _debug("$oldnick changed nick to $newnick ($tag)"); + #_debug( "Not bothering with this for now."); + add_to_watchlist($newnick, '***', $server); + remove_from_watchlist($oldnick, '***', $server); + + my $nick_cb = sub { + remove_from_watchlist($newnick, '***', $server); + }; + + start_watchlist_expire_timer($newnick, '***', $server, $nick_cb); +} + +sub sig_message_join { + my ($server, $channel, $nick) = @_; + add_to_watchlist($nick, $channel, $server); + +} + sub app_init { Irssi::signal_add('setup changed' => \&sig_setup_changed); + Irssi::signal_add_first('message quit' => \&sig_message_quit); + #Irssi::signal_add_first('message join' => \&sig_message_join); + Irssi::signal_add_first('message part' => \&sig_message_part); + Irssi::signal_add_first('message kick' => \&sig_message_kick); + Irssi::signal_add_first('message nick' => \&sig_message_nick); Irssi::signal_add_first("send text" => \&sig_send_text); Irssi::signal_add_first('gui key pressed' => \&sig_gui_keypress); Irssi::settings_add_str($IRSSI{name}, 'notifyquit_exceptions', '/^https?/ /^ftp/'); + Irssi::settings_add_bool($IRSSI{name}, 'notifyquit_verbose', 0); + Irssi::settings_add_time($IRSSI{name}, 'notifyquit_timeout', '30s'); # horrible name, but will serve. Irssi::command_bind('notifyquit_show_exceptions', \&cmd_show_exceptions); - + Irssi::command_bind('notifyquit_show_watchlist', \&cmd_show_watchlist); sig_setup_changed(); - } sub cmd_show_exceptions { @@ -273,15 +408,21 @@ sub cmd_show_exceptions { } } +sub cmd_show_watchlist { + Irssi::print Dumper($watchlist); +} + sub sig_setup_changed { my $except_str = Irssi::settings_get_str('notifyquit_exceptions'); + $verbose = Irssi::settings_get_bool('notifyquit_verbose'); my @except_list = split( m{(?:^|(?<=/))\s+(?:(?=/)|$)}, $except_str); @match_exceptions = (); foreach my $except (@except_list) { + _debug("Exception regex str: $except"); $except =~ s|^/||; $except =~ s|/$||; @@ -296,6 +437,7 @@ sub sig_setup_changed { if ($@ or not defined $regex) { print "Regex failed to parse: \"$except\": $@"; } else { + _debug("Adding match exception: $regex"); push @match_exceptions, $regex; } } @@ -312,3 +454,13 @@ sub set_prompt { $msg = ': ' . $msg if length $msg; Irssi::signal_emit('change prompt', $msg, 'UP_INNER'); } + +sub _debug { + + return unless $verbose; + + my ($msg, @params) = @_; + my $str = sprintf($msg, @params); + print $str; + +} -- cgit v1.2.3