Not a beauty, this code... A hash table instead of the variables and a smarter remove routine would prettify it a lot smile
I tested only a bit, hope it's all working.
Code:
menu channel {
  Temp Protection
  .$iif(($group(#autoprotection) == on),$style(1)) switch $qt(auto add/-remove) $iif(($group(#autoprotection) == on),off,on): $iif(($group(#autoprotection) == on),.disable,.enable) #autoprotection
  .-
  .temp-protect the nonreg users of $qt($active) now : add.protect $network $active
  .clear temp-protects of $qt($active) : rem.protect $network $active
  .clear temp-protects of $qt($network) : rem.protect $network net
  .clear all temp-protects : rem.protect
}

; group of events (menu switch)

#autoprotection on
; add temp protections if joining a chan
on me:*:join:#: { add.protect $network $chan }

; remove temp protections on kick/part/quit/disconnect/exit
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 }
#autoprotection end

; alias: add the nonreg users of a chan to temp protection 
alias 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
    }
  }
}

; alias: remove the protection of users added before
alias rem.protect {
  ; loop all variables
  var %nr = 1

  ; remove all temp entries 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 entries 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 entries
  else {
    while ($var(%tempprotect+*),%nr) {
      tokenize 43 $v1
      !protect -r $4 $3 $2
      inc %nr
    }
    ; unset all variables
    unset %tempprotect+*
  }

}

2 Notes:

1) The individual protect commands are not silenced yet (for you to check how it works). You can disable this output with ease: change the four occurrences of "!protect" to ".protect".

2) Atm, this will not add/remove protection on op/deop and the like, nor will it remove the protection entries of parting/quitting users.

Last edited by Horstl; 28/08/07 11:26 PM.