/var/www/www.irssi.org-old/scripts/html/autocycle.pl


   1 # Usage: /SET auto_regain_ops [On/Off]
   2 #        /autocycle
   3 
   4 use strict;
   5 use vars qw($VERSION %IRSSI);
   6 
   7 use Irssi 20020313 qw( settings_add_bool settings_get_bool servers command_bind timeout_add );
   8 $VERSION = "0.4";
   9 %IRSSI = (
  10    authors      => "Marcin Rozycki",
  11    contact      => "derwan\@irssi.pl",
  12    name         => "autocycle",
  13    description  => "Auto regain ops in empty opless channels",
  14    url          => "http://derwan.irssi.pl",
  15    license      => "GNU GPL v2",
  16    changed      => "Fri Jan  3 23:20:06 CET 2003"
  17 );
  18 
  19 sub check_channels {
  20    foreach my $server (servers) {
  21       if ($server->{usermode} !~ m/r/ and my @channels = $server->channels) {
  22          CHANNEL: while (my $channel = shift @channels) {
  23             my $modes = $channel->{mode};
  24             my $test = ($modes and $modes =~ m/a/) ? 1 : 0;
  25             if (!$test && $channel->{synced} && $channel->{name} !~ m/^[\+\!]/ && !$channel->{ownnick}->{op}) {
  26                foreach my $nick ($channel->nicks) {
  27                   ($nick->{nick} eq $server->{nick}) or goto CHANNEL;
  28                }
  29                $channel->print("Auto regain op in empty channel " . $channel->{name});
  30                $channel->command("cycle");
  31             }
  32          }
  33       }
  34    }
  35 }
  36 
  37 sub autocycle {
  38    if (settings_get_bool("auto_regain_ops")) {
  39       check_channels();
  40    }
  41 }
  42 
  43 settings_add_bool "misc", "auto_regain_ops", 1;
  44 command_bind "autocycle", "check_channels";
  45 timeout_add 60000, \&autocycle, undef;
  46 autocycle;
  47