diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:19:02 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 20:19:02 +0000 |
commit | 03929dac2a29664878d2c971648a4fe1fb698462 (patch) | |
tree | 02c5e2b3e006234aa29545f7a93a1ce01b291a8b /scripts/auto_whois.pl | |
parent | Initial commit. (diff) | |
download | irssi-scripts-74dedaab1f75de511e9ded8f64dcf9a4c7d2946f.tar.xz irssi-scripts-74dedaab1f75de511e9ded8f64dcf9a4c7d2946f.zip |
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/auto_whois.pl')
-rw-r--r-- | scripts/auto_whois.pl | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/auto_whois.pl b/scripts/auto_whois.pl new file mode 100644 index 0000000..59fc1ef --- /dev/null +++ b/scripts/auto_whois.pl @@ -0,0 +1,80 @@ +# /WHOIS all the users who send you a private message. +# v0.9 for irssi by Andreas 'ads' Scherbaum +# idea and some code taken from autowhois.pl from Timo Sirainen +use strict; +use Irssi; +use vars qw($VERSION %IRSSI); + +$VERSION = "0.9"; +%IRSSI = ( + authors => "Andreas \'ads\' Scherbaum", + contact => "ads\@ufp.de", + name => "auto_whois", + description => "/WHOIS all the users who send you a private message.", + license => "GPL", + url => "http://irssi.org/", + changed => "2004-02-10", + changes => "v0.9: don't /WHOIS if query exists for the nick already" +); + +# History: +# v0.9: don't /WHOIS if query exists for the nick already +# now we store all nicks we have seen in the last 10 minutes + +my @seen = (); + +sub msg_private_first { + my ($server, $msg, $nick, $address) = @_; + + # go through every stored connection and remove, if timed out + my $time = time(); + my ($connection); + my @new = (); + foreach $connection (@seen) { + if ($connection->{lasttime} >= $time - 600) { + # is ok, use it + push(@new, $connection); + # all timed out connections will be dropped + } + } + @seen = @new; +} + +sub msg_private { + my ($server, $msg, $nick, $address) = @_; + + # look, if we already know this connection + my ($connection, $a); + my $known_to_us = 0; + for ($a = 0; $a <= $#seen; $a++) { + $connection = $seen[$a]; + # the lc() works not exact, because irc uses another charset + if ($connection->{server} eq $server->{address} and $connection->{port} eq $server->{port} and lc($connection->{nick}) eq lc($nick)) { + $known_to_us = 1; + # mark as refreshed + $seen[$a]->{lasttime} = time(); + last; + } + } + + if ($known_to_us == 1) { + # all ok, return + return; + } + + # now store the new connection + $connection = {}; + # store our own server data here + $connection->{server} = $server->{address}; + $connection->{port} = $server->{port}; + # and the nick who queried us + $connection->{nick} = $nick; + $connection->{lasttime} = time(); + $connection->{starttime} = time(); + push(@seen, $connection); + + $server->command("whois $nick"); +} + +Irssi::signal_add_first('message private', 'msg_private_first'); +Irssi::signal_add('message private', 'msg_private'); |