openkore
openkore copied to clipboard
[eventMacro] if statement bug
I'm doing macro for spam blocking and I'm faced that if statement is bugged, it does not work with some phrases that contains <<<<<<< or >>>>>> symbols My macro:
automacro spampm {
PrivMsg /./i
call {
if( $.PrivMsgLastMsg =~ /(w.*|W.*|v.*|V.*).*(c[o0]m|C[0O]M)/ ) {
do ignore 1 $.PrivMsgLastName
log Ignoring $.PrivMsgLastName
}
}
}
Console error message:
[eventMacro] Error in macro 'tempMacro15' [eventMacro] Line index of the error '0' [eventMacro] Script of the line 'if ( $.PrivMsgLastMsg =~ /(w.|W.|v.|V.).*(c[o0]m|C[0O]M)/ ) {' [eventMacro] Error message 'syntax error in if statement'
The private message from spamer:
[PM] (From: uf1295) : WWW.AOAUE.COM >>>>>>>>>>>>>>>10Mil Zeny = 3 usd>>>>Buy Zeny Get 5% Bonus >>>>WWW.AOAUE.COM >>>>>>>>>>>>5700
You're missing a closing bracket.
Sorry, forgot it when I was trying to reproduce the bug. I've edited first post
Okay, so why use the if statement for the regex detection? I'm sure the parentheses of regex is messing with the if statement formatting. Try this.
automacro spampm {
PrivMsg /(w.*|W.*|v.*|V.*).*(c[o0]m|C[0O]M)/
call {
do ignore 1 $.PrivMsgLastName
log Ignoring $.PrivMsgLastName
}
}
It will only activate when a private message contains your desired regex. No need for a check for a private message first, then check what the message contains.
regex on eventMacro doesn't support you use (
and )
inside regex on an if condition
however, in a automacro condition, it works normally
there is a Pull Request to solve this issue (i did it) but only the creator of eventMacro can approve, and he is VERY busy with college #1205
and this regex is wrong
you could do it like this :
if ( $.PrivMsgLastMsg =~ /www\..*\.com/i )
I highly recommend you all using the strict regex.
In this case, I suggest www\.[\w\d-_]*\.co(m|\.\w+)
to catch the URL.
If you want to examine or test out regex, please try it on online regex tester sites. i.e. https://regexr.com/