#!/usr/bin/perl

Xchat::register("OPPPowerScript", "Version 0.1", "OPStatus Script", "OPStatus Script");
Xchat::print"Â» OPPPowerScript Version 0.1 geladen - Befehl: /power. Â«";
Xchat::hook_command("power", "power_main");

use warnings;
use strict;


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 9ist OP in4 $oppedchans 9von4 $wholechannels 9Channels, auf4 $networks 9Network/s und hat Macht über4 $opped 9von4 $whole 9User/n.");
	return 1;
}
