Public paste
clearchanlev
By: sc | Date: Aug 6 2009 12:38 | Format: None | Expires: never | Size: 7.25 KB | Hits: 1220

  1. ; ClearChanlev script by doomie
  2. ;   #help.script @ QuakeNet
  3. ;
  4. ;
  5. ; You can use this script by typing:
  6. ;
  7. ;        /clearchanlev [-c|-r] #channel
  8. ;
  9. ;   Note, that you must be authed and owner of #channel.
  10. ;
  11. ;   Flags:
  12. ;           * -r ... Resets the script, i.e. cleans everything up. One usually doesn't need that flag, however, if something didn't work,
  13. ;                    one can use it.  
  14. ;           * -c ... If you use this flag, the script will remove you from the channel aswell. This means, that Q will leave the channel
  15. ;                    completly. Note that you can _NOT_ reverse it!
  16. ;
  17. ;
  18. ;   Example output:
  19. ;
  20. ;      ClearChanlev: -----------------------------
  21. ;      ClearChanlev: Now beginning to remove all chanlevs from channel #channel except yours!
  22. ;      ClearChanlev: Receiving own auth now!
  23. ;      ClearChanlev: ...done.
  24. ;      ClearChanlev: Saving chanlev now...
  25. ;      ClearChanlev: ...done.
  26. ;      ClearChanlev: There are 2 lines to send. This will take approximatly 4 seconds. Removing...
  27. ;      ClearChanlev: ...done.
  28. ;      ClearChanlev: Cleaned up!
  29. ;      ClearChanlev: -----------------------------
  30. ;
  31.  
  32. ; Returns the milliseconds between every message sent to Q
  33. ; If you excess flood, you should increase this value to 4000 or even 5000.
  34. alias -l ClearChanlev.Delay { return 3000 }
  35.  
  36. ; $1 = #channel
  37. ;
  38. ; flags:
  39. ;   -c --complete = deletes the complete chanlev, inclusive owner. This will
  40. ;                   result in Q parting.
  41. ;   -r --reset    = resets the scripts in case something didn't work the last time.
  42. alias ClearChanlev {
  43.   echo -s ClearChanlev: -----------------------------
  44.   var %i = 1, %c, %ClearChanlev.Complete = 0, %r, %ClearChanlev.Force = 0, %ClearChanlev.Channel
  45.   while (%i <= $0) {
  46.     %c = $ [ $+ [ %i ] ]
  47.     if (%c == -c) || (%c == --complete) {
  48.       %ClearChanlev.Complete = 1
  49.     }
  50.     elseif (%c == -r) || (%c == --reset) {
  51.       %ClearChanlev.Force = 1
  52.     }
  53.     elseif ($left(%c, 1) == $chr(35)) {
  54.       %ClearChanlev.Channel = %c
  55.     }
  56.     inc %i
  57.   }
  58.   if (%ClearChanlev.Global) {
  59.     if (%ClearChanlev.Force == 0) {
  60.       echo -s ClearChanlev: ClearChanlev is currently running. If this is not the case, please use the -r flag (i.e. /clearchanlev -r #channel)
  61.       echo -s ClearChanlev: -----------------------------
  62.       return
  63.     }
  64.     else {
  65.       unset %ClearChanlev.Global
  66.       echo -s ClearChanlev: ClearChanlev reseted.
  67.     }
  68.   }
  69.   if (!%ClearChanlev.Channel) {
  70.     echo -s ClearChanlev: No channel specified.
  71.     return
  72.   }
  73.   %r = $rand(1,1000)
  74.   set %ClearChanlev.Global %ClearChanlev.Channel %ClearChanlev.Complete %r
  75.   echo -s ClearChanlev: Now beginning to remove all chanlevs from channel %ClearChanlev.Channel $iif(%ClearChanlev.Complete, inclusive, except) yours!
  76.   echo -s ClearChanlev: Receiving own auth now!
  77.   .timerClearChanlevCleanUp 1 60 ClearChanlev.CleanUp
  78.   .who $me n%nat, $+ %r
  79. }
  80.  
  81. raw 354:*: {
  82.   if ($2 == $gettok(%ClearChanlev.Global, 3, 32)) && ($3 == $me) {
  83.     haltdef
  84.     set %ClearChanlev.Global %ClearChanlev.Global $4
  85.   }
  86. }
  87.  
  88. raw 315:*: {
  89.   if (%ClearChanlev.Global) && ($2 == $me) {
  90.     haltdef
  91.     if ($gettok(%ClearChanlev.Global, 4, 32) == 0) {
  92.       echo -s ClearChanlev: You are NOT authed.
  93.       ClearChanlev.CleanUp
  94.     }
  95.     else {
  96.       echo -s ClearChanlev: ...done.
  97.       set %ClearChanlev.Global %ClearChanlev.Global 0
  98.       .msg Q chanlev $gettok(%ClearChanlev.Global, 1, 32)
  99.     }
  100.   }
  101. }
  102.  
  103. alias -l ClearChanlev.GotMessages {
  104.   if (!$exists(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt)) {
  105.     echo -s ClearChanlev: File does not exist!
  106.     ClearChanlev.CleanUp
  107.     return
  108.   }
  109.   if ($lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) == 0) {
  110.     echo -s ClearChanlev: No chanlev to remove!
  111.     ClearChanlev.CleanUp
  112.     return
  113.   }
  114.   if ($gettok(%ClearChanlev.Global, 5, 32) == 0) {
  115.     echo -s ClearChanlev: You are NOT owner of this channel. Aborting!
  116.     ClearChanlev.CleanUp
  117.     return
  118.   }
  119.   echo -s ClearChanlev: There are $lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) lines to send. This will take $&
  120.     approximatly $calc($lines(ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) * $ClearChanlev.Delay / 1000) seconds. Removing...
  121.   .play Q ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt $ClearChanlev.Delay
  122. }
  123.  
  124. alias -l ClearChanlev.CleanUp {
  125.   .remove ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt
  126.   unset %ClearChanlev.*
  127.   .timerClearChanlevCleanUp off
  128.   echo -s ClearChanlev: Cleaned up!
  129.   echo -s ClearChanlev: -----------------------------
  130. }
  131.  
  132. ; $1- = message from Q
  133. alias -l ClearChanlev.Interpret {
  134.   if (%ClearChanlev.Global) {
  135.     if (Username*Flags*Last join*Last changed iswm $1-) {
  136.       echo -s ClearChanlev: Saving chanlev now...
  137.       set %ClearChanlev.Global %ClearChanlev.Global 1
  138.     }
  139.     elseif (You do not have sufficient access on* iswm $1-) {
  140.       echo -s ClearChanlev: You do not have sufficied access on the specified channel!
  141.       ClearChanlev.CleanUp
  142.     }
  143.     elseif (End of list. == $1-) {
  144.       echo -s ClearChanlev: ...done.
  145.       set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 0, 6, 32)
  146.       if ($numtok(%ClearChanLev.Users,32)) {
  147.         write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanLev.Users
  148.         unset %ClearChanlev.Users
  149.       }
  150.       ClearChanlev.GotMessages
  151.     }
  152.     elseif (Channel * is unknown or suspended. iswm $1-) {
  153.       echo -s ClearChanlev: Channel is not known or suspended. Aborting.
  154.       ClearChanlev.CleanUp
  155.     }
  156.     elseif ($gettok(%ClearChanlev.Global, 6, 32) == 1) {
  157.       if ($1 == $gettok(%ClearChanlev.Global, 4, 32)) {
  158.         if (n !isin $2) {
  159.           set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 0, 5, 32)
  160.           return
  161.         }
  162.         else {
  163.           set %ClearChanlev.Global $puttok(%ClearChanlev.Global, 1, 5, 32)
  164.         }
  165.  
  166.         if ($gettok(%ClearChanlev.Global, 2, 32) == 0) {
  167.           return
  168.         }
  169.         else {
  170.           write ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 $replace($2,+,-)
  171.           return
  172.         }
  173.       }
  174.       else {
  175.         if (n isin $2) {
  176.           write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt CHANLEV $gettok(%ClearChanlev.Global, 1, 32) $chr(35) $+ $1 $replace($2,+,-)
  177.         }
  178.         else {
  179.           set %ClearChanlev.Users $addtok(%ClearChanLev.users,$chr(35) $+ $1,32)
  180.           if ($numtok(%ClearChanlev.Users,32) == 18) {
  181.             write -il1 ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt REMOVEUSER $gettok(%ClearChanlev.Global, 1, 32) %ClearChanlev.Users
  182.             unset %ClearChanlev.Users
  183.           }
  184.         }
  185.       }
  186.     }
  187.   }
  188. }
  189.  
  190. on ^*:Notice:*:?: {
  191.   if ($nick == Q) && (%ClearChanlev.Global) {
  192.     haltdef
  193.     ClearChanlev.Interpret $1-
  194.   }
  195. }
  196.  
  197. on ^*:Text:*:?: {
  198.   if ($nick == Q) && (%ClearChanlev.Global) {
  199.     haltdef
  200.     ClearChanlev.Interpret $1-
  201.   }
  202. }
  203.  
  204. on *:PLAYEND:{
  205.   if ($nopath($filename) == ClearChanlev $+ $gettok(%ClearChanlev.Global, 3, 32) $+ .txt) {
  206.     echo -s ClearChanlev: ...done.
  207.     ClearChanlev.Cleanup
  208.   }
  209. }