#!/usr/bin/perl -w


sub foncts(@)
{
	($chan,$fullpower,$nick,$texte) = ($_[0],$_[1],$_[2],$_[3]);
if ($texte =~ /\@time/) { print "PRIVMSG $chan :: Feignant!
"; }
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@op (.*)/) { 
		print "mode $chan +o $1\n";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@say (.*)/) { 
		print "PRIVMSG $chan :$1\n"; #chr(2) = Gras
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@chan (\#\w+)/) { 
			print "PART $chan :chan\n";
			$chan = $1;
			print "JOIN $chan\n";
		
			open(NICK_OPEN,"config");
			my @temp_nick = <NICK_OPEN>;
			close NICK_OPEN;
		
			open(NICK_WRITE,">config");
			foreach(@temp_nick)
			{
				if (/^\$chan/) { print NICK_WRITE "\$chan=\"$chan\";\n"; }
				else { print NICK_WRITE "$_"; }
			}
			close NICK_WRITE;
			
		
		
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@cycle/) { 
			print "PART $chan\n";
			print "JOIN $chan\n";
		
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@directcom (.*)/) { 
		print STDOUT "\n\n /\$\\DIRECTOM! /\$\\  $1\n\n";
		print "$1\n";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@join/) { 
		join_chan;
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@k (.*)/) { 
		print "KICK $chan $1 :c bon?";
		
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@kb (.*)/) { 
		my $temp_kb = $1;
		
		print "KICK $chan ".(split " ",$temp_kb)[0]." :non mais, on se croit ou la?\n";
		print "MODE  $chan +b $temp_kb*!*\@*\n";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@nick (\w+)/) { 
			$bot_nick = $1;
			print "NICK :$bot_nick\n";
		
			open(NICK_OPEN,"config");
			my @temp_nick = <NICK_OPEN>;
			close NICK_OPEN;
		
			open(NICK_WRITE,">config");
			foreach(@temp_nick)
			{
				if (/bot_nick/) { print NICK_WRITE "\$bot_nick=\"$bot_nick\";\n"; }
				else { print NICK_WRITE "$_"; }
			}
			close NICK_WRITE;
			
		
		
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@part/) { 
		print "PART $chan :1 bot less";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@perldoc/) { 
		print "PRIVMSG $chan :PERLDOC site url ....";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@quit/) { 
		print "PART $chan :1 bot less\n";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@reload/) { 
			foreach(split(" ",$fichiers_a_charger))
			{
				print STDOUT "$_\t";
				do "$_" or print "PRIVMSG $chan :[ERREUR] $!";
				print STDOUT "[OK]\n";
			}
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@site/) { 
		print "PRIVMSG $chan :Site de \#perl: http://les-bonbons.homelinux.net/home.pl\n";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@topic (.*)/) { 
		print "TOPIC $chan :$1\n";
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@users/) { 
		open (INFO,"/home/tfe/truc/newirc/datanick/full.dat") or print STDOUT "$chan :error=> $!\n";
		while (<INFO>)
		{
		print "PRIVMSG $chan :$_\n";
		}
		close USER;
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@figlet (\w*)/) { 
		
		@affiche=qx/figlet $1/;
		foreach (@affiche)
		{
		print "privmsg $chan :$_\n";
		}
	}
	elsif ($fullpower =~ / $nick / and $texte =~ /^\@allow ([^\s]*)/) { 
			$ajout = $1;
			
			if (\$fullpower !~ / \$ajout /) 
			{
			    print "PRIVMSG $chan :Ajout de $1 pour le controle du bot.\n";
			    
		
			    open(CONF_OPEN,"config");
			    my @temp_nick = <CONF_OPEN>;
			    close CONF_OPEN;
			
		
			    open(CONF_WRITE,">config");
			    foreach(@temp_nick)
			    {
			  	if (/^\$fullpower/) { print CONF_WRITE "\$fullpower=\"$fullpower$ajout \";\n"; }
			 	else { print CONF_WRITE "$_"; }
			    }
			    close CONF_WRITE;
			}
			else 
			{
			    print "PRIVMSG $chan :$1 a deja le pouvoir :)\n";	
			}
			
		
		
	}
}  
 return 1;