use vars qw($VERSION %IRSSI);

use Irssi;
use strict;
$VERSION = "0.11";
%IRSSI = (
    authors	=> "DLange based on tomaw's mvoice.pl",
    name	=> "Voice multiple users using ChanServ",
    description	=> "/csv nick1 <nick2> ... voice via ChanServ (devoice with -nick), /csva voice all users via ChanServ",
    license	=> "Public Domain",
    changed	=> "2008-10-01"
);

sub cmd_csva {
	my ($data, $server, $channel) = @_;
	my $nick;

	if ($channel->{type} ne "CHANNEL") {
		Irssi::print("Your are not on a channel");
		return;
	}

	if ($data ne "") {
		Irssi::print("/csva does not accept arguments, did you mean /csv?");
		return;
	}
	
	foreach $nick ($channel->nicks()) {
		$channel->command("quote cs voice $channel->{name} $nick->{nick}") if ! $nick->{voice} && ! $nick->{op};
	}
}

sub cmd_csv {
        my ($data, $server, $channel) = @_;

        if ($channel->{type} ne "CHANNEL") {
                Irssi::print("Your are not on a channel");
                return;
        }

	for (split /\s+/, $data) {
                $channel->command("quote cs voice $channel->{name} $_");
        }
}

Irssi::command_bind('csva','cmd_csva');
Irssi::command_bind('csv','cmd_csv');
