Difference between revisions of "Clear-Chanlev Script for QuakeNet"

From Scriptwiki
Jump to: navigation, search
(Script updated to work with Q9. Tested with version 1.00)
m (disable the removing of owners, so Q is not removed.)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
; ClearChanlev script by doomie
+
; ClearChanlev script by doomie
;  #help.script @ QuakeNet
+
;  #help.script @ QuakeNet
;
+
;
;
+
;
; You can use this script by typing:
+
; You can use this script by typing:
;
+
;
;        /clearchanlev [-c|-r] #channel
+
;        /clearchanlev [-r] #channel
;  
+
;  
;  Note, that you must be authed and owner of #channel.  
+
;  Note, that you must be authed and owner of #channel.  
;
+
;
;  Flags:
+
;  Flags:
;          * -r ... Resets the script, i.e. cleans everything up. One usually doesn't need that flag, however, if something didn't work,
+
;          * -r ... Resets the script, i.e. cleans everything up. One usually doesn't need that flag, however, if something didn't work,
;                    one can use it.   
+
;                    one can use it.   
;           * -c ... If you use this flag, the script will remove you from the channel aswell. This means, that Q will leave the channel
+
;
;                    completly. Note that you can _NOT_ reverse it!
+
;
;
+
;  Example output:
;
+
;
;  Example output:
+
;      ClearChanlev: -----------------------------
;
+
;      ClearChanlev: Now beginning to remove all chanlevs from channel #channel except yours!
;      ClearChanlev: -----------------------------
+
;      ClearChanlev: Receiving own auth now!
;      ClearChanlev: Now beginning to remove all chanlevs from channel #channel except yours!
+
;      ClearChanlev: ...done.
;      ClearChanlev: Receiving own auth now!
+
;      ClearChanlev: Saving chanlev now...
;      ClearChanlev: ...done.
+
;      ClearChanlev: ...done.
;      ClearChanlev: Saving chanlev now...
+
;      ClearChanlev: There are 2 lines to send. This will take approximatly 4 seconds. Removing...
;      ClearChanlev: ...done.
+
;      ClearChanlev: ...done.
;      ClearChanlev: There are 2 lines to send. This will take approximatly 4 seconds. Removing...
+
;      ClearChanlev: Cleaned up!
;      ClearChanlev: ...done.
+
;      ClearChanlev: -----------------------------
;      ClearChanlev: Cleaned up!
+
;
;      ClearChanlev: -----------------------------
+
;
+
; Returns the milliseconds between every message sent to Q
 
+
; If you excess flood, you should increase this value to 4000 or even 5000.
; Returns the milliseconds between every message sent to Q
+
[[alias]] -l ClearChanlev.Delay { [[return]] 3000 }  
; If you excess flood, you should increase this value to 4000 or even 5000.
+
alias -l ClearChanlev.Delay { return 3000 }  
+
; $1 = #channel
 
