; ---------- menu ----------
menu channel,nicklist {
$iif((!$protect),$style(2)) Temp Protection $iif((!$protect),[disabled])
; toggle auto add/remove
.$iif(($group(#autoprotection) == on),$style(1)) switch $qt(auto add/-remove) $iif(($group(#autoprotection) == on),OFF,ON) : {
$iif(($group(#autoprotection) == on),.disable,.enable) #autoprotection
}
.-
; add/remove single users
.$iif(($check.protect($$1,$active,$network)),$style(1) REMOVE,ADD) protection for user $qt($$1) on $qt($active) : {
$iif(($check.protect($$1,$active,$network)),rem.single.protect,add.single.protect) $network $active $$1
}
.-
; add/remove all nonreg users of a chan
.ADD temp-protecs for nonreg users of $qt($active) : add.protect $network $active
.REMOVE temp-protects of $qt($active) : rem.protect $network $active
.-
; remove all network entries
.CLEAR temp-protects of network $qt($network) : rem.protect $network net
; remove all entries
.CLEAR ALL temp-protects : rem.protect
}
; ---------- events ----------
; group (switch): automated protection events
#autoprotection off
; add temp protections if you're joining a chan
on me:*:join:#: { add.protect $network $chan }
; add temp protection if v/h/o is granted
on *:op:#: { add.single.protect $network $chan $opnick }
on *:help:#: { add.single.protect $network $chan $hnick }
on *:voice:#: { add.single.protect $network $chan $vnick }
; remove temp protections on kick/part/quit/disconnect/exit (you)
on *:kick:#: { if ($knick == $me) rem.protect $network $chan }
on me:*:part:#: { rem.protect $network $chan }
on me:*:quit: { rem.protect $network net }
on *:disconnect: { rem.protect $network net }
on *:exit: { rem.protect }
;remove temp protections on part/quit (protected users)
on !*:part:#: { rem.single.protect $network $chan $nick }
on !*:quit: { rem.single.protect $network * $nick }
#autoprotection end
; ---------- aliases ----------
; return whether or not a user is protected on that chan and network
; note: checking protections, not vars for tempprotections!
alias -l check.protect {
var %nr = 1, %address = $address($1,2)
while ($protect(%nr)) {
if (($v1 == %address) && ($istok($protect(%nr).type,$2,44)) && ($protect(%nr).network == $3)) { return %nr }
inc %nr
}
}
; add a temp protection
alias -l add.single.protect {
!protect $3 $2 2 $1
set $+(%,tempprotect+,$1,+,$2,+,$address($3,2))
}
; add all nonreg users of a chan to temp protection
alias -l add.protect {
if ($me ison $2) {
; ial for that chan is up to date:
if ($chan($2).ial) {
var %nr = 1
; loop all "regular" users
while ($nick($2,%nr,a,r)) {
!protect $v1 $2 2 $1
; set a variable for this protect entry/switch
set $+(%,tempprotect+,$1,+,$2,+,$address($v1,2))
inc %nr
}
}
; ial is not up to date: update ial, and try again
else {
.who $2
.timer 1 10 add.protect $network $2
}
}
}
; remove a temp protection
alias -l rem.single.protect {
if ($var($+(%,tempprotect+,$1,+,$2,+,$address($3,2)),1)) {
tokenize 43 $v1
!protect -r $4 $3 $2
unset $v1
}
else { echo -c info $2 The protection for $3 on $2 $+([,$1,]) was not added temporarily - remove it manually. }
}
; remove protections of users added before
alias -l rem.protect {
; loop all variables
var %nr = 1
; remove all temp protections of a chan
if ($2 != net) {
var %net = $1, %chan = $2
while ($var($+(%,tempprotect+,%net,+,%chan,+*),%nr)) {
tokenize 43 $v1
!protect -r $4 $3 $2
inc %nr
}
; unset the variables for that chan
unset $+(%,tempprotect+, [ %net ] ,+, [ %chan ] ,+*)
}
; remove all temp protections of a network
elseif ($2 == net) {
var %net = $1
while ($var($+(%,tempprotect+,%net,+*),%nr)) {
tokenize 43 $v1
!protect -r $4 $3 $2
inc %nr
}
; unset the variables for that net
unset $+(%,tempprotect+, [ %net ] ,+*)
}
; remove all temp protections
else {
while ($var(%tempprotect+*),%nr) {
tokenize 43 $v1
!protect -r $4 $3 $2
inc %nr
}
; unset all variables
unset %tempprotect+*
}
}
; ---------- end ----------