Added SILC Thread Queue API
[crypto.git] / apps / irssi / scripts / autorejoin.pl
1 # automatically rejoin to channel after kicked
2
3 # /SET autorejoin_channels #channel1 #channel2 ...
4
5 # NOTE: I personally don't like this feature, in most channels I'm in it
6 # will just result as ban. You've probably misunderstood the idea of /KICK
7 # if you kick/get kicked all the time "just for fun" ...
8
9 use Irssi;
10 use Irssi::Irc;
11 use strict;
12 use vars qw($VERSION %IRSSI);
13
14 $VERSION = "1.00";
15 %IRSSI = (
16     authors     => 'Timo Sirainen',
17     name        => 'autorejoin',
18     description => 'Automatically rejoin to channel after kicked',
19     license     => 'Public Domain',
20     changed     => 'Sun Mar 10 23:18 EET 2002'
21 );
22
23 sub channel_rejoin {
24   my ($server, $channel) = @_;
25
26   # check if channel has password
27   my $chanrec = $server->channel_find($channel);
28   my $password = $chanrec->{key} if ($chanrec);
29
30   # We have to use send_raw() because the channel record still
31   # exists and irssi won't even try to join to it with command()
32   $server->send_raw("JOIN $channel $password");
33 }
34
35 sub event_rejoin_kick {
36   my ($server, $data) = @_;
37   my ($channel, $nick) = split(/ +/, $data);
38
39   return if ($server->{nick} ne $nick);
40
41   # check if we want to autorejoin this channel
42   my @chans = split(/[ ,]+/, Irssi::settings_get_str('autorejoin_channels'));
43   foreach my $chan (@chans) {
44     if (lc($chan) eq lc($channel)) {
45       channel_rejoin($server, $channel);
46       last;
47     }
48   }
49 }
50
51 Irssi::settings_add_str('misc', 'autorejoin_channels', '');
52 Irssi::signal_add('event kick', 'event_rejoin_kick');