#!/usr/bin/perl
#use strict;
# Copyright (c) 2006 SchAmane.  All rights reserved.  This
# program is free software; you may redistribute it and/or modify it
# under the same terms as Perl itself.

#This script gives everyone who join voice in channel you specify.

#my %Channels = ('#gnome-art', '1', '#mdg-clan', '1');
my %Channels = ('#mdg-clan', '1');
my %BeenDevoiced = ();
my $Wellcomemessage = 0;

Xchat::register("AutoVoice© ","1.1","AutoVoice on specific channell","");
Xchat::print("\0034AutoVoice 1.0 \0035 - By CrazyGoogle has been loaded");

Xchat::hook_print('Join',\&on_join);
Xchat::hook_print('Channel DeVoice',\&on_devoice);
Xchat::hook_print('Channel Voice',\&on_voice);

Xchat::print( "\0036Autovoice set for specific channel names:");
foreach $key (keys %Channels) 
{
   Xchat::print("\0036\t" . $key);
}

sub on_join{
	my $JoinNick = $_[0][0];
	my $JoinChannel = $_[0][1];
	if(exists $Channels{$JoinChannel} && not(exists $BeenDevoiced{$JoinNick})) {
		#send the welcome notice
		if(0 != $Wellcomemessage) {
			Xchat::command("notice $JoinNick Wellcome on $JoinChannel");
		}
		Xchat::command("voice $JoinNick");
		Xchat::print("\0032$JoinNick join channel $JoinChannel");
	}
	
sub on_devoice {
	$BeenDevoiced{$_[0][1]} = 1;
	}

sub on_voice {
	if(exists $BeenDevoiced{$_[0][1]}) {
		delete $BeenDevoiced{$_[0][1]};
	 }
	}
}
