pattern matching
Hey, anyone good at this could help me match this message so i can filter it ?
Playername-Realm is now roleicon Tank. (Changed by Playerame.) roleicon is, well, the icon :) and Realm may contain spaces |
First, you need to figure out which global string gets used. When filtering system messages, you should always use the relevant global string, so it works in all languages and automatically works if/when Blizzard changes the string. In this case, it's ROLE_CHANGED_INFORM_WITH_SOURCE, which in its raw state looks like "%s is now %s. (Changed by %s.)" in English, "%s ist nun %s. (Von %s geändert.)" in German, etc.
Second, you need to use some gsub magic to turn that string into a pattern you can use with string.find. Here's the function I use that will turn any Blizzard global string into a search pattern: Code:
local function topattern(str) (a) If you're only working with a few strings, you may be tempted to just gsub them directly, but then if Blizzard changes them (for example, changes %s tokens to %1$s tokens, or adds a token) you have to update. The above function will automatically handle any such changes, unless Blizzard adds some new type of tokens. (b) The above function doesn't add captures, so it's mainly for use with string.find -- is this a "X defated Y in a duel" message? -- and not with string.match -- what are the values of X and Y in this message?. Back on topic -- to hide the messages: Code:
local pattern = topattern(ROLE_CHANGED_INFORM_WITH_SOURCE) Code:
local patterns = { |
This is absolutely perfect, and will simplify my filters file ten fold.
There's one system message i can't seem to find in the GlobalStrings though "Playername is not online." Any idea how it's possible that it isn't there ? Could it be an addon sending a message through that channel or ? |
Well, you could search your Addons folder for the phrase "not online". Some messages are sent pre-formed from the server, though, and don't have global strings, so you'll have to use hardcoded translations for them, unfortunately. :/
|
Did that, but:
Search "is not online." (0 hits in 0 files) Ah well, that's no big deal, thanks a lot anyway ! |
So it should look like this but somehow, the role thingy isn't filtered
Code:
local patternize = function(text) |
Code:
ROLE_CHANGED_INFORM = "%s is now %s."; |
Quote:
|
What? I meant that your code is missing a string, and that's why you're still seeing messages about roles being changed. There are two separate global strings for this:
Code:
ROLE_CHANGED_INFORM_WITH_SOURCE = "%s is now %s. (Changed by %s.)"; Code:
ROLE_CHANGED_INFORM = "%s is now %s."; Your code only looks for the first string (changed by another player) and not the second one. |
Oh i know, i do have both, but those just aren't filtered:
Code:
local topattern = function(text) |
Use debug prints to figure out what the problem is.
Code:
local topattern = function(text) |
Thing is, with this, absolutely nothing gets printed. How can that be ?
|
The first print is missing a closing parenthesis. You'll want to enable Lua errors to catch these kind of errors easily.
|
Quote:
Well, no, obviously i fixed that before even trying :) |
Then "if strfind(message, " is now ") then" must be failing. Print the message too, I guess, just to be sure.
|
Quote:
Code:
NO MATCH: .+ is now .+. |
And what's the chat message?
|
Quote:
Code:
MESSAGE: You are now queued in the Raid Finder. 0 Hard to tell for now. Doesn't make much sense tbh. |
So a chat msg fits your "if" but the whole message is not in your patterns. Whats wrong ?
|
Quote:
|
They do, when you add the global string of the message ("You are now queued in the Raid Finder.") to your pattern list.
from GlobalStrings.lua Lua Code:
|
Quote:
This is what i want to filter, but those just aren't: Code:
ROLE_CHANGED_INFORM = "%s is now %s."; |
Quote:
Move the print(message) to outside of the if-block and see what it says when someone sets their role. EDIT: Ok ok, it's not even a chat event, hah. :P Code:
ROLE_CHANGED_INFORM(changed, from, oldRole, newRole) Code:
RoleChangedFrame:UnregisterEvent("ROLE_CHANGED_INFORM") |
Ups, did not expect that ... for the records:
http://wowprogramming.com/utils/xmlb...L/RolePoll.xml Code:
<Frame name="RoleChangedFrame" parent="UIParent"> Lua Code:
|
Sure these are events, but as you can see, there's something sent to chat "ChatFrame_DisplaySystemMessageInPrimary"
There's no need to unregister the event, there has to be a way to just filter the message, right ? And the question is, why aren't the patterns catching them ? |
Quote:
Quote:
|
Code:
RoleChangedFrame:UnregisterAllEvents() But it bothers me. Why the filtering way wouldn't work. I mean, those messages are sent to CHAT_MSG_SYSTEM right ? So, if they are why can't i filter them there like just about anything else being sent to the chat ? |
Quote:
|
Quote:
Or not, i don't know :) |
Quote:
Also, you may want to change the last line in topattern to escape all the "magic characters", not just parentheses. For my purposes it didn't matter, but if you're using it on other global strings, it might matter. Code:
text = gsub(text, "([%(%)%.%%%+%-%*%?%[%^%$])", "%%%1") |
Quote:
Quote:
|
Quote:
|
All times are GMT -6. The time now is 12:31 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI