Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/jzacsh/dotfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jzacsh committed Mar 20, 2016
2 parents 814f551 + aafb33e commit 805c361
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .irssi/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');
1 change: 1 addition & 0 deletions .irssi/scripts/autorun/auto_whois.pl

0 comments on commit 805c361

Please sign in to comment.