rendered paste bodyforeach user [bncuserlist] {
if { ![file exists "users/$user.aop"]} {
set aopfile [open "users/$user.aop" a+]
close $aopfile
}
}
internalbind server autoop:do
internalbind client autoop:client
proc autoop:do {client parameters} {
if {[string equal -nocase [lindex $parameters 1] "JOIN"]} {
set whom [lindex $parameters 0]
set where [lindex $parameters 2]
set exists [check:aop $client $where $whom]
if {$exists} {
set nick [lindex [split $whom !] 0]
puthelp "MODE $where +o $nick"
bncnotc "$nick matches autoop, opped on $where."
}
}
}
proc autoop:client {client parameters} {
if {[string equal -nocase "addautoop" [lindex $parameters 0]]} {
if {[llength $parameters] < 3} {
bncnotc "Syntax: /addautoop <#channel> <nick!ident@host.mask>"
} else {
set where [lindex $parameters 1]
set whom [lindex $parameters 2]
set exists [check:aop $client $where $whom]
if {$exists} { bncnotc "Auto-op for $whom on $where already exists."; return }
set aopfile [open "users/$client.aop" a+]
puts $aopfile "$where $whom"
close $aopfile
bncnotc "Added auto-op for $whom on $where."
}
haltoutput
} elseif {[string equal -nocase "listautoops" [lindex $parameters 0]]} {
set aopfile [open "users/$client.aop" r]
set count 0
while { [gets $aopfile line] >= 0 } {
bncnotc "#$count: autoop on [lindex $line 0] for [lindex $line 1]"
incr count
}
close $aopfile
haltoutput
} elseif {[string equal -nocase "delautoop" [lindex $parameters 0]]} {
if {[llength $parameters] < 2} {
bncnotc "Syntax: /delautoop <number>"
} else {
set number [lindex $parameters 1]
set aopfile [open "users/$client.aop" r]
set count 0
while { [gets $aopfile line] >= 0 } {
set aops($count) $line
incr count
}
close $aopfile
bncnotc "Deleted auto-op with number $number."
set aopfile [open "users/$client.aop" w]
for {set i 0} {$i < $count} {incr i} {
if {$i != $number} {
bncnotc "#$i: autoop on [lindex $aops($i) 0] for [lindex $aops($i) 1]"
puts $aopfile "[lindex $aops($i) 0] [lindex $aops($i) 1]"
}
}
close $aopfile
haltoutput
}
}
}
proc check:aop {client chan mask} {
set aopfile [open "users/$client.aop" r]
while { [gets $aopfile line] >= 0 } {
if {[string match -nocase [lindex $line 0] $chan] && [string match -nocase [lindex $line 1] $mask]} { return 1 }
}
close $aopfile
return 0
haltoutput
}
internalbind command sbnc:autoop
proc sbnc:autoop {client parameters} {
set command [lindex $parameters 0]
if {[string equal -nocase $command "addautoop"]} { autoop:client $client $parameters }
if {[string equal -nocase $command "delautoop"]} { autoop:client $client $parameters }
if {[string equal -nocase $command "listautoops"]} { autoop:client $client $parameters }
}