+
;
; $1 = #channel
+
; flags:
;
+
;  -c --complete = deletes the complete chanlev, inclusive owner. This will
; flags:
+
;                  result in Q parting. This option is disabled.
;  -c --complete = deletes the complete chanlev, inclusive owner. This will
+
;  -r --reset    = resets the scripts in case something didn't work the last time.
;                  result in Q parting.
+
alias ClearChanlev {
;  -r --reset    = resets the scripts in case something didn't work the last time.
+
  [[echo]] -s ClearChanlev: -----------------------------
alias ClearChanlev {
+
  [[var]] %i = 1, %c, %ClearChanlev.Complete = 0, %r, %ClearChanlev.Force = 0, %ClearChanlev.Channel
  echo -s ClearChanlev: -----------------------------
+
  [[While loops|while]] (%i [[If#.3C.3D|<=]] [[$0]]) {
  var %i = 1, %c, %ClearChanlev.Complete = 0, %r, %ClearChanlev.Force = 0, %ClearChanlev.Channel
+
    %c = $ [[Evaluation_brackets|[]] [[DollarPlus|$+]] [[Evaluation_brackets|[]] %i [[Evaluation_brackets|] ]]]
  while (%i <= $0) {
+
    [[if]] (%c [[If#.3D.3D|==]] -c) [[If#Combining_comparisons|||]] (%c == --complete) {
    %c = $ [ $+ [ %i ] ]
+
      echo -s ClearChanlev: The %c option to remove Q is disabled, it is ignored.
    if (%c == -c) || (%c == --complete) {
+
      ; %ClearChanlev.Complete = 0
      %ClearChanlev.Complete = 1
+
    }
    }
+
    elseif (%c == -r) || (%c == --reset) {
    elseif (%c == -r) || (%c == --reset) {
+
      %ClearChanlev.Force = 1
      %ClearChanlev.Force = 1
+
    }
    }
+
    elseif ([[$left]](%c, 1) == [[$chr]](35)) {
    elseif ($left(%c, 1) == $chr(35)) {
+
      %ClearChanlev.Channel = %c
      %ClearChanlev.Channel = %c
+
    }
    }
+
    [[inc]] %i
    inc %i
+
  }
  }
+
  if (%ClearChanlev.Global) {
  if (%ClearChanlev.Global) {
+
    if (%ClearChanlev.Force == 0) {
    if (%ClearChanlev.Force == 0) {
+
      echo -s ClearChanlev: ClearChanlev is currently running. If this is not the case, please use the -r flag (i.e. /clearchanlev -r #channel)
      echo -s ClearChanlev: ClearChanlev is currently running. If this is not the case, please use the -r flag (i.e. /clearchanlev -r #channel)
+
      echo -s ClearChanlev: -----------------------------
      echo -s ClearChanlev: -----------------------------
+
      return
      return
+
    }
    }
+
    else {
    else {
+
      [[unset]] %ClearChanlev.Global
      unset %ClearChanlev.Global
+
      echo -s ClearChanlev: ClearChanlev reseted.
      echo -s ClearChanlev: ClearChanlev reseted.
+
    }
    }
+
  }
  }
+
  if (!%ClearChanlev.Channel) {
  if (!%ClearChanlev.Channel) {
+
    echo -s ClearChanlev: No channel specified.
    echo -s ClearChanlev: No channel specified.
+
    return
    return
+
  }
  }
+
  %r = [[$rand]](1,1000)
  %r = $rand(1,1000)
+
  [[set]] %ClearChanlev.Global %ClearChanlev.Channel %ClearChanlev.Complete %r
  set %ClearChanlev.Global %ClearChanlev.Channel %ClearChanlev.Complete %r
+
  echo -s ClearChanlev: Now beginning to remove all chanlevs from channel %ClearChanlev.Channel [[$iif]](%ClearChanlev.Complete, inclusive, except) yours!
  echo -s ClearChanlev: Now beginning to remove all chanlevs from channel %ClearChanlev.Channel $iif(%ClearChanlev.Complete, inclusive, except) yours!
+
  echo -s ClearChanlev: Receiving own auth now!
  echo -s ClearChanlev: Receiving own auth now!
+
  .[[timer]]ClearChanlevCleanUp 1 60 ClearChanlev.CleanUp
  .timerClearChanlevCleanUp 1 60 ClearChanlev.CleanUp
+
  .[[who]] [[$me]] n%nat, $+ %r
  .who $me n%nat, $+ %r
+
}
}
+
 
+
[[:Category:Raws|raw]] [[Raw_354|354]]:*: {
raw 354:*: {
+
  if ([[$1-|$2]] == [[$gettok]](%ClearChanlev.Global, 3, 32)) && ($3 == $me) {
  if ($2 == $gettok(%ClearChanlev.Global, 3, 32)) && ($3 == $me) {
+
    haltdef
    haltdef
+
    set %ClearChanlev.Global %ClearChanlev.Global $4
    set %ClearChanlev.Global %ClearChanlev.Global $4
+
  }
  }
+
}
}
+
 
+
raw [[Raw_315|315]]:*: {
raw 315:*: {
+
  if (%ClearChanlev.Global) && ($2 == $me) {
  if (%ClearChanlev.Global) && ($2 == $me) {
+
    [[haltdef]]
    haltdef
+
    if ($gettok(%ClearChanlev.Global, 4, 32) == 0) {
    if ($gettok(%ClearChanlev.Global, 4, 32) == 0) {
+
      echo -s ClearChanlev: You are NOT authed.
      echo -s ClearChanlev: You are NOT authed.
+
      ClearChanlev.CleanUp
      ClearChanlev.CleanUp
+
    }  
    }  
+
    else {
    else {
+
      echo -s ClearChanlev: ...done.
      echo -s ClearChanlev: ...done.
+
      set %ClearChanlev.Global %ClearChanlev.Global 0
      set %ClearChanlev.Global %ClearChanlev.Global 0
+
      .[[msg]] Q chanlev $gettok(%ClearChanlev.Global, 1, 32)
      .msg Q chanlev $gettok(%ClearChanlev.Global, 1, 32)
+
    }
    }
+
  }
  }
+
}
}
+
 
+
alias -l ClearChanlev.GotMessages {
alias -l ClearChanlev.GotMessages {
+
  if (![[$exists]](ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt)) {
  if (!$exists(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt)) {
+
    echo -s ClearChanlev: File does not exist!
    echo -s ClearChanlev: File does not exist!
+
    ClearChanlev.CleanUp
    ClearChanlev.CleanUp
+
    return
    return
+
  }
  }
+
  if ([[$lines]](ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) == 0) {
  if ($lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) == 0) {
+
    echo -s ClearChanlev: No chanlev to remove!
    echo -s ClearChanlev: No chanlev to remove!
+
    ClearChanlev.CleanUp
    ClearChanlev.CleanUp
+
    return
    return
+
  }
  }
+
  if ($gettok(%ClearChanlev.Global, 5, 32) == 0) {
  if ($gettok(%ClearChanlev.Global, 5, 32) == 0) {
+
    echo -s ClearChanlev: You are NOT owner of this channel. Aborting!
    echo -s ClearChanlev: You are NOT owner of this channel. Aborting!
+
    ClearChanlev.CleanUp
    ClearChanlev.CleanUp
+
    return
    return
+
  }
  }
+
  echo -s ClearChanlev: There are $lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) lines to send. This will take [[$&]]
  echo -s ClearChanlev: There are $lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) lines to send. This will take $&
+
    approximatly $calc($lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) * $ClearChanlev.Delay / 1000) seconds. Removing...  
    approximatly $calc($lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) * $ClearChanlev.Delay / 1000) seconds. Removing...  
+
  .[[play]] Q ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt $ClearChanlev.Delay
  .play Q ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt $ClearChanlev.Delay
+
}
}
+
 
+
alias -l ClearChanlev.CleanUp {
alias -l ClearChanlev.CleanUp {
+
  .[[remove]] ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt
  .remove ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt
+
  unset %ClearChanlev.*
  unset %ClearChanlev.*
+
  .timerClearChanlevCleanUp off
  .timerClearChanlevCleanUp off
+
  echo -s ClearChanlev: Cleaned up!
  echo -s ClearChanlev: Cleaned up!
+
  echo -s ClearChanlev: -----------------------------
  echo -s ClearChanlev: -----------------------------
+
}
}
+
 
+
; $1- = message from Q
; $1- = message from Q
+
alias -l ClearChanlev.Interpret {
alias -l ClearChanlev.Interpret {
+
  if (%ClearChanlev.Global) {
  if (%ClearChanlev.Global) {
+
    if (Username*Flags*Last join*Last changed iswm $1-) {
    if (Username*Flags*Last join*Last changed iswm $1-) {
+
      echo -s ClearChanlev: Saving chanlev now...
      echo -s ClearChanlev: Saving chanlev now...
+
      set %ClearChanlev.Global %ClearChanlev.Global 1
      set %ClearChanlev.Global %ClearChanlev.Global 1
+
    }
    }
+
    elseif (You do not have sufficient access on* iswm $1-) {
    elseif (You do not have sufficient access on* iswm $1-) {
+
      echo -s ClearChanlev: You do not have sufficied access on the specified channel!
      echo -s ClearChanlev: You do not have sufficied access on the specified channel!
+
      ClearChanlev.CleanUp
      ClearChanlev.CleanUp
+
    }
    }
+
    elseif (End of list. == $1-) {  
    elseif (End of list. == $1-) {  
+
      echo -s ClearChanlev: ...done.
      echo -s ClearChanlev: ...done.
+
      set %ClearChanlev.Global [[$puttok]](%ClearChanlev.Global, 0, 6, 32)
      set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 0, 6, 32)
+
      if ([[$numtok]](%ClearChanLev.Users,32)) {
      if ($numtok(%ClearChanLev.Users,32)) {
+
        [[write]] -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanLev.Users
        write ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanLev.Users
+
        unset %ClearChanlev.Users
        unset %ClearChanlev.Users
+
      }
      }
+
      ClearChanlev.GotMessages
      ClearChanlev.GotMessages
+
    }
    }
+
    elseif (Channel * is unknown or suspended. iswm $1-) {
    elseif (Channel * is unknown or suspended. iswm $1-) {
+
      echo -s ClearChanlev: Channel is not known or suspended. Aborting.
      echo -s ClearChanlev: Channel is not known or suspended. Aborting.
+
      ClearChanlev.CleanUp
      ClearChanlev.CleanUp
+
    }
    }
+
    elseif ($gettok(%ClearChanlev.Global, 6, 32) == 1) {
    elseif ($gettok(%ClearChanlev.Global, 6, 32) == 1) {
+
      if ($1 == $gettok(%ClearChanlev.Global, 4, 32)) {
      if ($1 == $gettok(%ClearChanlev.Global, 4, 32)) {
+
        if (n !isin $2) {
        if (n !isin $2) {
+
          set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 0, 5, 32)
          set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 0, 5, 32)
+
          return
          return
+
        }
        }
+
        else {
        else {
+
          set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 1, 5, 32)
          set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 1, 5, 32)
+
        }
        }
+
 
+
        if ($gettok(%ClearChanlev.Global, 2, 32) == 0) {
        if ($gettok(%ClearChanlev.Global, 2, 32) == 0) {
+
          return
          return
+
        }
        }
+
        else {
        else {
+
          write ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 [[$replace]]($2,+,-)
          write ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 $replace($2,+,-)
+
          return
          return
+
        }
        }
+
      }
      }
+
      else {
      else {
+
        if (n isin $2) {
        if (n isin $2) {
+
          ; do not remove owners - do not change unless you know what you are doing!
          write ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 $replace($2,+,-)
+
          return
        }
+
          ; write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 $replace($2,+,-)
        else {
+
        }
          set %ClearChanlev.Users $addtok(%ClearChanLev.users,$chr(35) $+ $1,32)
+
        else {
          if ($numtok(%ClearChanlev.Users,32) == 18) {
+
          set %ClearChanlev.Users $addtok(%ClearChanLev.users,$chr(35) $+ $1,32)
            write ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanlev.Users
+
          if ($numtok(%ClearChanlev.Users,32) == 18) {
            unset %ClearChanlev.Users
+
            write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanlev.Users
          }
+
            unset %ClearChanlev.Users
        }
+
          }
      }
+
        }
    }
+
      }
  }
