mIRC Home    About    Download    Register    News    Help

Topic Options
#231255 - 10/04/11 05:07 AM set mode -i, help?
badcarwash Offline
Self-satisified door

Registered: 10/04/11
Posts: 4
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?

Top
#231256 - 10/04/11 05:17 AM Re: set mode -i, help? [Re: badcarwash]
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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.

Top
#231258 - 10/04/11 05:50 AM Re: set mode -i, help? [Re: RusselB]
badcarwash Offline
Self-satisified door

Registered: 10/04/11
Posts: 4
So, would this be correct, then?

on *:MODE:#: {
if (mode $chan +i) {
mode $chan -i }
}

Top
#231259 - 10/04/11 06:39 AM Re: set mode -i, help? [Re: badcarwash]
genius_at_work Offline
Hoopy frood

Registered: 08/10/05
Posts: 1741
Try this:

Code:

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



(untested)

-genius_at_work

Top
#231264 - 10/04/11 12:15 PM Re: set mode -i, help? [Re: genius_at_work]
badcarwash Offline
Self-satisified door

Registered: 10/04/11
Posts: 4
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.

Top
#231265 - 10/04/11 01:01 PM Re: set mode -i, help? [Re: badcarwash]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
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.


Edited by Riamus2 (10/04/11 03:18 PM)
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#231270 - 10/04/11 03:08 PM Re: set mode -i, help? [Re: Riamus2]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
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"

Top
#231271 - 10/04/11 03:18 PM Re: set mode -i, help? [Re: hixxy]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
Thanks. I was apparently thinking of both methods and ended up combining them. Still learning. laugh

I edited the previous post.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#231281 - 10/04/11 08:02 PM Re: set mode -i, help? [Re: Riamus2]
Tomao Offline
Hoopy frood

Registered: 07/07/07
Posts: 1129
Loc: United States
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)))
  }
}

Top
#231291 - 11/04/11 01:21 AM Re: set mode -i, help? [Re: Tomao]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: NC, USA
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.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#231293 - 11/04/11 03:44 AM Re: set mode -i, help? [Re: badcarwash]
badcarwash Offline
Self-satisified door

Registered: 10/04/11
Posts: 4
Thank you, everyone! This was very helpful. Hopefully I will get the hang of this kind of stuff soon.

Top