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


   1 # /AUTOOP <*|#channel> [<nickmasks>]
   2 # use friends.pl if you need more features
   3 
   4 use Irssi;
   5 use strict;
   6 use vars qw($VERSION %IRSSI);
   7 
   8 $VERSION = "1.00";
   9 %IRSSI = (
  10     authors     => 'Timo Sirainen',
  11     name        => 'autoop',
  12     description => 'Simple auto-op script',
  13     license     => 'Public Domain',
  14     changed	=> 'Sun Mar 10 23:18 EET 2002'
  15 );
  16 
  17 my (%opnicks, %temp_opped);
  18 
  19 sub cmd_autoop {
  20 	my ($data) = @_;
  21 	my ($channel, $masks) = split(" ", $data, 2);
  22 
  23 	if ($channel eq "") {
  24 		if (!%opnicks) {
  25 			Irssi::print("Usage: /AUTOOP <*|#channel> [<nickmasks>]");
  26 			Irssi::print("No-one's being auto-opped currently.");
  27 			return;
  28 		}
  29 
  30 		Irssi::print("Currently auto-opping in channels:");
  31 		foreach $channel (keys %opnicks) {
  32 			$masks = $opnicks{$channel};
  33 
  34 			if ($channel eq "*") {
  35 				Irssi::print("All channels: $masks");
  36 			} else {
  37 				Irssi::print("$channel: $masks");
  38 			}
  39 		}
  40 		return;
  41 	}
  42 
  43 	if ($masks eq "") {
  44 		$masks = "<no-one>";
  45 		delete $opnicks{$channel};
  46 	} else {
  47 		$opnicks{$channel} = $masks;
  48 	}
  49 	if ($channel eq "*") {
  50 		Irssi::print("Now auto-opping in all channels: $masks");
  51 	} else {
  52 		Irssi::print("$channel: Now auto-opping: $masks");
  53 	}
  54 }
  55 
  56 sub autoop {
  57 	my ($channel, $masks, @nicks) = @_;
  58 	my ($server, $nickrec);
  59 
  60 	$server = $channel->{server};
  61 	foreach $nickrec (@nicks) {
  62 		my $nick = $nickrec->{nick};
  63 		my $host = $nickrec->{host};
  64 
  65                 if (!$temp_opped{$nick} &&
  66 		    $server->masks_match($masks, $nick, $host)) {
  67 			$channel->command("/op $nick");
  68 			$temp_opped{$nick} = 1;
  69 		}
  70 	}
  71 }
  72 
  73 sub event_massjoin {
  74 	my ($channel, $nicks_list) = @_;
  75 	my @nicks = @{$nicks_list};
  76 
  77 	return if (!$channel->{chanop});
  78 
  79 	undef %temp_opped;
  80 
  81 	# channel specific
  82 	my $masks = $opnicks{$channel->{name}};
  83 	autoop($channel, $masks, @nicks) if ($masks);
  84 
  85 	# for all channels
  86 	$masks = $opnicks{"*"};
  87 	autoop($channel, $masks, @nicks) if ($masks);
  88 }
  89 
  90 Irssi::command_bind('autoop', 'cmd_autoop');
  91 Irssi::signal_add_last('massjoin', 'event_massjoin');