~nhandler/+junk/irssi-scripts

« back to all changes in this revision

Viewing changes to bansearch.pl

  • Committer: Nathan Handler
  • Date: 2012-06-14 05:39:03 UTC
  • Revision ID: nhandler@ubuntu.com-20120614053903-rsezbat2qq0cic20
Fix issue that caused bansearch and grepbans to interfere with each other.
Still not really sure what caused the issue, but it is no longer occuring.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
    license     => 'GPLv3+',
15
15
);
16
16
 
17
 
my($channel,$person,$nick,$user,$host,$real,$account,$string,$issues);
 
17
my($channel,$person,$nick,$user,$host,$real,$account,$string,$issues,$running);
 
18
 
 
19
$running=0;
18
20
 
19
21
sub bansearch {
20
22
        my($data,$server,$witem) = @_;
21
23
 
 
24
        if($running) {
 
25
                Irssi::print("bansearch is already running.");
 
26
        }
 
27
 
 
28
        $running=1;
 
29
 
22
30
        #Clear variables and register redirects
23
31
        &reset();
24
32
 
33
41
        #Stop the script and display usage information if they did not specify a person or if we can't find a channel to use
34
42
        if($channel!~m/^#/ || $person=~m/^\s*$/) {
35
43
                Irssi::active_win()->print("\x02Usage\x02: /bansearch nick [#channel]");
 
44
                $running=0;
36
45
                return;
37
46
        }
38
47
 
40
49
        Irssi::active_win()->print("\x02Channel\x02: $channel");
41
50
 
42
51
        #Perform a /who <user> %uhnar
43
 
        $server->redirect_event('who',0, $person, 0, undef,
 
52
        $server->redirect_event('who',1, $person, 0, undef,
44
53
        {
45
54
          'event 352' => 'redir rpl_whoreply',
46
55
          'event 354' => 'redir rpl_whospcrpl',
66
75
sub EMPTY {
67
76
        my($server, $data) = @_;
68
77
 
 
78
        return if(!$running);
 
79
 
69
80
        Irssi::print("\x02EMPTY\x02: $data");
70
81
}
71
82
 
72
83
sub RPL_BANLIST {
73
84
        my($server, $data) = @_;
 
85
 
 
86
        return if(!$running);
 
87
 
74
88
        my($type, $mask, $setby);
75
89
        if($data=~m/^Ban/) {
76
90
                ($type, undef, undef, $mask, $setby, undef) = split(/ /, $data, 6);
149
163
 
150
164
sub RPL_ENDOFBANLIST {
151
165
        my($server, $data) = @_;
 
166
 
 
167
        return if(!$running);
 
168
 
152
169
#       Irssi::active_win()->print("End of Ban List");
153
170
        if($data=~m/^Ban/) {
154
 
                $server->redirect_event('mode q',0, $channel, 0, undef,
 
171
                $server->redirect_event('mode q',1, $channel, 0, undef,
155
172
                {
156
173
                  'event 728' => 'redir rpl_quietlist',
157
174
                  'event 729' => 'redir rpl_endofquietlist',
161
178
                $server->send_raw("MODE $channel q");
162
179
        }
163
180
        elsif($data=~m/^Quiet/) {
164
 
                $server->redirect_event('mode channel',0, $channel, 0, undef,
 
181
                $server->redirect_event('mode channel',1, $channel, 0, undef,
165
182
                {
166
183
                  'event 324' => 'redir rpl_channelmodeis',
167
184
                  '' => 'event empty',
173
190
 
174
191
sub RPL_WHOREPLY {
175
192
        my($server, $data) = @_;
 
193
 
 
194
        return if(!$running);
 
195
 
176
196
        (undef, $user, $host, $nick, $account, $real) = split(/ /, $data, 6);
177
197
        $real=~s/^://;
178
198
        Irssi::active_win()->print("\x02User\x02: $nick [$account] ($real) $user\@$host");
180
200
 
181
201
sub RPL_ENDOFWHO {
182
202
        my($server, $data) = @_;
 
203
 
 
204
        return if(!$running);
 
205
 
183
206
        if($nick=~m/^$/ && $user=~m/^$/ && $host=~m/^$/) {
184
207
                Irssi::active_win()->print("$person is currently offline.");
185
208
                return;
186
209
        }
187
210
        $string="$nick!$user\@$host";
188
 
        $server->redirect_event('mode b',0, $channel, 0, undef, 
 
211
        $server->redirect_event('mode b',1, $channel, 0, undef, 
189
212
        {
190
213
          'event 367' => 'redir rpl_banlist',
191
214
          'event 368' => 'redir rpl_endofbanlist',
199
222
sub ERR_NOSUCHNICK {
200
223
        my($server, $data) = @_;
201
224
 
 
225
        return if(!$running);
 
226
 
202
227
        Irssi::active_win()->print("$person is currently offline.");
 
228
        $running=0;
203
229
}
204
230
 
205
231
sub ERR_NOSUCHCHANNEL {
206
232
        my($server, $data) = @_;
207
233
 
 
234
        return if(!$running);
 
235
 
208
236
        Irssi::active_win()->print("$channel does not exist.");
 
237
        $running=0;
209
238
}
210
239
 
211
240
sub RPL_CHANNELMODEIS {
212
241
        my($server, $data) = @_;
 
242
 
 
243
        return if(!$running);
 
244
 
213
245
        my(undef, undef, $modes, $args) = split(/ /, $data, 4);
214
246
        Irssi::active_win()->print("\x02Channel Modes\x02: $modes");
215
247
        if($modes=~m/i/) {
249
281
        else {
250
282
                Irssi::active_win()->print("There are \x02$issues issues\x02 that might be preventing $person from joining/talking in $channel");
251
283
        }
 
284
        $running=0;
252
285
}
253
286
 
254
287
sub reset {
 
288
 
 
289
        return if(!$running);
 
290
 
255
291
        $channel='';
256
292
        $person='';
257
293
        $nick='';
266
302
}       
267
303
 
268
304
sub register_redirects {
 
305
 
 
306
        return if(!$running);
 
307
 
269
308
        #who
270
309
        Irssi::Irc::Server::redirect_register('who', 0, 0,
271
310
        { "event 352" => 1,    # start events