|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
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? on *:text:*:#: {
if (expletive iswn $1-) { /kick $chan $nick }
elseif (expletive2 iswm $1-) { /kick $chan $nick }
etc
} or on *:text:*:#: {
if (expletive isin $1-) { /kick $chan $nick }
elseif (expletive2 isin $1-) { /kick $chan $nick }
etc
}
|
|
|
|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
Hoopy frood
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"
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2007
Posts: 228 |
I think I follow you. So, in this situation, isin would be the right choice. Thanks.
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2007
Posts: 228 |
However, say, I wanted to put a list of expletives in a file: expletive1 expletive2 expletive3
if ($read(expletives.txt) isin $1-) { /kick $chan $nick } How's that?
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
I think it'd be better if you used: if ($read(expletives.txt,w,$+(*,$1-,*))) { kick $chan $nick }
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
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.: 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
}
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2007
Posts: 228 |
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.: 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: 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.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Is that the same as != $null? -> Yes
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2007
Posts: 228 |
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
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. 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: 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.
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2007
Posts: 228 |
So basically, means "if %x exists and doesn't equal zero" and means "if %x exists or equals zero" Correct?
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
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".
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
Joined: Apr 2007
Posts: 228 |
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
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. 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.
|
|
|
|
Joined: Jun 2007
Posts: 933
Hoopy frood
|
Hoopy frood
Joined: Jun 2007
Posts: 933 |
You could use $istok instead. 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.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
I suggest (inside your original loop): 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: 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.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
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)
|
|
|
|
Joined: Apr 2007
Posts: 228
Fjord artisan
|
OP
Fjord artisan
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.
|
|
|
|
|