mIRC Homepage
Posted By: badcarwash set mode -i, help? - 10/04/11 04:07 AM
I am an owner of a channel, and some of my OPs set the channel to invite-only. I want to put something in my remotes that automatically makes me set the mode back to -i.

I think my script is wrong, because I'm new to this. This is what I have:

on *:INVITE:#: { mode $chan -i }

but it doesn't work. Help?
Posted By: RusselB Re: set mode -i, help? - 10/04/11 04:17 AM
The problem you are having, is due to using the wrong event.
The on INVITE event triggers when a user invites you to a channel.

What you want to do is watch for someone setting mode +i
You can use the ON MODE or ON RAWMODE for this.

See the help file for more details.
Posted By: badcarwash Re: set mode -i, help? - 10/04/11 04:50 AM
So, would this be correct, then?

on *:MODE:#: {
if (mode $chan +i) {
mode $chan -i }
}
Posted By: genius_at_work Re: set mode -i, help? - 10/04/11 05:39 AM
Try this:

Code:

on *:MODE:*:{
  if ((($me isop $chan) || ($me ishop $chan)) && (i isincs $1)) {
    mode $chan -i
  }
}



(untested)

-genius_at_work
Posted By: badcarwash Re: set mode -i, help? - 10/04/11 11:15 AM
Thanks! This looks like it works.

But, I want to figure out how the script works so I can get a better understanding of it. What does everything mean?

For example, I wanted to tinker around with this code by having me automatically set the channel to -m when an OP sets the channel to +m, but it didn't seem to work when I was messing around with it.
Posted By: Riamus2 Re: set mode -i, help? - 10/04/11 12:01 PM
Not too much there to figure out. The first parts of the IF check to see if you are op or halfop to make sure that you have access to changing the mode. The last part is what checks for the mode.

isincs = check to see if the first part is in the second part using a case sensitive comparison (+m isn't the same as +M).

So, check to see if the mode i is in the list of modes being set. The reason to check using isin is because someone might set multiple modes at once, such as +ism or whatever. If you only look for +i, then it won't match multiple modes.

So if you want to check for +m, replace i with m. As a note, you can use regex to check for a list of different modes and remove them if you have a variety of modes you want to remove.

Code:
on *:mode:#: {
  if (($me isop $chan || $me ishop $chan) && $regex($1,/([ims])/gS)) {
    var %c = 1, %t = $regml(0)
    while (%c <= %t) {
      var %modes = %modes $+ $regml(%c)
      inc %c
    }
    mode $chan - $+ %modes
  }
}


Look inside $regex and you'll see [i|m|s]. Replace the letters with the modes you want to remove. Separate each with a | as shown and use lowercase or capital as needed.

What this does... it still starts by checking your mode to make sure you can change modes. Then, it will use regex to see if any letter within the brackets is matched. If so, all matches are placed into $regml(N) where N is the number of the match. So $regml(1) is the first match. The while loop puts everything from $regml(1) to $regml(0) into a %modes variable ($regml(0) is the total number of matches). It will then unset all of those modes at once. So if all 3 were in the mode, you'd do:

/mode $chan -ims

So that you know... $regex() won't be as fast as isincs for a single match. At some point, it will be faster as you add additional modes, but without running comparison speed tests on the code, I'm not sure when that will happen. isincs using IF/ELSEIF checks may be faster for 2 or 3 or even more modes, or it may only be faster for one mode. $regex() does help to avoid needing multiple IF/ELSEIF checks and keeps all of the modes in one small location, so that's helpful if you have more than one mode to deal with.
Posted By: hixxy Re: set mode -i, help? - 10/04/11 02:08 PM
Riamus,

You don't need to separate the individual mode letters with a "|" if they're inside [...] in a regex. Your regex should really be one of the following:

/(i|m|s)/gS
or
/([ims])/gS

[...] is a character class and means "match one of the characters specified within these brackets"
Posted By: Riamus2 Re: set mode -i, help? - 10/04/11 02:18 PM
Thanks. I was apparently thinking of both methods and ended up combining them. Still learning. laugh

I edited the previous post.
Posted By: Tomao Re: set mode -i, help? - 10/04/11 07:02 PM
Riamus2, you forgot to prefix the mode event with an exclamation mark to keep the client running the code from being triggered.

I think you can do it with a tokenize loop to reduce the byte size quite a bit, but then that won't make much of a difference in workability:
Code:
on !*:mode:#:{
  if (($nick(#,$me,oh) && $regex($1,/([ims])/g))) {
    while ($regml($0)) tokenize 32 $1- $v1
    mode # $+(-,$remove($2-,$chr(32)))
  }
}
Posted By: Riamus2 Re: set mode -i, help? - 11/04/11 12:21 AM
Yes, I knew I didn't include a check against the user typing mode themselves. Neither did genius_at_work. At some point, you have to stop adding in every single possible check for people. wink

Anyhow, there are often ways to reduce the number of bytes. If it doesn't improve speed significantly, I'm not too concerned about bytes.
Posted By: badcarwash Re: set mode -i, help? - 11/04/11 02:44 AM
Thank you, everyone! This was very helpful. Hopefully I will get the hang of this kind of stuff soon.
© mIRC Discussion Forums