-
Notifications
You must be signed in to change notification settings - Fork 1
/
mwhois.pl
147 lines (122 loc) · 3.23 KB
/
mwhois.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Usage:
# /mwhois <mask or other garbage usually passed to /who>
# Behaves like /who, but returns whois results! Amazing!
# Alternatively, to /whois all users in a channel except
# yourself, run /mwhois in the channel window without
# any arguments.
# This is based on another script of mine, affiliated.pl.
use strict;
use Irssi;
use Data::Dumper;
use vars qw($VERSION %IRSSI);
$VERSION = "1.1";
%IRSSI = (
authors => "mr_flea",
contact => "mrflea\@gmail.com",
name => "mwhois.pl",
description => "Runs a whois on all results from a WHO request.",
license => "BSD",
url => "http://www.phantomflame.com/",
changed => "Mon 28 May 2012 02:46:31 AM UTC"
);
Irssi::settings_add_int('misc', 'mwhois_max_users', 8);
# This script uses a bunch of global variables because I am very lazy. :(
my @nicklist;
my $currserver = 0;
sub printmsg {
Irssi::print("mwhois: " . $_[0], MSGLEVEL_CLIENTCRAP);
}
sub clear {
@nicklist = ();
$currserver = 0;
}
sub mwhois {
my ($data, $server, $channel) = @_;
if (!$server) {
printmsg("Please connect to a server.");
return;
}
$data =~ s/^\s+//g;
$data =~ s/\s+$//g;
# if (lc($data) eq 'cancel') {
# printmsg("Operation cancelled.");
# if ($currserver) {
# print_results();
# } else {
# clear();
# }
# return;
# }
if ($currserver) {
printmsg("There is already an operation in progress! "
. "Please wait until it is finished.");
return;
}
$currserver = $server;
if (!$data && (!defined $channel || $channel->{chat_type} ne "IRC")) {
printmsg("Usage: /mwhois [mask] - execute WHOIS on all users returned by a " .
"WHO for 'mask', or execute WHOIS on all users in the current channel.");
return;
}
# This code looks pretty stupid but I'm so tired that I
# can't figure out how to fix it. :(
if ($data) {
# Channel types #, &, !, +.
if ($data =~ /^[#&!+]/) {
my $chan = $server->channel_find($data);
if ($chan)
{
$channel = $chan;
} else {
populate_nicklist($data);
return;
}
} else {
populate_nicklist($data);
return;
}
}
foreach ($channel->nicks()) {
push @nicklist, $_->{nick} unless (lc($_->{nick}) eq lc($currserver->{nick}));
}
start();
}
sub populate_nicklist {
my ($target) = @_;
$currserver->redirect_event('who', 1, '', -1, '', {
'event 352' => 'redir mwhois_who',
'event 315' => 'redir mwhois_endwho',
'' => 'event empty'
});
$currserver->send_raw("WHO $target");
}
sub receive_who {
my ($server, $data) = @_;
return if (!$currserver);
my @user = split(/\s+/, $data);
return if (lc($user[5]) eq lc($server->{nick})); # Exclude self.
push @nicklist, $user[5];
}
sub start {
return if (!$currserver);
if (@nicklist > Irssi::settings_get_int('mwhois_max_users')) {
splice(@nicklist, Irssi::settings_get_int('mwhois_max_users') + 1, -1);
printmsg("Truncating results to " .
Irssi::settings_get_int('mwhois_max_users') . " users.");
}
if (@nicklist > 0)
{
printmsg("User list: " . join(', ', @nicklist). ".");
} else {
printmsg("No users match mask.");
}
foreach my $nick (@nicklist)
{
$currserver->command("whois $nick");
}
@nicklist = ();
$currserver = 0;
}
Irssi::command_bind('mwhois', 'mwhois');
Irssi::signal_add('redir mwhois_who', 'receive_who');
Irssi::signal_add('redir mwhois_endwho', 'start');