#!/usr/bin/perl

##### 'PowerScript' script developed by the-me on irc.quakenet.org ( #Linux-Dev ) Version 1.3
##### This program is free software; you can redistribute it and/or modify
##### it under the terms of the GNU General Public License as published by
##### the Free Software Foundation; either version 2 of the License, or
##### (at your option) any later version.
##### This program is distributed in the hope that it will be useful,
##### but WITHOUT ANY WARRANTY; without even the implied warranty of
##### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##### GNU General Public License for more details.
##### You should have received a copy of the GNU General Public License
##### along with this program; if not, write to the Free Software
##### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

### Xchat registers and hooks.

Xchat::register("irc.quakenet.org:6667 #Linux-Dev Power Script for XChat", "1.3", "This is the /power Perlscript for XChat", "");
Xchat::print"» Loaded PowerScript Version 1.3 from 'the-me' on irc.quakenet.org @ #Linux-Dev - Try /power. «";
Xchat::hook_command("power", "power_main");

use warnings;
use strict;

### Main routine.

sub power_main {
	my $opped = my $whole = my $networks = my $oppedchans = my $wholechannels = 0;
	my $oldcontext = Xchat::get_context();
	my @channels = Xchat::get_list('channels');
	foreach my $temp (@channels){
		my $type = $temp->{'type'};
		if($type == 1){
			$networks++;
		}
		elsif($type == 2){
			my $chan = $temp->{'channel'};
			Xchat::set_context("$chan");
			my $userinfo = Xchat::user_info();
			if($userinfo->{'prefix'} =~ /^[@~&\!]$/){
				my $users = Xchat::get_list('users');
				$oppedchans++;
				$wholechannels++;
				$opped = $opped+$users;
				$whole = $whole+$users;
			} else {
				my $uopusers = Xchat::get_list('users');
				$wholechannels++;
				$whole = $whole+$uopusers;
			}
		}
	}
	Xchat::set_context("$oldcontext");
	Xchat::command("say I'm opped in $oppedchans/$wholechannels channels on $networks network/s. I've got the power about $opped/$whole users.");
	return 1;
}

#####
##### That's all, folks!
#####