mIRC Home    About    Download    Register    News    Help

Print Thread
$regex/$regml help #212876 08/06/09 03:55 AM
Joined: Mar 2004
Posts: 359
L
LostServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Mar 2004
Posts: 359
I may not be even doing this right, but basically what I want to do is with on mode, check for specific modes being set, and if I find one (or more) (by themselves or multiple modes set at once), then display which modes were set to a seperate channel. For example:

in #mainchannel:
* User1 sets mode: +imN

in #botchannel:
* <Bot> #mainchannel +imN by User1.


It works right (as in, the $regex string triggers the modes perfectly) from what I can tell, all except for when I try to display them. (Note: $_botchan is fine)
Code:
on *:mode:#: {
  if ($me ison $_botchan) {
    if ($regex(fmode,$1,/^[\+]?[iRmN]+$/)) { msg $_botchan $chan Modes: $regml(fmode,1) set by $nick }
  }
}

I've been playing around with various things to try and get it to work, $regml $ifmatch $v1 $v2.. I'm stumped.

Re: $regex/$regml help [Re: LostServ] #212881 08/06/09 07:09 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
on @*:RAWMODE:#: {
  if ($me ison $_botchan) && ($regex(fmode,$1,/\+[^\-]*(i\S*|R\S*|m\S*|N\S*)/)) .msg $_botchan $chan Mode(s): $+(+,$regml(1)) set by $nick $+ .
}
You can also use on mode event if you want.

Last edited by Tomao; 08/06/09 07:32 AM.
Re: $regex/$regml help [Re: LostServ] #212882 08/06/09 07:22 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Made a little mistake. Corrected.

Re: $regex/$regml help [Re: LostServ] #212883 08/06/09 09:22 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
If you're happy with your current regex and just want to have the the $regml return something: put the respective part of the regex inside round brackets to create your back reference, e.g.: /^([\+]?[iRmN]+)$/ for the whole string.

Re: $regex/$regml help [Re: LostServ] #212886 08/06/09 10:11 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I agree with Horstl. But with the round bracket, it will still return a single mode, so that needs to change to:
Quote:
/^([\+]?[iRmN]\S*)$/))

Last edited by Tomao; 08/06/09 10:14 AM.
Re: $regex/$regml help [Re: Tomao] #212887 08/06/09 10:48 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Hm, not exactly. It matches/returns:
"start of the string, possibly followed by a single plus char, followed by one or more chars out of "iRmN", followed by no other chars (end of string)"
It matches/returns for example: mr / +m / +miR / +Ni / N
It won't match: +I / +R-m / -i / + / +mk somekey

Now I don't know what the OP intended to match/return... Not all of the matched examples are possible values of $1- in "on mode", while some out of the unmatched examples are possible values. smile

If the goal is to message any changes in the modes iRmN, ignoring changes of other modes:
Code:
on *:mode:#: {
  if ($me ison $_botchan) { 
    ; remove from the first word of the mode string everything that is no char out of: iRmN+-
    ; if anything besides "+" and/or "-" remains: message the changes of the modes "iRmN" to $_botchan
    var %m = $regsubex($1,/[^iRmN+-]/g,$null)
    if ($remove(%m,+,-)) {
      msg $_botchan $chan Modes: $replace($iif(($right(%m,1) isin +-),$left(%m,-1),%m),+-,-,-+,+) set by $nick
    }
  }
}

Edit: added part to remove leading/trailing mode prefixes if followed by no mode. I admit it's not pretty though smirk

Re: $regex/$regml help [Re: Horstl] #212892 08/06/09 03:29 PM
Joined: Mar 2004
Posts: 359
L
LostServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Mar 2004
Posts: 359
The regex /^([\+]?[iRmN]+)$/ almost worked. It didn't work in situations where it was +i-G, etc.

Code:
on *:mode:#: {
  if ($me ison $_botchan) { 
    ; remove from the first word of the mode string everything that is no char out of: iRmN+-
    ; if anything besides "+" and/or "-" remains: message the changes of the modes "iRmN" to $_botchan
    var %m = $regsubex($1,/[^iRmN+-]/g,$null)
    if ($remove(%m,+,-)) {
      msg $_botchan $chan Modes: $replace($iif(($right(%m,1) isin +-),$left(%m,-1),%m),+-,-,-+,+) set by $nick
    }
  }
}

This is almost it.. however after playing with it I still can't make it ignore the changes if they are unset, I just need it to show when they are set.

Thanks for all the help so far guys.

Re: $regex/$regml help [Re: LostServ] #212893 08/06/09 04:00 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Ah, I thought you wanted to track both set and unset of these modes. Try:
Code:
on *:mode:#: {
  if ($me ison $_botchan) && ($regsubex($gettok($1,$iif((- isin $1),2,1),43),/[^iRmN]/g,$null)) {
    msg $_botchan $chan Modes: + $+ $v1 set by $nick
  }
}
This code assumes that if both +<mode(s)> and -<mode(s)> are set in the same mode string, the "-" modes will preceed the "+" modes, which afaik will always be true.

Re: $regex/$regml help [Re: Horstl] #212894 08/06/09 04:04 PM
Joined: Mar 2004
Posts: 359
L
LostServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Mar 2004
Posts: 359
If I read it right, you meant that is wasn't possible. It is on UnrealIRCd anyway:

Edit: It works both ways.

* Phase sets mode: +m-iQ
* Phase sets mode: +iRNT-m

* Phase sets mode: -i+l 23

Last edited by LostServ; 08/06/09 04:10 PM.
Re: $regex/$regml help [Re: LostServ] #212895 08/06/09 04:21 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Nah, gettok was to keep it more simple; and sorry for the wrong assumtion wink It's possible, e.g. by changing the if-line to:
Code:
  if ($me ison $_botchan) && ($regsubex($regsubex($1,/-\w+/,$null),/[^iRmN]/g,$null)) {
The inner regsubex removes a possible "-<mode(s)>" from $1. The outer regsubex removes any char that is not i,R,m, or N from what's left. If any chars are left now, they should be the mode(s) you're looking for.

Re: $regex/$regml help [Re: Horstl] #212896 08/06/09 04:30 PM
Joined: Mar 2004
Posts: 359
L
LostServ Offline OP
Fjord artisan
OP Offline
Fjord artisan
L
Joined: Mar 2004
Posts: 359
This appears to be working perfectly. Thanks for your help. smile