1use strict;
2use Irssi 20010920.0000 ();
3use vars qw($VERSION %IRSSI);
4$VERSION = "1.00";
5%IRSSI = (
6    authors     => 'David Leadbeater',
7    contact     => 'dgl@dgl.cx',
8    name        => 'autolimit',
9    description => 'does an autolimit for a channel, set variables in the script',
10    license     => 'GNU GPLv2 or later',
11    url         => 'http://irssi.dgl.cx/',
12);
13
14# Change these!
15my $channel = "#channel";
16my $offset = 5;
17my $tolerence = 2;
18my $time = 60;
19
20sub checklimit {
21   my $c = Irssi::channel_find($channel);
22   return unless ref $c;
23   return unless $c->{chanop};
24   my $users = scalar @{[$c->nicks]};
25
26   if(($c->{limit} <= ($users+$offset-$tolerence)) ||
27		 ($c->{limit} > ($users+$offset+$tolerence))) {
28	  $c->{server}->send_raw("MODE $channel +l " . ($users+$offset));
29   }
30}
31
32Irssi::timeout_add($time * 1000, 'checklimit','');
33
34