+
    }
}
+
  }
 
+
}
on ^*:Notice:*:?: {
+
  if ($nick == Q) && (%ClearChanlev.Global) {
+
on ^*:[[On_notice|Notice]]:*:?: {
    haltdef
+
  if ([[$nick]] == Q) && (%ClearChanlev.Global) {
    ClearChanlev.Interpret $1-
+
    haltdef
  }
+
    ClearChanlev.Interpret $1-
}
+
  }
 
+
}
on ^*:Text:*:?: {
+
  if ($nick == Q) && (%ClearChanlev.Global) {
+
on ^*:[[On_text|Text]]:*:?: {
    haltdef
+
  if ($nick == Q) && (%ClearChanlev.Global) {
    ClearChanlev.Interpret $1-
+
    haltdef
  }
+
    ClearChanlev.Interpret $1-
}
+
  }
 
+
}
on *:PLAYEND:{
+
  if ($nopath($filename) == ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) {
+
on *:[[On_playend|PLAYEND]]:{
    echo -s ClearChanlev: ...done.
+
  if ([[$nopath]]([[$filename]]) == ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) {
    ClearChanlev.Cleanup
+
    echo -s ClearChanlev: ...done.
  }
+
    ClearChanlev.Cleanup
}
+
  }
 +
}
 
