mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2014
Posts: 14
S
Pikka bird
OP Offline
Pikka bird
S
Joined: Apr 2014
Posts: 14
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!

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
$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 }


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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)) {

Last edited by Loki12583; 23/07/14 12:21 AM.
Joined: Mar 2014
Posts: 215
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
i would think
Code:
if ($1- >= 0.5) { stuff }
but idk


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Joined: Apr 2014
Posts: 14
S
Pikka bird
OP Offline
Pikka bird
S
Joined: Apr 2014
Posts: 14
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.

Last edited by spamgirl; 22/07/14 11:52 PM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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) {

Joined: Apr 2014
Posts: 14
S
Pikka bird
OP Offline
Pikka bird
S
Joined: Apr 2014
Posts: 14
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

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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
}

Joined: Apr 2014
Posts: 14
S
Pikka bird
OP Offline
Pikka bird
S
Joined: Apr 2014
Posts: 14
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...

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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.

Joined: Apr 2014
Posts: 14
S
Pikka bird
OP Offline
Pikka bird
S
Joined: Apr 2014
Posts: 14
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?

Last edited by spamgirl; 24/07/14 01:49 AM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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)

Last edited by Loki12583; 24/07/14 02:12 AM.
Joined: Apr 2014
Posts: 14
S
Pikka bird
OP Offline
Pikka bird
S
Joined: Apr 2014
Posts: 14
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!

Last edited by spamgirl; 24/07/14 12:16 PM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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)

Last edited by Loki12583; 24/07/14 12:50 PM.

Link Copied to Clipboard