mIRC Home    About    Download    Register    News    Help

Topic Options
#262229 - 11/01/18 02:41 AM looking for conditions / from a username
DJQuad Offline
Pikka bird

Registered: 01/07/17
Posts: 10
So I'm starting with this very basic script


Code:
on *:TEXT:*hello*:#channe123:{
  /msg $chan hey $nick <3
}

I'd like to add to that but am confused about some conditions. Here are some examples
(name123) hello
(nameABC) hello
(me) hi nameABC

The condition should only be met if nameABC says it.

Another example:
(nameXXX) gives a high 5 to nameYYY
(me) nameYYY got a high 5 from nameXXX

Another example with more variables:
(nameXXX) gives 16 high 5s to nameYYY
(me) nameYYY got 16 high 5s from nameXXX

I'm assuming each example would involve some regex to match the condition with variables for the response, but simple examples would really help.


Edited by DJQuad (11/01/18 02:44 AM)

Top
#262230 - 11/01/18 07:50 AM Re: looking for conditions / from a username [Re: DJQuad]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3331
Loc: France
Hello

Quote:
The condition should only be met if nameABC says it.

Code:
on *:TEXT:*hello*:#channe123:{
 if ($nick == nameABC) msg $chan hey $nick <3
}


Code:
on *:TEXT:& gives a high 5 to &:#channe123:{
 if ($1 ison $chan) && ($7 ison $chan) msg $chan $7 got a high 5 from $1
}


Code:
on *:TEXT:& gives & high 5s to &:#channe123:{
 if ($1 ison $chan) && ($3 isnum) && ($7 ison $chan) msg $chan $7 got $3 highs 5 from $1
}


The last two codes could indeed be merged using regex, (or maybe still even using wildcard) but if you don't know how to make this without regex it's probably not a good idea to try to start using regex right now, at least I don't recommend it.

Check https://en.wikichip.org/wiki/mirc/conditional_statements & https://en.wikichip.org/wiki/mirc/operators to learn more about if statement and the different operator mIRC supports.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#262239 - 12/01/18 12:35 AM Re: looking for conditions / from a username [Re: Wims]
DJQuad Offline
Pikka bird

Registered: 01/07/17
Posts: 10
Thank you! I've been playing with your helpful examples, but I'm stuck on this -

<hnlbot> user johndoe123 just enlisted for 2 months

This doesn't work

Quote:
on *:TEXT:& just enlisted for & months:#djquad:{
if ($1 ison $chan) && ($3 isnum) msg $chan $3 months for $1
}


Also, I guess this a rate limit question, but if I see this in chat:

<userABC> hi there hi there hi there hi there
<userXYZ> hello
<user123> hi there hi there hi there hi there

I'd like to look for the spam of "hi there", but just once and respond

<me> stop spamming hi there

Top
#262244 - 12/01/18 06:35 PM Re: looking for conditions / from a username [Re: DJQuad]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 803
Be sure to look at the wikichip links above, and the other topics at that wiki. They often give a little more detail than mentioned in the F1 help.

In your example, you are using ampersand incorrectly. That field should use wildcards ? as a single character and asterisk as 1-or-more characters. "*enlisted for ?? months*" would only match when the word before 'months' has 2 digits.

Also, look at words as if they are values separated by at least 1 space, even if they are touched by color codes or punctuation. $1 is the first 'word' of the line, so in your example, $1 is 'user', so $2 is johndoe123 and $6 is the the 6th word '2'. $nick is the nick saying the message, in this case it's hnlbot.

You can trap rate limited data using a variable that unsets after N seconds. When you use global variables which remain outside your alias or on-text, you should avoid using simple names like %a or %short_word which might also be used by a different script. If you are using %var to create local variables which disappear outside the ON TEXT or your alias, it's fine to use %a or %x as long as you first define them as blank or another value, to prevent them containing the value in the global variable, which continues to exist after your local variable vanishes. If you have an on text which triggers only for lines containing *hi there*, you can use that to increase the counter.

Code:
on *:TEXT:*hi there*:#djquad:{
  inc -u30 %hithere_counter $count($1-,hi there)
  if (%hithere_counter isnum 3-) msg $chan hey $nick - <message>
}


The -uN switch makes the variable unset 30 seconds later, so each time the -u30 is used to increment the counter, the 30 second clock gets reset to 30. If you don't want the clock reset each time:

inc $iif( !%hithere_counter,-u30) %hithere_counter $count($1-,hi there)

This uses the -u30 only to create the variable, so it disappears 30 seconds after the 1st 'hi there' regardless how many times triggered during that 30 seconds.

if $1- is 'hi there hi there' $count returns 2. You don't want to use /inc -u30 for all lines even when $count returns 0 because the countdown clock gets reset to to 30 each time a chat message appears.

Be careful about using a %variable with /inc if it could be blank:

unset %x
inc %a %x

This is the same as "inc %a" and increases %a by 1.

Also, the purple messages created by "/me says hi there" use the event ON ACTION, so you would also need to trap that if you want the script to see those too.

Be careful about putting more than 1 ON TEXT in a script.

Code:
on *:TEXT:*test*:#djquad:{
  echo -a event 1
}
on *:TEXT:*:#djquad:{
 echo -a event 2
}


The 1st one traps all messages containing 'test', preventing them from being trapped by the 2nd one.

Top
#262247 - 13/01/18 03:05 AM Re: looking for conditions / from a username [Re: maroon]
DJQuad Offline
Pikka bird

Registered: 01/07/17
Posts: 10
Things are making a lot more sense. I did misunderstand the $variable. It makes sense how it counts words.

Quote:
on *:TEXT:& just enlisted for & months:#djquad:{
Quote:
In your example, you are using ampersand incorrectly. That field should use wildcards ? as a single character and asterisk as 1-or-more characters. "*enlisted for ?? months*" would only match when the word before 'months' has 2 digits.
The ampersand seems to work whether it's 2 or 20 months.

I'm not treating it as a number, just a word. If I were treating it as a number, I'd use isnum 1-99 instead of just isnum right?

Top
#262248 - 13/01/18 03:14 AM Re: looking for conditions / from a username [Re: DJQuad]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 803
sorry, you're right.
and...
if ($6 isnum) true for all numbers even zero and negatives
if ($6 isnum 1-) true for all numbers 1 and greater
if ($6 isnum 1-99) true for all numbers 1 through 99
if ($6 isnum) not true if it's a number touched by comma or color codes

Top
#262361 - 26/01/18 11:30 PM Re: looking for conditions / from a username [Re: maroon]
DJQuad Offline
Pikka bird

Registered: 01/07/17
Posts: 10
Can someone tell me why this doesn't work?
Code:
; <@djquad> meepere gives 16 high fives to nameYYY

on *:TEXT:& gives & high 5s to &:#djquad:{
 msg $chan $7 got $3 highs 5 from $1
}


Edited by DJQuad (26/01/18 11:38 PM)

Top
#262362 - 27/01/18 12:31 AM Re: looking for conditions / from a username [Re: DJQuad]
KindOne Offline
Fjord artisan

Registered: 23/02/11
Posts: 298
You typed "fives" instead of "5s" in the script.
_________________________
irc.swiftirc.net #msl (mIRC Scripting Language)

Top
#262372 - 27/01/18 04:50 PM Re: looking for conditions / from a username [Re: KindOne]
DJQuad Offline
Pikka bird

Registered: 01/07/17
Posts: 10
Thanks, I knew it had to be something entirely freaking stupid.

Top