mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#211967 06/05/09 08:27 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
How exactly do isin and iswm operate differently? Say, if you wanted to catch an expletive, which would be better?

Code:
on *:text:*:#: {
  if (expletive iswn $1-) { /kick $chan $nick }
  elseif (expletive2 iswm $1-) { /kick $chan $nick }
  etc
}


or

Code:
on *:text:*:#: {
  if (expletive isin $1-) { /kick $chan $nick }
  elseif (expletive2 isin $1-) { /kick $chan $nick }
  etc
}

Mpot #211970 06/05/09 08:59 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
iswm as stated by the help is a wildcard match,

a wildcard match is a string of text with the "*" character meaning "any set of 0 or more characters" and "?" meaning "exactly one character". If you don't specify any of these wildcard characters in a match, the comparison is made literally, from the beginning of the string to the end:

(HELLO iswm HELLO WORLD) is equivalent to (HELLO == HELLO WORLD) without wildcards -- this obviously will not work.

If you wrote *HELLO it would search for anything ending in HELLO

HELLO* would look for anything beginning with HELLO

*HELLO* would be anything with HELLO inside of it

The last behaviour, if you didn't catch it, is equivalent to that of the isin operator.

--

So really, iswm is a superset of the isin functionality. If you're only testing the existence of a substring in a larger string, use isin. If you have specific constraints on where the substring should be (beginning, end, or more complex constraints), use iswm to build a wildcard match.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
argv0 #211971 06/05/09 09:09 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
I think I follow you. So, in this situation, isin would be the right choice. Thanks.

Mpot #211972 06/05/09 09:25 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
However, say, I wanted to put a list of expletives in a file:

Quote:

expletive1
expletive2
expletive3


Code:
if ($read(expletives.txt) isin $1-) { /kick $chan $nick }


How's that?

Mpot #211974 06/05/09 10:04 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I think it'd be better if you used:
Code:
if ($read(expletives.txt,w,$+(*,$1-,*))) { kick $chan $nick }


Tomao #211976 06/05/09 10:13 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
I think the OP don't want to check TEXT isin <any line>, but <any line> isin TEXT. In this case - if a text file is used as the source - a loop is inevitable. e.g.:
Code:
  var %n = 1
  while ($read(expletives.txt,n,%n)) {
    if ($v1 isin $1-) {
      kick $chan $nick Your message contained badword $qt($v1)
      break
    }
    inc %n
  }

Horstl #211977 06/05/09 11:32 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Originally Posted By: Horstl
I think the OP don't want to check TEXT isin <any line>, but <any line> isin TEXT. In this case - if a text file is used as the source - a loop is inevitable. e.g.:
Code:
  var %n = 1
  while ($read(expletives.txt,n,%n)) {
    if ($v1 isin $1-) {
      kick $chan $nick Your message contained badword $qt($v1)
      break
    }
    inc %n
  }


I think that's what I'm looking for. Thanks. I have a question though. This line:
Code:
while ($read(C:\IcyBot2\expletives.txt,n,%n))
doesn't seem to have the while compare against something. Is that the same as != $null?

Last edited by Mpot; 06/05/09 11:37 PM.
Mpot #211979 07/05/09 12:06 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Is that the same as != $null? -> Yes

RusselB #211980 07/05/09 12:18 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Thanks.

RusselB #211981 07/05/09 12:23 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Not exactly. if (something) is false whenever "something" is $null, 0 or $false.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Mpot #211982 07/05/09 12:28 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
It's like != $null && != 0. But that's nit-picking in your concrete case, as you'll hardly add "0" as a badword to the file. smile

In other situations, especially if numerical values are involved, the difference between if (something) and if (something != $null) can be both a pitfall and useful for scripts. Take for example some "boolean switch" (0=false 1=true) in an .ini or the like.

You can see the difference at %y in this example:
Code:
alias test {
 var %x = 1, %y = 0, %z
 if (%x != $null) echo -a x has some value
 if (%y != $null) echo -a y has some value
 if (%z != $null) echo -a z has some value
 if (%x) echo -a x has a value that isn't 0
 if (%y) echo -a y has a value that isn't 0
 if (%z) echo -a z has a value that isn't 0
}

qwerty beat me to it

Last edited by Horstl; 07/05/09 12:31 AM.
Horstl #211986 07/05/09 01:35 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
So basically,

Code:
if (%x)
means "if %x exists and doesn't equal zero"

and

Code:
if (%x != $null)
means "if %x exists or equals zero"

Correct?

Mpot #211987 07/05/09 01:59 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Well, qwerty's answer was more precise.

I'll try to be precise just as much:
- your variable may "exist" without any value assigned
- if (%x != $null) is true if %x has *any* value assigned
- if (%x) is true if %x has a value asssigned AND this value is neither "0" nor "$false".

Horstl #211988 07/05/09 03:39 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Got it!

Horstl #212030 08/05/09 09:42 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Just to nitpick, if (%x) will also fail if the value of %x is mathematically 0. This means it will fail if %x is 00 or 000, etc.

hixxy #212118 11/05/09 07:10 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Little problem. One of the words on the list is "mom". People are getting kicked when they say "moment". Obviously this makes sense, but how would you go about forcing the script to evaluate each word as a whole? Tokenizing, perhaps?

Edit: Okay, I came up with this. It's either batshit crazy or it works.

Code:
on *:text:*:#auroratest: {
  var %text = $1-
  tokenize 32 %text
  var %n3 = $numtok(%text,32)
  var %n = 1
  var %word = $+($,%n2)
  var %2n = 1
  while ($read(C:\IcyBot2\expletives.txt,n,%n)) {
    while (%n2 <= %numtok) {
      if ($v1 == %word) { 
        kick $chan $nick You said $read(C:\IcyBot2\kicks.txt,w,* $+ $v1 $+ *)
        break
      }
      inc %n
      inc %n2
    }
  }
}

Last edited by Mpot; 11/05/09 07:36 PM.
Mpot #212121 11/05/09 07:38 PM
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
You could use $istok instead.
Code:
if ($istok($1-,your.mom.jokes,46))

In this example the if-statement is true if the *single* words "your" "mom" or "jokes" are in the line.

Mpot #212125 11/05/09 07:45 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
I suggest (inside your original loop):
Code:
  if ($istok($1-,$v1,32)) { kick with some general reason }
(the $v1 is the line just read)

or, to repeat the match in the kick message:
Code:
  if ($findtok($1-,$v1,32)) { kick with reference to the matching token: $gettok($1-,$v1,32) }
(the first $v1 is the line just read, the second $v1 is the number of the token just found)

Or, if you have wildcard definitions in the file, you have to go for $wildtok instead of $findtok.

Last edited by Horstl; 11/05/09 07:55 PM.
5618 #212126 11/05/09 07:49 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
This won't work, the parameters are the other way arround.
true: $istok(your.mom.jokes,mom,46)
not true: $istok(mom,your.mom.jokes,46)

Horstl #212127 11/05/09 08:04 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
You've completely lost me.

($findtok($1-,$v1,32))

=

if $v2 (the bad word we're on) is anywhere in the $1- (the spoken line)

?

Last edited by Mpot; 11/05/09 08:14 PM.
Page 1 of 2 1 2

Link Copied to Clipboard