OpenKore / openkore

A free/open source client and automation tool for Ragnarok Online
http://openkore.com
Other
1.28k stars 1.04k forks source link

[eventMacro] if statement bug #1316

Open Yakov-Chernogor opened 6 years ago

Yakov-Chernogor commented 6 years ago

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

Asonael commented 6 years ago

You're missing a closing bracket.

Yakov-Chernogor commented 6 years ago

Sorry, forgot it when I was trying to reproduce the bug. I've edited first post

Asonael commented 6 years ago

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.

Nipodemos commented 6 years ago

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 )

windhamwong commented 6 years ago

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/