From d86c7157909486cc377ce3d9d021feac789fd077 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 24 Aug 2000 01:01:21 +0000 Subject: [PATCH] Added /AUTOOP git-svn-id: http://svn.irssi.org/repos/irssi/trunk@625 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- scripts/Makefile.am | 1 + scripts/autoop.pl | 79 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 scripts/autoop.pl diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 409ff8dd..f528e4d9 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -1,4 +1,5 @@ EXTRA_DIST = \ + autoop.pl \ autorejoin.pl \ hello.pl \ privmsg.pl \ diff --git a/scripts/autoop.pl b/scripts/autoop.pl new file mode 100644 index 00000000..1a89381a --- /dev/null +++ b/scripts/autoop.pl @@ -0,0 +1,79 @@ +# /AUTOOP <*|#channel> [] +# For Irssi 0.7.96 and above (older versions had a few bugs) + +use Irssi; + +my %opnicks, %temp_opped; + +sub cmd_autoop { + my ($data) = @_; + my ($channel, $masks) = split(" ", $data, 2); + + if ($channel eq "") { + if (!%opnicks) { + Irssi::print("Usage: /AUTOOP <*|#channel> []"); + Irssi::print("No-one's being auto-opped currently."); + return 1; + } + + Irssi::print("Currently auto-opping in channels:"); + foreach $channel (keys %opnicks) { + $masks = $opnicks{$channel}; + + if ($channel eq "*") { + Irssi::print("All channels: $masks"); + } else { + Irssi::print("$channel: $masks"); + } + } + return 1; + } + + if ($masks eq "") { + $masks = "" if (!$masks); + delete $opnicks{$channel}; + } else { + $opnicks{$channel} = $masks; + } + if ($channel eq "*") { + Irssi::print("Now auto-opping in all channels: $masks"); + } else { + Irssi::print("$channel: Now auto-opping: $masks"); + } + return 1; +} + +sub autoop { + my ($channel, $masks, @nicks) = @_; + my $nickrec; + + foreach $nickrec (@nicks) { + $nick = $nickrec->values()->{'nick'}; + $host = $nickrec->values()->{'host'}; + + if (!$temp_opped{$nick} && + Irssi::irc_masks_match($masks, $nick, $host)) { + $channel->command("/op $nick"); + $temp_opped{$nick} = 1; + } + } +} + +sub event_massjoin { + my ($channel, @nicks) = @_; + + return if (!$channel->values()->{'chanop'}); + + undef %temp_opped; + + # channel specific + my $masks = $opnicks{$channel->values()->{'name'}}; + autoop($channel, $masks, @nicks) if ($masks); + + # for all channels + $masks = $opnicks{"*"}; + autoop($channel, $masks, @nicks) if ($masks); +} + +Irssi::command_bind('autoop', '', 'cmd_autoop'); +Irssi::signal_add_last('massjoin', 'event_massjoin');