[[Category:Script Archive]]
 
[[Category:Script Archive]]
 
{{Author|Doomie}}
 
{{Author|Doomie}}

Latest revision as of 23:24, 9 April 2010

; ClearChanlev script by doomie
;   #help.script @ QuakeNet
;
;
; You can use this script by typing:
;
;        /clearchanlev [-r] #channel
; 
;   Note, that you must be authed and owner of #channel. 
;
;   Flags:
;           * -r ... Resets the script, i.e. cleans everything up. One usually doesn't need that flag, however, if something didn't work,
;                    one can use it.  
;
;
;   Example output:
;
;      ClearChanlev: -----------------------------
;      ClearChanlev: Now beginning to remove all chanlevs from channel #channel except yours!
;      ClearChanlev: Receiving own auth now!
;      ClearChanlev: ...done.
;      ClearChanlev: Saving chanlev now...
;      ClearChanlev: ...done.
;      ClearChanlev: There are 2 lines to send. This will take approximatly 4 seconds. Removing...
;      ClearChanlev: ...done.
;      ClearChanlev: Cleaned up!
;      ClearChanlev: -----------------------------
;

; Returns the milliseconds between every message sent to Q
; If you excess flood, you should increase this value to 4000 or even 5000.
alias -l ClearChanlev.Delay { return 3000 } 

