mIRC Home    About    Download    Register    News    Help

Print Thread
#231255 10/04/11 04:07 AM
Joined: Apr 2011
Posts: 4
B
Self-satisified door
OP Offline
Self-satisified door
B
Joined: Apr 2011
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?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

Joined: Apr 2011
Posts: 4
B
Self-satisified door
OP Offline
Self-satisified door
B
Joined: Apr 2011
Posts: 4
So, would this be correct, then?

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

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Try this:

Code:

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



(untested)

-genius_at_work

Joined: Apr 2011
Posts: 4
B
Self-satisified door
OP Offline
Self-satisified door
B
Joined: Apr 2011
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.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.

Last edited by Riamus2; 10/04/11 02:18 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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"

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
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)))
  }
}

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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
Joined: Apr 2011
Posts: 4
B
Self-satisified door
OP Offline
Self-satisified door
B
Joined: Apr 2011
Posts: 4
Thank you, everyone! This was very helpful. Hopefully I will get the hang of this kind of stuff soon.


Link Copied to Clipboard