# version_check.tcl 2.0					
#
# Queries the joining users in the specified channel
# Kickban if the reply matches Bottler clients
# Messages MIRC users a channel Password
# Kickban MIRC users who don't reply with password

# Channel to query
set version_channel "#channel"

# Bindings for join, reply, and manual checking
bind join - "$version_channel *" join:version_check
bind ctcr - version reply:version_check
bind dcc - version list:version_check

# Send out the version request
proc join:version_check { nick host hand channel } {
	putserv "PRIVMSG $nick :\001VERSION\001"
}

# Process the version reply
proc reply:version_check { nick host hand dest keyword text } {
	global version_channel
	
	set reply [string tolower $text]
	if { [string match "*bottler*build*" "$reply"] } {
		putlog "$nick found with Bottler: $text"
		
		# Commence with the kickban
		putquick "MODE $version_channel +b [maskhost $host]"
		putquick "KICK $version_channel $nick :Bottler isn't welcome here."
		
		# Set the ban in the bot
		newchanban $version_channel [maskhost $host] Automatic "Bottler isn't welcome here."
	}
}




# Process the version reply for mirc	
proc reply:version_check { nick host hand dest keyword text } {
	global version_channel
	set ch_pass "0u812"
	set botnick "whatever"
	set channel "#channel"

	set reply [string tolower $text]
	if { [string match "*mirc*" "$reply"] } {
		putserv "PRIVMSG $nick :Channel Password $ch_pass"
		putserv "PRIVMSG $nick : Type /msg $botnick password <channel password> (In 2 minute you will be ban, if you don't reply)"
		set timer_id [utimer 120 [list pass_ck $nick $host $hand &text]]
	}
}

#process the Password reply
bind msg - password pass_ck
proc pass_ck { nick host hand text } { 
	global version_channel
	set ch_pass "0u812"
	
	if { $text == "$ch_pass"} { 
		putserv "PRIVMSG $nick :Password accepted"
		putlog "$nick Password accepted" } {
		# Commence with the kickban
		putlog "$nick did not reply or pass was wrong"
		putserv "PRIVMSG $nick :Wrong password or no reply"
		putquick "MODE $version_channel +b [maskhost $host]"
		putquick "KICK $version_channel $nick :Scripts are not welcome here."

		# Set the ban in the bot
		newchanban $version_channel [maskhost $host] Automatic "Did not respond with password ..  XDCC Downloaders/Scripts are not welcome here."
	}

}

# Manually query a user or the channel, if blank
proc list:version_check { hand idx target args } {
	global version_channel

	if { $target == "" } {
		# Blank, query the channel instead
		set target $version_channel
	}

		putlog "Checking $target for Bottler"
		putserv "PRIVMSG $target :\001VERSION\001"
}

putlog "Now monitoring $version_channel for Sctipts, XDCC downloaders and Bottler clients..."
