updates.
[runtime.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 strict;
10 use Irssi::Irc;
11
12 sub channel_rejoin {
13   my ($server, $channel) = @_;
14
15   # check if channel has password
16   my $chanrec = $server->channel_find($channel);
17   my $password = $chanrec->{key} if ($chanrec);
18
19   # We have to use send_raw() because the channel record still
20   # exists and irssi won't even try to join to it with command()
21   $server->send_raw("JOIN $channel $password");
22 }
23
24 sub event_rejoin_kick {
25   my ($server, $data) = @_;
26   my ($channel, $nick) = split(/ +/, $data);
27
28   return if ($server->{nick} ne $nick);
29
30   # check if we want to autorejoin this channel
31   my @chans = split(/ ,/, Irssi::settings_get_str('autorejoin_channels'));
32   foreach my $chan (@chans) {
33     if (lc($chan) eq lc($channel)) {
34       channel_rejoin($server, $channel);
35       last;
36     }
37   }
38 }
39
40 Irssi::settings_add_str('misc', 'autorejoin_channels', '');
41 Irssi::signal_add('event kick', 'event_rejoin_kick');