#OBF
# +-------------------------------------------------------------------------------------+
# |                                                                                     |
# |                         a&a (light) script v0.03.02 Alpha                           |
# |                                                                                     |
# +-------------------------------------------------------------------------------------+
# |                                                                                     |
# |             Creative Commons Copyright 2002-2005 by universalia aka aqwzsx          |
# |                               http://ascript.name                                   |
# |                                                                                     |
# +-------------------------------------------------------------------------------------+
# |                                                                                     |
# |        Project             @  http://ascript.name                                   |
# |        Forum               @  http://forum.ascript.name                             |
# |        Features request    @  http://features.ascript.name (category a&a)           |
# |        Support request     @  http://support.ascript.name (category a&a)            |
# |        Bugs report         @  http://bugs.ascript.name                              |
# |        CVS pserver         @  cvs.sourceforge.net:/cvsroot/scripting co -P a&a      |
# |        CVS Web repository  @  http://cvs.ascript.name (folder a&a)                  |
# |                                                                                     |
# +-------------------------------------------------------------------------------------+
# |                                                                                     |
# |                            #a&a @ Undernet/Quakenet IRC                             |
# |                                                                                     |
# +-------------------------------------------------------------------------------------+
############ Command Binds ###########################

a:command -add templeave  pub:templeave 1037 550 |n
a:command -add comeback   pub:comeback  1036 551 |n
a:command -add chanset    pub:chanset   1034 553 |n
a:command -add cycle      pub:cycle     1100 601 |n

############ Command Procs ###########################

proc pub:templeave {hand chan args x mix} {
	global settings

	set reason [join [lrange $args 0 end]]

	if {![isdynamic $chan]} { a:tell $x 129 $chan; return "FAILED: static chan ($chan)"}
	if { [channel get $chan inactive]} { a:tell $x 21 $chan; return "FAILED: chan already innactive ($chan)"}
	if { $reason == ""} { a:tell $x 19; return "FAILED: no reason supplied"}
	if { [check:m:gl $hand] && $settings(strict_reason) && ![a:check -reason [lindex $args 0]] } { a:tell $x 13; return "FAILED: invalid reason"}

	::stats::channel -set $chan templeavetime [unixtime] 
	::stats::channel -set $chan templeavewhom $hand
	::stats::channel -set $chan templeavewhy $reason 

	a:tell $x 122 $chan

	putquick "part $chan :templeft on demand of $hand, reason: $reason; for any help apply on $settings(suppchan) & \037\00302$settings(homepage)"
	channel set $chan +inactive
	return "$chan" 
}

proc pub:comeback {hand chan args x mix} {

	set mix [lindex $args 0]

	if {![channel get $chan inactive] && ![a:check -now $mix]} {a:tell $x 124 $chan ; return "FAILED: chan already active ($chan)"}
	if { [channel get $chan suspended]} {a:tell $x 127 $chan ; return "FAILED: chan suspended ($chan)"}
	channel set $chan -inactive
	putquick "join $chan";		     a:tell $x 123 $chan ; return "$chan"
}