; $1 = #channel
;
; flags:
;   -c --complete = deletes the complete chanlev, inclusive owner. This will
;                   result in Q parting. This option is disabled.
;   -r --reset    = resets the scripts in case something didn't work the last time.
alias ClearChanlev {
  echo -s ClearChanlev: -----------------------------
  var %i = 1, %c, %ClearChanlev.Complete = 0, %r, %ClearChanlev.Force = 0, %ClearChanlev.Channel
  while (%i <= $0) {
    %c = $ [ $+ [ %i ] ]
    if (%c == -c) || (%c == --complete) {
      echo -s ClearChanlev: The %c option to remove Q is disabled, it is ignored.
      ; %ClearChanlev.Complete = 0
    }
    elseif (%c == -r) || (%c == --reset) {
      %ClearChanlev.Force = 1
    }
    elseif ($left(%c, 1) == $chr(35)) {
      %ClearChanlev.Channel = %c
    }
    inc %i
  }
  if (%ClearChanlev.Global) {
    if (%ClearChanlev.Force == 0) {
      echo -s ClearChanlev: ClearChanlev is currently running. If this is not the case, please use the -r flag (i.e. /clearchanlev -r #channel)
      echo -s ClearChanlev: -----------------------------
      return
    }
    else {
      unset %ClearChanlev.Global
      echo -s ClearChanlev: ClearChanlev reseted.
    }
  }
  if (!%ClearChanlev.Channel) {
    echo -s ClearChanlev: No channel specified.
    return
  }
  %r = $rand(1,1000)
  set %ClearChanlev.Global %ClearChanlev.Channel %ClearChanlev.Complete %r
  echo -s ClearChanlev: Now beginning to remove all chanlevs from channel %ClearChanlev.Channel $iif(%ClearChanlev.Complete, inclusive, except) yours!
  echo -s ClearChanlev: Receiving own auth now!
  .timerClearChanlevCleanUp 1 60 ClearChanlev.CleanUp
  .who $me n%nat, $+ %r
}

raw 354:*: {
  if ($2 == $gettok(%ClearChanlev.Global, 3, 32)) && ($3 == $me) {
    haltdef
    set %ClearChanlev.Global %ClearChanlev.Global $4
  }
}

raw 315:*: {
  if (%ClearChanlev.Global) && ($2 == $me) {
    haltdef
    if ($gettok(%ClearChanlev.Global, 4, 32) == 0) {
      echo -s ClearChanlev: You are NOT authed.
      ClearChanlev.CleanUp
    } 
    else {
      echo -s ClearChanlev: ...done.
      set %ClearChanlev.Global %ClearChanlev.Global 0
      .msg Q chanlev $gettok(%ClearChanlev.Global, 1, 32)
    }
  }
}

alias -l ClearChanlev.GotMessages {
  if (!$exists(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt)) {
    echo -s ClearChanlev: File does not exist!
    ClearChanlev.CleanUp
    return
  }
  if ($lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) == 0) {
    echo -s ClearChanlev: No chanlev to remove!
    ClearChanlev.CleanUp
    return
  }
  if ($gettok(%ClearChanlev.Global, 5, 32) == 0) {
    echo -s ClearChanlev: You are NOT owner of this channel. Aborting!
    ClearChanlev.CleanUp
    return
  }
  echo -s ClearChanlev: There are $lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) lines to send. This will take $&
    approximatly $calc($lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) * $ClearChanlev.Delay / 1000) seconds. Removing... 
  .play Q ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt $ClearChanlev.Delay
}

