#
# --------( ServerJump by MonkeyBrains v1.0 )----------
#
#  special special!! thanks to    - TymezUp - 
#
#  this program will jump servers every 8 hrs 
#  to keep k-lines at a minimum
#  it ensures that the bot will regain ops before it changes servers
#  if it can't ensure a safe arival back on you channel(s)
#  it will check every 5 min until it can....

# ---------------(on with the script)------------------  
    
#  this command sets flag #5 to 'j'
#  the 'j' flag indicates users that you trust
#  to give ops back to the bot...
set flag5 j	

#  this value sets the time intervals that you want
#  the bot to change servers at
#  note: default is '480' = 8 hours		
timer 480 auto_jump		

proc auto_jump {} {
	global chan_ok bchan
	set chan_ok yes
	set botchan [channels]
	foreach bchan $botchan {
		if {[botisop $bchan]} {
		is_ok } 
	}
	if {$chan_ok != "no"} {
		putlog "jump timer reset"
		timer 480 auto_jump 
		jump 
	}
	if {$chan_ok != "yes"} {
		timer 5 auto_jump 
	}
}

proc is_ok {} {
	global bchan
	set jumpuser [userlist j]
	foreach handle $jumpuser {
	if { ([isop [hand2nick $handle $bchan] $bchan]) } {
		return 1 } }
	not_safe
}

proc not_safe {} {
	global chan_ok
	set chan_ok no
}

putlog "Y -- ServerJump -- Y v1.0"