proc pub:chanset {hand chan args x mix} {
	
	set mode   [string tolower [lindex $args 0]]
	set opti   [lindex $args 1]

	if {([regexp {^aop-delay|flood-(chan|deop|kick|join|nick|ctcp)$} $mode] && [regexp {^\d{1,2}\:\d{1,3}$} $opti]) || ([string equal $mode stopnethack-mode] && [string match {[0-6]} $opti]) || ([string equal $mode idle-kick] && [a:check -digit $opti]) || ([string equal -nocase $mode idle-deop] && [a:check -digit $opti])  || ([string equal $mode revenge-mode] && [string match {[0-3]} $opti]) || ([regexp {^(ban|exempt|invite)-time$} $mode] && [a:check -digit $opti])} {channel set $chan $mode $opti} elseif { 
	     [string equal $mode -inactive] && [channel get $chan suspended]} {a:tell $x 127 $chan ; return "FAILED: chan suspended ($chan)"} elseif {
	     [string equal $mode +suspended] && [check:m:gl $hand]} {channel set $chan +inactive +suspended} elseif {
	     [string equal $mode -suspended] && [check:m:gl $hand]} {channel set $chan -inactive -suspended} elseif {
	       [string equal $mode +antitake]} { channel set $chan chanmode +tn-ik revenge-mode 2 flood-chan 7:20 flood-ctcp 2:20 flood-join 4:40 flood-kick 3:20 flood-deop 3:20 flood-nick 4:40 ban-time 0 +enforcebans +dynamicbans +protectops -protectfriends -dontkickops +revenge +cycle -autoop -op +antitake} elseif {
             [string equal $mode -antitake]} { channel set $chan chanmode +tn revenge-mode 0 flood-chan 0:00 flood-ctcp 0:00 flood-join 0:00 flood-kick 0:00 flood-deop 0:00 flood-nick 0:00 ban-time 120 -enforcebans -dynamicbans -protectops -protectfriends -dontkickops -revenge -cycle -autoop -op -antitake } elseif {
             [string equal $mode +strict]} { channel set $chan +antipub +anticolour +antibold +antireverse +antiunderline +antiurl +antinotice +antiaction +antirepeat +strict} elseif {
             [string equal $mode -strict]} { channel set $chan -antipub -anticolour -antibold -antireverse -antiunderline -antiurl -antinotice -antiaction -antirepeat -strict} elseif {
             [string equal $mode +paranoia]} { pub:chanset $hand $chan "+antitake" $x $mix ; pub:chanset $hand $chan "+strict" $x $mix } elseif {
             [string equal $mode -paranoia]} { pub:chanset $hand $chan "-antitake" $x $mix ; pub:chanset $hand $chan "-strict" $x $mix } elseif {           
           [regexp {^[+-](auto(op|voice)|bitch|cycle|revenge(bot|)|dontkickops|nodesynch|(dynamic|enforce|user)bans|inactive|protect(friends|ops)|secret|greet|seen|anti(pub|take|swear|colour|bold|underline|notice|url|reverse|repeat|action|spam)|limit|secure|voice|op|enforcetopic|private|csc|weather|next|dns|putty|google|paranoia|strict|welcome|tools|leave|counter|away|silent|flyby)$} $mode]} {channel set $chan $mode} elseif { 
	     [regexp -- {^(rules|url|faq|fuck|news|desc|mail|slap|kiss|(ban|kick)-reason)$} $mode]} {if { [string equal $opti none] || $opti == ""} {set opti ""; a:tell $x 136 "$chan $mode"; ::stats::channel -set $chan $mode $opti; return "$mode none"} {set opti [join [lrange $args 1 end]]; ::stats::channel -set $chan $mode $opti}} elseif {	     [string equal $mode mode] || [string equal $mode modes] && [regexp {^[ntrimlkprs+-]+$} $opti]} {channel set $chan chanmode $opti} elseif {	
	     [string match {[-+]locked} $mode] && [check:N:gl $hand] } {channel set $chan $mode } else {a:help $x chanset ; return "FAILED: wrong options ($mode $opti)"}

	a:tell $x 126 "$chan $mode $opti"
	return "$mode $opti"
}

proc pub:cycle {hand chan args x mix} {
	global settings

	set time [lindex $args 0]

	if {![isdynamic $chan]} {a:tell $x 129 $chan; return "FAILED: static chan ($chan)"}
	if {![a:check -digit $time] || $time < 7 || $time > 72000} {set time 9}

	putquick "part $chan :cycling on demand of $hand, be back in $time seconds; for any help apply on $settings(suppchan) & \037\00302$settings(homepage)"
	channel set $chan +inactive
	utimer $time [list channel set $chan -inactive]
	return "$chan for $time"
}


return "local n commands"
#/OBF
