/var/www/www.irssi.org-old/scripts/html/autorejoin.pl
1 # automatically rejoin to channel after kick
2 # delayed rejoin: Lam 28.10.2001 (lam@lac.pl)
3
4 # NOTE: I personally don't like this feature, in most channels I'm in it
5 # will just result as ban. You've probably misunderstood the idea of /KICK
6 # if you kick/get kicked all the time "just for fun" ...
7
8 use Irssi;
9 use Irssi::Irc;
10 use strict;
11 use vars qw($VERSION %IRSSI);
12 $VERSION = "1.0.0";
13 %IRSSI = (
14 authors => "Timo 'cras' Sirainen, Leszek Matok",
15 contact => "lam\@lac.pl",
16 name => "autorejoin",
17 description => "Automatically rejoin to channel after being kick, after a (short) user-defined delay",
18 license => "GPLv2",
19 changed => "10.3.2002 14:00"
20 );
21
22
23 # How many seconds to wait before the rejoin?
24 # TODO: make this a /setting
25 my $delay = 5;
26
27 my @tags;
28 my $acttag = 0;
29
30 sub rejoin {
31 my ( $data ) = @_;
32 my ( $tag, $servtag, $channel, $pass ) = split( / +/, $data );
33
34 my $server = Irssi::server_find_tag( $servtag );
35 $server->send_raw( "JOIN $channel $pass" ) if ( $server );
36 Irssi::timeout_remove( $tags[$tag] );
37 }
38
39 sub event_rejoin_kick {
40 my ( $server, $data ) = @_;
41 my ( $channel, $nick ) = split( / +/, $data );
42
43 return if ( $server->{ nick } ne $nick );
44
45 # check if channel has password
46 my $chanrec = $server->channel_find( $channel );
47 my $password = $chanrec->{ key } if ( $chanrec );
48 my $rejoinchan = $chanrec->{ name } if ( $chanrec );
49 my $servtag = $server->{ tag };
50
51 Irssi::print "Rejoining $rejoinchan in $delay seconds.";
52 $tags[$acttag] = Irssi::timeout_add( $delay * 1000, "rejoin", "$acttag $servtag $rejoinchan $password" );
53 $acttag++;
54 $acttag = 0 if ( $acttag > 60 );
55 }
56
57 Irssi::signal_add( 'event kick', 'event_rejoin_kick' );