mIRC Home    About    Download    Register    News    Help

Print Thread
#163453 30/10/06 03:49 AM
Joined: Aug 2006
Posts: 60
S
Babel fish
OP Offline
Babel fish
S
Joined: Aug 2006
Posts: 60
I'm trying to make a script that saves totals of how many times I have been +/-qaohv. The +/-ov work fine, but for +/-qah...then it gets tricky. I want this to be accurate, but it's got to the point where I need help. Because you see the thing is, if someone sets "mode +kq my_nickname person_getting_owner", this script will increment %founders, when clearly it was just a coincidence that my name is the channel key.

on *:rawmode:*: {
if ($me isin $2-) && ( (+*q iswm $1) || (+q isin $1) ) && (-*q !iswm $1) {
/inc %founders
/echo $chan %founders founders
}
if ($me isin $2-) && ( (+*a iswm $1) || (+a isin $1) ) && (-*a !iswm $1) {
/inc %protects
/echo $chan %protects protects
}
if ($me isin $2-) && ( (+*h iswm $1) || (+h isin $1) ) && (-*h !iswm $1) {
/inc %hops
/echo $chan %hops hops
}
if ($me isin $2-) && ( (-*q iswm $1) || (-q isin $1) ) {
/inc %defounders
/echo $chan %defounders defounders
}
if ($me isin $2-) && ( (-*a iswm $1) || (-q isin $1) ) {
/inc %deprotects
/echo $chan %deprotects deprotects
}
if ($me isin $2-) && ( (-*h iswm $1) || (-q isin $1) ) {
/inc %dehops
/echo $chan %dehops dehops
}
}

Last edited by Shining_Phoenix; 30/10/06 04:42 AM.
#163454 30/10/06 05:14 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
It's a fair bit longer than yours, and includes the ops/voices (which you already say you have working).

This has been tested on a network running UnrealIRCd. I don't know if that's going to make a difference or not. I don't think it will.
Code:
 on *:rawmode:*:{
  var %mode = $1
  tokenize 32 $2-
  if $left(%mode,1) == + {
    if $pos(%mode,q,0) {
      var %a = 1, %b = $pos(%mode,q,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %founders
          echo $chan %founders founders 
        }
        inc %a
      }
    }
    if $pos(%mode,a,0) {
      var %a = 1, %b = $pos(%mode,a,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %protects
          echo $chan %protects protects
        }
        inc %a
      }
    }
    if $pos(%mode,o,0) {
      var %a = 1, %b = $pos(%mode,o,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %ops
          echo $chan %ops ops
        }
        inc %a
      }
    }
    if $pos(%mode,h,0) {
      var %a = 1, %b = $pos(%mode,h,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %hops
          echo $chan %hops half-ops
        }
        inc %a
      }
    }
    if $pos(%mode,v,0) {
      var %a = 1, %b = $pos(%mode,v,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %voices
          echo $chan %voices voices
        }
        inc %a
      }
    }
  }
  else {
    if $pos(%mode,q,0) {
      var %a = 1, %b = $pos(%mode,q,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %defounders
          echo $chan %defounders de-founders
        }
        inc %a
      }
    }
    if $pos(%mode,a,0) {
      var %a = 1, %b = $pos(%mode,a,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %deprotects
          echo $chan %deprotects de-protects
        }
        inc %a
      }
    }
    if $pos(%mode,o,0) {
      var %a = 1, %b = $pos(%mode,o,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %deops
          echo $chan %deops de-ops
        }
        inc %a
      }
    }
    if $pos(%mode,h,0) {
      var %a = 1, %b = $pos(%mode,h,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %dehops
          echo $chan %dehops de-half-ops
        }
        inc %a
      }
    }
    if $pos(%mode,v,0) {
      var %a = 1, %b = $pos(%mode,v,0)
      while %a <= %b {
        if $($+($,%a),2) == $me {
          inc %devoices
          echo $chan %devoices de-voices
        }
        inc %a
      }
    }
  }
}
 


Noting the level of complexity in your code, you should be able to work out how my code works, however, if you have problems, post here and I or someone else will be happy to explain.

#163455 30/10/06 10:12 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
problem with this is it doesn't accurately account for other modes that take parameters that may also have been set alongside the modes you're checking for. for +ohv, this is easy enough by handling the mode string with $mode(). for +a and +q it's a little more difficult, involves parsing the string of modes and comparing it to values in $chanmodes

$chanmodes returns 4 tokens delimited by a comma. the first are the list modes, when you receive these from the server they take a parameter both when being set and unset. the second also take a parameter when set and unset. the third take a parameter when being set, but not when being unset... and the last never take any parameters

i believe there's a few snippets that pick out modes for you on mircscripts.org's snippets section.. so give that a look :tongue:

btw, +q can be detected with an on *:owner event, which functions much like an op event, $opnick is the person being ownered. on *:deowner exists too, and again $opnick is used


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
#163456 30/10/06 11:32 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I'd like to know how you figure that. I tested it with about a dozen different variations with a friend of mine setting the modes at their discrepancy, and it worked 100% each time.

An example of how you think it would fail would help me determine if it would, or help me explain why it wouldn't.

#163457 31/10/06 10:33 AM
Joined: Aug 2006
Posts: 60
S
Babel fish
OP Offline
Babel fish
S
Joined: Aug 2006
Posts: 60
Heh I'm new to scripting. Could you please explain how your one works?