alias -l ClearChanlev.CleanUp {
  .remove ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt
  unset %ClearChanlev.*
  .timerClearChanlevCleanUp off
  echo -s ClearChanlev: Cleaned up!
  echo -s ClearChanlev: -----------------------------
}

; $1- = message from Q
alias -l ClearChanlev.Interpret {
  if (%ClearChanlev.Global) {
    if (Username*Flags*Last join*Last changed iswm $1-) {
      echo -s ClearChanlev: Saving chanlev now...
      set %ClearChanlev.Global %ClearChanlev.Global 1
    }
    elseif (You do not have sufficient access on* iswm $1-) {
      echo -s ClearChanlev: You do not have sufficied access on the specified channel!
      ClearChanlev.CleanUp
    }
    elseif (End of list. == $1-) { 
      echo -s ClearChanlev: ...done.
      set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 0, 6, 32)
      if ($numtok(%ClearChanLev.Users,32)) {
        write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanLev.Users
        unset %ClearChanlev.Users
      }
      ClearChanlev.GotMessages
    }
    elseif (Channel * is unknown or suspended. iswm $1-) {
      echo -s ClearChanlev: Channel is not known or suspended. Aborting.
      ClearChanlev.CleanUp
    }
    elseif ($gettok(%ClearChanlev.Global, 6, 32) == 1) {
      if ($1 == $gettok(%ClearChanlev.Global, 4, 32)) {
        if (n !isin $2) {
          set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 0, 5, 32)
          return
        }
        else {
          set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 1, 5, 32)
        }

        if ($gettok(%ClearChanlev.Global, 2, 32) == 0) {
          return
        }
        else {
          write ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 $replace($2,+,-)
          return
        }
      }
      else {
        if (n isin $2) {
          ; do not remove owners - do not change unless you know what you are doing!
          return
          ; write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 $replace($2,+,-)
        }
        else {
          set %ClearChanlev.Users $addtok(%ClearChanLev.users,$chr(35) $+ $1,32)
          if ($numtok(%ClearChanlev.Users,32) == 18) {
            write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanlev.Users
            unset %ClearChanlev.Users
          }
        }
      }
    }
  }
}

on ^*:Notice:*:?: {
  if ($nick == Q) && (%ClearChanlev.Global) {
    haltdef
    ClearChanlev.Interpret $1-
  }
}

on ^*:Text:*:?: {
  if ($nick == Q) && (%ClearChanlev.Global) {
    haltdef
    ClearChanlev.Interpret $1-
  }
}

on *:PLAYEND:{
  if ($nopath($filename) == ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) {
    echo -s ClearChanlev: ...done.
    ClearChanlev.Cleanup
  }
}
Contributed by Doomie