Difference between revisions of "Undo Modechanges"

From Scriptwiki
Jump to: navigation, search
(changed on quit to on exit..)
m (added some spacing to make it more readable, also added to script archive,)
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
 
   ; check if bitchmode is globally on
 
   ; check if bitchmode is globally on
 
   [[if]] ($bitchmode(global) != on) { halt }
 
   [[if]] ($bitchmode(global) != on) { halt }
 +
 
   ; check if bitchmode for this channel is on
 
   ; check if bitchmode for this channel is on
 
   if ($bitchmode($chan) != on) { halt }
 
   if ($bitchmode($chan) != on) { halt }
 +
 
   ; set some variable.  
 
   ; set some variable.  
 
   ; we use %cmode to save if it is currenty a "+" or "-" what we are looking at (in $1-)
 
   ; we use %cmode to save if it is currenty a "+" or "-" what we are looking at (in $1-)
Line 15: Line 17:
 
   ; %npara is the number of the parameter we are currently looking at
 
   ; %npara is the number of the parameter we are currently looking at
 
   [[var]] %i = 1, %cmode, %+modes, %-modes, %modes, %+param, %-param, %npara = 1
 
   [[var]] %i = 1, %cmode, %+modes, %-modes, %modes, %+param, %-param, %npara = 1
 +
 
   ; lets loop through the string
 
   ; lets loop through the string
 
   [[while]] (%i <= [[$len]]($1)) {
 
   [[while]] (%i <= [[$len]]($1)) {
Line 20: Line 23:
 
     if ([[$mid]]($1,%i,1) == +) { %cmode = + }
 
     if ([[$mid]]($1,%i,1) == +) { %cmode = + }
 
     elseif ($mid($1,%i,1) == -) { %cmode = - }
 
     elseif ($mid($1,%i,1) == -) { %cmode = - }
 +
 
     ; if its in the third field of $chanmodes, it needs a parameter to set and none to unset. Look at [[Raw_005|raw 005]] to get
 
     ; if its in the third field of $chanmodes, it needs a parameter to set and none to unset. Look at [[Raw_005|raw 005]] to get
 
     ; more info about it
 
     ; more info about it
 
     elseif ($mid($1,%i,1) isincs [[$gettok]]([[$chanmodes]],3,44)) {
 
     elseif ($mid($1,%i,1) isincs [[$gettok]]([[$chanmodes]],3,44)) {
 +
 
       ; if we are currently at the "+"  
 
       ; if we are currently at the "+"  
 
       if (%cmode == +) {
 
       if (%cmode == +) {
 +
 
         ; check if we set something, if yes, we need to set it as "default". Add it to the hashtable
 
         ; check if we set something, if yes, we need to set it as "default". Add it to the hashtable
 
         if ($nick == $me) { hadd bitchmode chan. [ $+ [ $chan ] $+ [ $chr(124) ] $+ [ $mid($1,%i,1) ] ] $gettok($1-,$calc(%npara + 1),32) }
 
         if ($nick == $me) { hadd bitchmode chan. [ $+ [ $chan ] $+ [ $chr(124) ] $+ [ $mid($1,%i,1) ] ] $gettok($1-,$calc(%npara + 1),32) }
 +
 
         ; if there is something as default in our hashtable, we want to set this again
 
         ; if there is something as default in our hashtable, we want to set this again
 
         if ($bitchmode($chan $+ $chr(124) $+ $mid($1,%i,1))) {  
 
         if ($bitchmode($chan $+ $chr(124) $+ $mid($1,%i,1))) {  
 +
 
           ; put it to the variable
 
           ; put it to the variable
 
           %+modes = %+modes $+ $mid($1,%i,1)
 
           %+modes = %+modes $+ $mid($1,%i,1)
 +
 
           ; increase the parameter-variable so that we look at the next one
 
           ; increase the parameter-variable so that we look at the next one
 
           inc %npara
 
           inc %npara
 
           %+param = %+param $bitchmode($chan $+ $chr(124) $+ $mid($1,%i,1))
 
           %+param = %+param $bitchmode($chan $+ $chr(124) $+ $mid($1,%i,1))
 
         }
 
         }
 +
 
         ; if there is no default, just unset it
 
         ; if there is no default, just unset it
 
         else {
 
         else {
 
           %-modes = %-modes $+ $mid($1,%i,1)
 
           %-modes = %-modes $+ $mid($1,%i,1)
 +
 
           ; increase the parameter-variable so that we look at the next one
 
           ; increase the parameter-variable so that we look at the next one
 
           inc %npara
 
           inc %npara
Line 49: Line 60:
 
       }
 
       }
 
     }
 
     }
 +
 
     ; if its in the field 1 or 2, it needs a parameter to set AND unset
 
     ; if its in the field 1 or 2, it needs a parameter to set AND unset
 
     elseif ($mid($1,%i,1) isincs $gettok($chanmodes,1-2,44)) {  
 
     elseif ($mid($1,%i,1) isincs $gettok($chanmodes,1-2,44)) {  
 +
 
       ; if its +, we just want to unset it. You dont need to look if this set "oversets" another setting, as this is
 
       ; if its +, we just want to unset it. You dont need to look if this set "oversets" another setting, as this is
 
       ; not possible with modes in these fields of $chanmodes
 
       ; not possible with modes in these fields of $chanmodes
Line 72: Line 85:
 
     ; here we increase the parameter counter if its a nickmode (e.g. +o)
 
     ; here we increase the parameter counter if its a nickmode (e.g. +o)
 
     elseif ($mid($1,%i,1) isincs $nickmodes) { inc %npara }
 
     elseif ($mid($1,%i,1) isincs $nickmodes) { inc %npara }
 +
 
     ; increase the looping variable
 
     ; increase the looping variable
 
     inc %i
 
     inc %i
 
   }
 
   }
 +
 
   ; put all stuff together
 
   ; put all stuff together
 
   if ($len(%+modes) > 0) { %modes = %modes + $+ %+modes }
 
   if ($len(%+modes) > 0) { %modes = %modes + $+ %+modes }
 
   if ($len(%-modes) > 0) { %modes = %modes $+ - $+ %-modes }
 
   if ($len(%-modes) > 0) { %modes = %modes $+ - $+ %-modes }
 +
 
   ; if we did do all this stuff, we dont want to undo it of course. We still needed to loop through it to set new
 
   ; if we did do all this stuff, we dont want to undo it of course. We still needed to loop through it to set new
 
   ; default settings
 
   ; default settings
 
   if ($nick != $me) { mode $chan %modes %+param %-param }
 
   if ($nick != $me) { mode $chan %modes %+param %-param }
 
  }
 
  }
 +
 
  ; This is the alias to turn the script on or off, either globally or for channels
 
  ; This is the alias to turn the script on or off, either globally or for channels
 
  ; Its /bitchmode [#channel] [on|off]
 
  ; Its /bitchmode [#channel] [on|off]
Line 95: Line 112:
 
   ; we want to check if its used as identifier ($bitchmode())
 
   ; we want to check if its used as identifier ($bitchmode())
 
   if ($isid) {
 
   if ($isid) {
 +
 
     ; lets return the global setting
 
     ; lets return the global setting
 
     if ($1 == global) { return $hget(bitchmode,global) }
 
     if ($1 == global) { return $hget(bitchmode,global) }
 +
 
     ; if its a channel in the first parameter
 
     ; if its a channel in the first parameter
 
     if ($left($1,1) == $chr(35)) {
 
     if ($left($1,1) == $chr(35)) {
Line 103: Line 122:
 
         [[return]] [[$iif]]([[$hget]](bitchmode,chan. [ $+ [ $1 ] ]),$hget(bitchmode,chan. [ $+ [ $1 ] ]))
 
         [[return]] [[$iif]]([[$hget]](bitchmode,chan. [ $+ [ $1 ] ]),$hget(bitchmode,chan. [ $+ [ $1 ] ]))
 
       }
 
       }
 +
 
       ; return information we have saved about a certain channel (modes that are set)
 
       ; return information we have saved about a certain channel (modes that are set)
 
       else {
 
       else {
Line 115: Line 135:
 
       ; lets loop through all items in the hash
 
       ; lets loop through all items in the hash
 
       var %i = 1
 
       var %i = 1
 +
 
       while (%i <= $hfind(bitchmode,chan.*,0,w)) {  
 
       while (%i <= $hfind(bitchmode,chan.*,0,w)) {  
 
         ; if it is really a channel option     
 
         ; if it is really a channel option     
Line 128: Line 149:
 
     ; we want to turn it on
 
     ; we want to turn it on
 
     if ($1 == on) { hadd bitchmode global on | echo -a bitchmode turned on for: global. }
 
     if ($1 == on) { hadd bitchmode global on | echo -a bitchmode turned on for: global. }
 +
 
     ; we want to turn it off
 
     ; we want to turn it off
 
     if ($1 == off) { hadd bitchmode global off | echo -a bitchmode turned off for: global. }
 
     if ($1 == off) { hadd bitchmode global off | echo -a bitchmode turned off for: global. }
 +
 
     ; we want to change a channel setting, so lets do it
 
     ; we want to change a channel setting, so lets do it
 
     if ($left($1,1) == $chr(35)) {
 
     if ($left($1,1) == $chr(35)) {
Line 143: Line 166:
 
   ; we need to get all stuff in field #3 @ raw 005 ($chanmodes)
 
   ; we need to get all stuff in field #3 @ raw 005 ($chanmodes)
 
   var %i = 1, %npara = 1  
 
   var %i = 1, %npara = 1  
 +
 
   ; lets loop through the information the raw gives us
 
   ; lets loop through the information the raw gives us
 
   while (%i <= $len($3)) {
 
   while (%i <= $len($3)) {
Line 149: Line 173:
 
       ; add it to the hashtable
 
       ; add it to the hashtable
 
       hadd bitchmode chan. [ $+ [ $2 ] $+ [ $chr(124) ] $+ [ $mid($3,%i,1) ] ] $gettok($1-,$calc($3 + %npara),32)  
 
       hadd bitchmode chan. [ $+ [ $2 ] $+ [ $chr(124) ] $+ [ $mid($3,%i,1) ] ] $gettok($1-,$calc($3 + %npara),32)  
 +
 
       ; increase parameter counter
 
       ; increase parameter counter
 
       inc %npara  
 
       inc %npara  
Line 154: Line 179:
 
     ; if its in the first or second field, lets increase the counter parameter again
 
     ; if its in the first or second field, lets increase the counter parameter again
 
     if ($mid($3,%i,1) isincs $gettok($chanmodes,1-2,44)) { inc %npara }
 
     if ($mid($3,%i,1) isincs $gettok($chanmodes,1-2,44)) { inc %npara }
 +
 
     ; increase looping variable
 
     ; increase looping variable
 
     inc %i
 
     inc %i
Line 163: Line 189:
 
   ; lets make a new hashtable if it doesnt exist
 
   ; lets make a new hashtable if it doesnt exist
 
   if (!$hget(bitchmode)) { hmake bitchmode 10 }
 
   if (!$hget(bitchmode)) { hmake bitchmode 10 }
 +
 
   ; load the "old" stuff in it
 
   ; load the "old" stuff in it
 
   hload bitchmode bitchmode.dat
 
   hload bitchmode bitchmode.dat
 +
 
   ; delete everything but channels and global
 
   ; delete everything but channels and global
 
   var %i = 1
 
   var %i = 1
 +
 
   ; loop through the entire table
 
   ; loop through the entire table
 
   while (%i <= $hget(bitchmode,0).item) {
 
   while (%i <= $hget(bitchmode,0).item) {
 
     ; delete everything thats no channel or global option
 
     ; delete everything thats no channel or global option
 
     if ($chr(124) isin $hget(bitchmode,%i).item) && (global != $hget(bitchmode,%i).item) { hdel bitchmode $hget(bitchmode,%i).item }
 
     if ($chr(124) isin $hget(bitchmode,%i).item) && (global != $hget(bitchmode,%i).item) { hdel bitchmode $hget(bitchmode,%i).item }
 +
 
     ; increase looping variable
 
     ; increase looping variable
 
     inc %i
 
     inc %i
Line 178: Line 208:
 
  ; lets save everything when we exit to bitchmode.dat
 
  ; lets save everything when we exit to bitchmode.dat
 
  [[On_exit|on *:EXIT:]] {
 
  [[On_exit|on *:EXIT:]] {
   if ($nick == $me) {
+
   hsave bitchmode bitchmode.dat
    hsave bitchmode bitchmode.dat
 
  }
 
 
  }
 
  }
 +
 +
[[Category:Script Archive]]

Latest revision as of 13:17, 2 July 2007

This script is supposed to undo all modechanges in a channel. It may not work 100%, but it will be updated in the future. You can find explanations in the script.

Note that you cant just replace + with - and - with plus as e.g. +l needs a parameter for setting (the limit that is), but you can unset it without parameter (just -l). Read more about it here.

on @*:RAWMODE:#: {
 ; check if bitchmode is globally on
 if ($bitchmode(global) != on) { halt }

 ; check if bitchmode for this channel is on
 if ($bitchmode($chan) != on) { halt }

 ; set some variable. 
 ; we use %cmode to save if it is currenty a "+" or "-" what we are looking at (in $1-)
 ; %+modes is for modes we want to set, %-modes for modes we want to unset
 ; %+param are the params for the modes we want to set, %-param for the one we want to unset
 ; %npara is the number of the parameter we are currently looking at
 var %i = 1, %cmode, %+modes, %-modes, %modes, %+param, %-param, %npara = 1

 ; lets loop through the string
 while (%i <= $len($1)) {
   ; we want to know if a mode is + or -, so lets set it to a variable
   if ($mid($1,%i,1) == +) { %cmode = + }
   elseif ($mid($1,%i,1) == -) { %cmode = - }

   ; if its in the third field of $chanmodes, it needs a parameter to set and none to unset. Look at raw 005 to get
   ; more info about it
   elseif ($mid($1,%i,1) isincs $gettok($chanmodes,3,44)) {

     ; if we are currently at the "+" 
     if (%cmode == +) {

       ; check if we set something, if yes, we need to set it as "default". Add it to the hashtable
       if ($nick == $me) { hadd bitchmode chan. [ $+ [ $chan ] $+ [ $chr(124) ] $+ [ $mid($1,%i,1) ] ] $gettok($1-,$calc(%npara + 1),32) }

       ; if there is something as default in our hashtable, we want to set this again
       if ($bitchmode($chan $+ $chr(124) $+ $mid($1,%i,1))) { 

         ; put it to the variable
         %+modes = %+modes $+ $mid($1,%i,1)

         ; increase the parameter-variable so that we look at the next one
         inc %npara
         %+param = %+param $bitchmode($chan $+ $chr(124) $+ $mid($1,%i,1))
       }

       ; if there is no default, just unset it
       else {
         %-modes = %-modes $+ $mid($1,%i,1)

         ; increase the parameter-variable so that we look at the next one
         inc %npara
       }
     }
     ; if its "-" 
     else {
       ; just reset it with the info we have in our hashtable
       %+modes = %+modes $+ $mid($1,%i,1)
       %+param = %+param $bitchmode($chan $+ $chr(124) $+ $mid($1,%i,1))
     }
   }

   ; if its in the field 1 or 2, it needs a parameter to set AND unset
   elseif ($mid($1,%i,1) isincs $gettok($chanmodes,1-2,44)) { 

     ; if its +, we just want to unset it. You dont need to look if this set "oversets" another setting, as this is
     ; not possible with modes in these fields of $chanmodes
     if (%cmode == +) { 
       %-modes = %-modes $+ $mid($1,%i,1) 
       %-param = $addtok(%-param,$gettok($1-,$calc(%npara + 1),32),32)
     }
     ; if someone unsets it, we just set it again
     else { 
       %+modes = %+modes $+ $mid($1,%i,1) 
       %+param = $addtok(%+param,$gettok($1-,$calc(%npara + 1),32),32)
     } 
     ; we need to increase the parameter counter again
     inc %npara
   }
   ; if its in the last field, its just a simple mode without parameter, so we will just undo it
   elseif ($mid($1,%i,1) isin $gettok($chanmodes,4,44)) { 
     if (%cmode == +) { %-modes = %-modes $+ $mid($1,%i,1) }
     else { %+modes = %+modes $+ $mid($1,%i,1) } 
   }
   ; here we increase the parameter counter if its a nickmode (e.g. +o)
   elseif ($mid($1,%i,1) isincs $nickmodes) { inc %npara }

   ; increase the looping variable
   inc %i
 }

 ; put all stuff together
 if ($len(%+modes) > 0) { %modes = %modes + $+ %+modes }
 if ($len(%-modes) > 0) { %modes = %modes $+ - $+ %-modes }

 ; if we did do all this stuff, we dont want to undo it of course. We still needed to loop through it to set new
 ; default settings
 if ($nick != $me) { mode $chan %modes %+param %-param }
}

; This is the alias to turn the script on or off, either globally or for channels
; Its /bitchmode [#channel] [on|off]
; You can do:
; /bitchmode #channel <on|off> - turns bitchmode for this channel on or off
; /bitchmode #channel - shows current option
; /bitchmode <on> - turns bitchmode on / off. If on, its just activated for the previosly 
;                   activated channel
; /bitchmode <off>  - turns bitchmode off
; /bitchmode - shows all options

alias bitchmode {
 ; we want to check if its used as identifier ($bitchmode())
 if ($isid) {

   ; lets return the global setting
   if ($1 == global) { return $hget(bitchmode,global) }

   ; if its a channel in the first parameter
   if ($left($1,1) == $chr(35)) {
     ; return whether bitchmode is on or off for this channel
     if ($numtok($1-,32) == 1) { 
       return $iif($hget(bitchmode,chan. [ $+ [ $1 ] ]),$hget(bitchmode,chan. [ $+ [ $1 ] ]))
     }

     ; return information we have saved about a certain channel (modes that are set)
     else {
       return $iif($hget(bitchmode,chan. [ $+ [ $1 ] ]),$hget(bitchmode,chan. [ $+ [ $1 ] ]));
     }
   }
 }
 ; its no identifier, so its for changing options
 else {
   ; we want to give everything out
   if (!$1) {
     ; lets loop through all items in the hash
     var %i = 1

     while (%i <= $hfind(bitchmode,chan.*,0,w)) { 
       ; if it is really a channel option    
       if ($chr(124) !isin $hfind(bitchmode,chan*,%i,w)) {
         echo -a $gettok($hfind(bitchmode,chan*,%i,w),2,46) => $hget(bitchmode,$hfind(bitchmode,chan*,%i,w))
       }
       ; increase looping variable
       inc %i
     }
     ; echo the global options
     echo -a GLOBAL: $hget(bitchmode,global)
   }
   ; we want to turn it on
   if ($1 == on) { hadd bitchmode global on | echo -a bitchmode turned on for: global. }

   ; we want to turn it off
   if ($1 == off) { hadd bitchmode global off | echo -a bitchmode turned off for: global. }

   ; we want to change a channel setting, so lets do it
   if ($left($1,1) == $chr(35)) {
     if (!$istok(on off, $2, 32)) { halt }
     hadd bitchmode chan. [ $+ [ $chan ] ] on
     echo -a bitchmode turned $2 for: $1 $+ .
   }  
 }
}

; adds everything to the hash
raw 324:*: {
 ; we need to get all stuff in field #3 @ raw 005 ($chanmodes)
 var %i = 1, %npara = 1 

 ; lets loop through the information the raw gives us
 while (%i <= $len($3)) {
   ; if it is in the field 3, we need to save it (as we dont get the information when it is unset)
   if ($mid($3,%i,1) isincs $gettok($chanmodes,3,44)) { 
     ; add it to the hashtable
     hadd bitchmode chan. [ $+ [ $2 ] $+ [ $chr(124) ] $+ [ $mid($3,%i,1) ] ] $gettok($1-,$calc($3 + %npara),32) 

     ; increase parameter counter
     inc %npara 
   }
   ; if its in the first or second field, lets increase the counter parameter again
   if ($mid($3,%i,1) isincs $gettok($chanmodes,1-2,44)) { inc %npara }

   ; increase looping variable
   inc %i
 }
}

; we want to load everything on start again
on *:START: {
 ; lets make a new hashtable if it doesnt exist
 if (!$hget(bitchmode)) { hmake bitchmode 10 }

 ; load the "old" stuff in it
 hload bitchmode bitchmode.dat

 ; delete everything but channels and global
 var %i = 1

 ; loop through the entire table
 while (%i <= $hget(bitchmode,0).item) {
   ; delete everything thats no channel or global option
   if ($chr(124) isin $hget(bitchmode,%i).item) && (global != $hget(bitchmode,%i).item) { hdel bitchmode $hget(bitchmode,%i).item }

   ; increase looping variable
   inc %i
 }
}

; lets save everything when we exit to bitchmode.dat
on *:EXIT: {
 hsave bitchmode bitchmode.dat
}