Last edited by Shining_Phoenix; 31/10/06 10:34 AM.
#163458 31/10/06 07:00 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
ok for example, say "+m-a $me" is set. it will increase %protects when it should increase %deprotects. a similar thing occurs with -m+a in case the server sends them in that order. if someone sets a key equal to your nick but ops someone else with "+ko $me someone" it'll be inaccurate too

however unlikely you may think these scenarios are, imo it's always best to make your code as supportive as possible (within reason of course)

btw i didnt need to study your code to see it wasn't going to be totally accurate.. the fact that you didn't use $chanmodes anywhere makes it immediately obvious :P


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
#163459 31/10/06 09:32 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I am in a bit of a hurry right now, so can't really look at this, but why not just check all the modes used and base it on that?

Example:

mode +kmo-v key nick1 nick2

Check $1, one character at a time:

Character 1 is +, so set a variable or whatever noting that everything after it is a + (until you reach a -, of course)

Character 2 is k. As such, you know that $2 will be the key value.

Character 3 is m. Assuming m is moderated on your network, you can just ignore this mode and continue to the next.

Character 4 is o. So, you know that you will op someone. Since you already know $2 is the key, then you know you are on $3 for the nick being opped.

Character 5 is -. Change your variable, or whatever you're using, to say that everything is now a -.

Character 6 is v. So, you know that you're devoicing someone. Since $3 was the last used token, $4 is the one being devoiced.

Now, I am sure that there is probably another method of doing this that is faster than checking every character in $1. Still, I can't imagine this taking too long to do because you can only do a limited number of modes at one time.

Another method that I can think of really quickly is to backtrack. Check $1 for specific characters. Then, remove the + and - from it (and any modes that don't need another token, such as +m [moderated]) and check the $pos of the character (such as o) and add 1 (because $1 isn't a mode token). You will then know that the token matching the $pos + 1 will be the one opped/deopped. Then, just backtrack to see what the last used +/- is.

I actually think RusselB was doing this sort of thing, though I haven't looked closely, nor have I tested it. I just don't have time right now to really go through it all.


Invision Support
#Invision on irc.irchighway.net
#163460 31/10/06 10:42 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
OK, I see your point with "+m-a $me" ...my code would fail in that case.
However, using "+ko $me someone" would not cause it to fail, and here's why:
The code looks at the first character of the set of modes that are set, in this case +
then it removes that character from the modes, now making the string of mode "ko"
The nicks that were entered are tokenized using $chr(32), creating
$1 = $me
$2 = someone

then it grabs the position of the "o" from the mode string, which returns 2. This is appended to the $ character, creating the identifier $2.
Next it checks if $2 == $me, which in this case it doesn't, so none of the tracking variables are altered.

#163461 01/11/06 02:50 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
lol, did you forget what your while loops are doing? ;P

look over your code again, you're not just checking $me == $2. you're checking each parameter from 1 to the one that corresponds to the position of the mode. so in the +ko $me example, you check both $1 and $2 against $me


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
#163462 01/11/06 02:53 AM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
what you've mentioned is essentially what needs to be done. however, since the mode string could contain any of the modes in $chanmodes, that's why you need to factor it in to the script to check which are expected to take a parameter and which arent

and yes, you need to loop through all characters in $1 to achieve this, that's not unreasonable. as i said theres several snippets on mircscripts.org that do the work for you, i'll try to find a specific url if anyones interested


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
#163463 01/11/06 03:14 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
My while loops only cover the the number of times a particular mode has been set (eg: +qoao RusselB tim2 navada nobody)
+q is set once for RusselB
+o is set twice, once for tim2, and once for nobody
+a is set once for navada

That's the only thing my while loops do. They ensure that all occurances of a single mode are covered, rather than just the first one.

#163464 01/11/06 03:56 AM
Joined: Aug 2006
Posts: 60
S
Babel fish
OP Offline
Babel fish
S
Joined: Aug 2006
Posts: 60
Being given a specific url would be faster than searching for myself :P

Thanks heaps for your genuine interest!!

#163465 01/11/06 02:47 PM
Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
I haven't fully tested this, but it should be right.
Code:
on *:rawmode:#:{
  noop $regex(ckm,$1,/([+-][^+-]*)/g)
  var %i = 1,%masks = $2-
  while $regml(ckm,%i) {
    var %v1 = $v1
    set -u %cmodes $remove($gettok($chanmodes,$iif(+* iswm %v1,1-3,1-2),44) $+ $nickmode,$chr(44))
    var %t = $count(%v1, [ $mid($regsubex(%cmodes,/(.)/g,$chr(44)\t),2) ] ) [color:gray]| ; don't destroy this spacing.[/color]
    _add %v1 $gettok(%masks,$+(1-,%t),32)
    inc %t | %masks = $gettok(%masks,$+(%t,-),32) | inc %i
  }
}
alias -l _add {
  var %i = 2,%p = 2,%c
  while $mid($1,%i,1) != $null {
    %c = $v1
    if %c !isin %cmodes { inc %i | continue }
    if $gettok($1-,%p,32) == $me && $findtok(q a o h v,%c,1,32) {
      var %v = $gettok(founders protects ops hops voices,$v1,32)
      if -* iswm $1 { var %v = de $+ %v }
      inc % $+ %v
      echo # % $+ %v $(% $+ %v,2)
    }
    inc %i | inc %p
  }
}

#163466 02/11/06 05:19 AM
Joined: Aug 2006
Posts: 60
S
Babel fish
OP Offline
Babel fish
S
Joined: Aug 2006
Posts: 60
I'll test deegee's script first, since it has $chanmodes in it.


Link Copied to Clipboard