From: phyber Date: Fri, 9 Jan 2015 15:33:31 +0000 (+0000) Subject: (quakequit) Various tidying. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=3d3c79269e97e417bb99074d1cd0b9dc263b50fe;p=irssi-scripts.irssi.org.git (quakequit) Various tidying. --- diff --git a/scripts/quakequit.pl b/scripts/quakequit.pl index 6455161..2efae54 100644 --- a/scripts/quakequit.pl +++ b/scripts/quakequit.pl @@ -1,6 +1,6 @@ # scripts/quakequit.pl -# Gets rid of some of the spam that you may see on quakenet if someone joins a channel -# before registering with nickserv. +# Gets rid of some of the spam that you may see on quakenet if someone joins +# a channel before registering with nickserv. # eg. ##### # >>> Nick!ident@hos.t has joined #channel @@ -15,8 +15,9 @@ # >>> Nick!ident@hos.t has joined #channel # +++ Q sets +o Nick #channel ##### -# It does this by remembering people who quit with a message of "Registered" for -# 1 second after they quit. Any joins or modes set within that one second are ignored. +# It does this by remembering people who quit with a message of "Registered" +# for 1 second after they quit. Any joins or modes set within that one +# second are ignored. ##### # Settings: # quakequit_networks (default: quakenet) @@ -35,12 +36,22 @@ $VERSION = "1.0"; licence => "GPLv2", changed => "02/03/2009", ); -# Output a few extra messages to the status window to help with + +# Output a few extra messages to the status window to help with # any errors that might happen. my $debug = 0; + # Hash to store our temporary ignores in. my %quits; +# Debug line output. +sub dprint { + my ($msg) = @_; + if ($debug) { + Irssi::print $msg; + } +} + # Return 1 if we should process the tag, otherwise 0. sub process_tag { my ($tag) = @_; @@ -56,7 +67,7 @@ sub process_tag { # Remove entries from the quits hash. sub purge_nick { my ($nick) = @_; - Irssi::print "Purging $nick from the quits list" if $debug; + dprint("Purging $nick from the quits list"); delete $quits{$nick}; return 0; } @@ -65,18 +76,23 @@ sub purge_nick { sub message_join { my ($server_rec, $channel, $nick, $addr) = @_; my $tag = $server_rec->{tag}; + # Don't proceed if the hash is empty. - # hash returns / in scalar context and just 0 if it's empty. + # hash returns / in scalar context and just 0 if + # it's empty. if (!%quits) { return 0; } + # Return if we don't care about this tag. - if (process_tag($tag) == 0) { + if (!process_tag($tag)) { return 0; } - Irssi::print "Processing JOIN $tag: $nick $addr" if $debug; + + dprint("Processing JOIN $tag: $nick $addr"); + # If the joining nick is in our quit hash, don't show the join. - if ($quits{$tag.':'.$nick} == 1) { + if ($quits{$tag.':'.$nick}) { Irssi::signal_stop(); return 0; } @@ -86,56 +102,76 @@ sub message_join { sub message_quit { my ($server_rec, $nick, $addr, $reason) = @_; my $tag = $server_rec->{tag}; + # Return if we don't care about this tag. - if (process_tag($tag) == 0) { + if (!process_tag($tag)) { return 0; } - Irssi::print "Processing QUIT $tag: $nick $addr $reason" if $debug; - # If the quit message is registered, add the person to our quit hash and abort the signal. - if ($reason eq "Registered") { - $quits{$tag.':'.$nick} = 1; - Irssi::timeout_add_once(1000, 'purge_nick', $tag.':'.$nick); - Irssi::signal_stop(); + + dprint("Processing QUIT $tag: $nick $addr $reason"); + + if ($reason ne "Registered") { return 0; } + + # If the quit message is registered, add the person to our quit hash + # and abort the signal. + $quits{$tag.':'.$nick} = 1; + Irssi::timeout_add_once(1000, 'purge_nick', $tag.':'.$nick); + Irssi::signal_stop(); + return 0; } # Sometimes we have to hide server modes on quakenet too. sub message_irc_mode { my ($server_rec, $channel, $nick, $addr, $mode) = @_; my $tag = $server_rec->{tag}; + # Don't proceed if the hash is empty if (!%quits) { return 0; } + # Return if we don't care about this tag. - if (process_tag($tag) == 0) { + if (!process_tag($tag)) { return 0; } - Irssi::print "Processing MIM $tag: $channel $nick $addr $mode" if $debug; + + dprint("Processing MIM $tag: $channel $nick $addr $mode"); + my $servermask = Irssi::settings_get_str('quakequit_servermask'); - # If the server is setting the mode, the $nick will be the server mask and $addr will be empty. - if ($nick eq $servermask) { - Irssi::print "$nick == $servermask" if $debug; - # break the target nicks away from the modes set on them. - my ($modes, @targets) = split / /, $mode, 2; - # If the nick exists in the hash and the mode setter is *.quakenet.org, signal_stop. - foreach my $target (@targets) { - Irssi::print "Processing $target" if $debug; - if ($quits{$tag.':'.$target} == 1) { - Irssi::print "Found $target in target list, stopping signal" if $debug; - Irssi::signal_stop(); - return 0; - } + # If the server is setting the mode, the $nick will be the server mask + # and $addr will be empty. + + if ($nick ne $servermask) { + return 0; + } + + dprint("$nick == $servermask"); + + # break the target nicks away from the modes set on them. + my ($modes, @targets) = split / /, $mode, 2; + + # If the nick exists in the hash and the mode setter is + # *.quakenet.org, signal_stop. + foreach my $target (@targets) { + dprint("Processing $target"); + + if ($quits{$tag.':'.$target}) { + dprint("Found $target in target list, stopping signal"); + Irssi::signal_stop(); + return 0; } } } ## Settings # quakequit_networks: set the networks that you'd like this script to watch -# quakequit_servermask: the name of the server that's setting the modes on rejoin +# quakequit_servermask: the name of the server that's setting the modes on +# rejoin Irssi::settings_add_str('quakequit', 'quakequit_networks', 'QuakeNet'); Irssi::settings_add_str('quakequit', 'quakequit_servermask', '*.quakenet.org'); + # Signals to grab Irssi::signal_add_first('message irc mode', 'message_irc_mode'); Irssi::signal_add_last('message join', 'message_join');