mIRC Homepage
Posted By: spamgirl Equal to or greater than text match - 22/07/14 07:25 PM
I have a simple script:

on *:text:*math*:#:{
IF (*number >= .5*) {
/msg $me High number math
}
ELSEIF (*no math * iswm $1-) {
/msg $me No math
}
ELSE {
/msg $me Low math
}
}

My question is what do I put to cause any mention of any number from .5 upwards to trigger the IF section? I've highlighted the area I mean in red. Thanks for your help!
Posted By: Nillen Re: Equal to or greater than text match - 22/07/14 07:42 PM
$1 returns the first word mentioned in the on text event
$2 returns the second...

Assuming that the actual value you're looking for is the third word, you'd use
Code:
if ($3 >= .5) { do stuff }
Posted By: Loki12583 Re: Equal to or greater than text match - 22/07/14 08:13 PM
This becomes a bit more complicated if you allow the number anywhere in the input and if you allow other characters like operators to touch them. Is that what you want?

Here's a terrible, terrible solution for that problem:
Code:
if ($regex($1-,/(^|[^\.\d])0*[1-9]|\.[5-9]/S)) {
Posted By: judge2020 Re: Equal to or greater than text match - 22/07/14 11:48 PM
i would think
Code:
if ($1- >= 0.5) { stuff }
but idk
Posted By: spamgirl Re: Equal to or greater than text match - 22/07/14 11:50 PM
Originally Posted By: Loki12583
This becomes a bit more complicated if you allow the number anywhere in the input and if you allow other characters like operators to touch them. Is that what you want?


Yes, that's the problem - the text which comes before it will vary in length unpredictably. frown For example:

!The Name Is Here - There is a title which goes here and can be very long or very short ($0.06)

or

!category !The Name Is Here There is a title which goes here and can be very long or very short $0.10

Those are the two formats the text it is to be triggered by take.
Posted By: Loki12583 Re: Equal to or greater than text match - 23/07/14 12:21 AM
Well then as I see it regular expressions are your only option.

You can use this single regex which is tailored to your needs:
Code:
if ($regex($1-,/(^|[^\.\d])0*[1-9]|\.[5-9]/S)) {


Or you can identify and loop over all numbers (I like this regex even less):
Code:
var %large, %i = $regex($1-,/(\d*(?:\.\d+))/Sg)
while (%i) {
  if ($regml(%i) >= .5) { %large = 1 | break }
  dec %i
}
if (%large) {
Posted By: spamgirl Re: Equal to or greater than text match - 23/07/14 06:17 PM
Originally Posted By: Loki12583
Well then as I see it regular expressions are your only option.

You can use this single regex which is tailored to your needs:
Code:
if ($regex($1-,/(^|[^\.\d])0*[1-9]|\.[5-9]/S)) {


I tried that and it just alerted on this:

!Name !Title $0.04
Posted By: Loki12583 Re: Equal to or greater than text match - 23/07/14 07:02 PM
Not according to this:
Code:
alias test {
  tokenize 32 $(!Name !Title $0.04,0)
  if ($regex($1-,/(^|[^\.\d])0*[1-9]|\.[5-9]/S)) {
    echo -ag big
  }
  else echo -ag small
}
Posted By: spamgirl Re: Equal to or greater than text match - 23/07/14 08:07 PM
I just copied and pasted that into my script:

on *:text:*math*:#channel:{
IF (badtext) {
halt
}
ELSEIF ($regex($1-,/(^|[^\.\d])0*[1-9]|\.[5-9]/S)) {
window @UrgentAlert 0 0 1275 875
aline -pi @UrgentAlert $remove(( $time ), $chr(32)) 12 $nick  7 $chan  11 $1- $+
splay urgent.wav
}
ELSE {
window @RegularAlert 0 0 1275 875
aline -pi @RegularAlert $remove(( $time ), $chr(32)) 12 $nick  7 $chan  11 $1- $+
splay beep.wav
}
}

And then tested it with 28.50 and 0.02 and both alerted in the urgent window with the urgent wav...
Posted By: Loki12583 Re: Equal to or greater than text match - 23/07/14 09:05 PM
Well I just tested it with that and they both went to the correct windows. I did have to change "badtext" to 0 so that it wouldn't halt.

Are you sure you don't have a similar script loaded and interfering? Insert debug print statements to make sure you're at the lines you think you are. If you can, provide a single test alias like I did before to reliably demonstrate the problem.
Posted By: spamgirl Re: Equal to or greater than text match - 24/07/14 01:34 AM
Originally Posted By: Loki12583
Well I just tested it with that and they both went to the correct windows. I did have to change "badtext" to 0 so that it wouldn't halt.

Are you sure you don't have a similar script loaded and interfering? Insert debug print statements to make sure you're at the lines you think you are. If you can, provide a single test alias like I did before to reliably demonstrate the problem.


I've found the problem - within the entire text there is a URL which has numbers in it. While they don't have a period, they're setting it off.

!Name Title ($0.02) does nothing
!Name Title ($0.02) https://www.website.com/page.html?Id=3X19M43Z4VULD73G1I2N3GGRYF10D8 sets it off.

Is there a way to force the script to only go off on a number which has a decimal in it?
Posted By: Loki12583 Re: Equal to or greater than text match - 24/07/14 02:07 AM
Well I wish you would have mentioned that to begin with, it's much easier.

To allow text as ".5"
Code:
$regex($1-,/\.[5-9]/S)


To force the full dollar amount "$0.5":
Code:
$regex($1-,/\x24\d+\.[5-9]/S)
Posted By: spamgirl Re: Equal to or greater than text match - 24/07/14 12:00 PM
Originally Posted By: Loki12583
Well I wish you would have mentioned that to begin with, it's much easier.

To allow text as ".5"
Code:
$regex($1-,/\.[5-9]/S)


To force the full dollar amount "$0.5":
Code:
$regex($1-,/\x24\d+\.[5-9]/S)


The problem is that it also has to allow $1.0, etc. I figured out a dirty way to do it, which sucks, but works:

IF ((*0.0* iswm $1-) || (*0.1* iswm $1-) || (*0.2* iswm $1-) || (*0.3* iswm $1-) || (*0.4* iswm $1-)) {
don't do urgent stuff
}

ELSE {
do urgent stuff
}
}

And that's working for now. smile Thanks for your help!
Posted By: Loki12583 Re: Equal to or greater than text match - 24/07/14 12:36 PM
Right, my bad. This will trigger on $0.50, $1.0, $1.5...
Code:
$regex($1-,/\x24([1-9]\d*\.\d+|0+\.[5-9])/S)
© mIRC Discussion Forums