Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:API ChatFrame AddMessageEventFilter
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{framexmlfunc|FrameXML/ChatFrame.lua}} Manipulates [[FrameXML]]'s list of chat event filters. ChatFrame_AddMessageEventFilter("event", filterFunc) ChatFrame_RemoveMessageEventFilter("event", filterFunc) filterFuncList = ChatFrame_GetMessageEventFilters("event") == Arguments == ;"event" : String - name of the event to filter for ;filterFunc : Function - your filtering function; see below for details == Returns == ;filterFuncList : table - an array of filter functions. This is the same table as is used by the filtering system. == filterFunc == filter, arg1, arg2, arg3, ..., arg15 = myFilterFunc(chatFrame, event, arg1, arg2, arg3, ..., arg15); For most chat events, arg1 is the message text. === Return values === ; filter : Boolean: if true, the message is discarded. ; arg1, arg2, ... arg15 : Mixed: if ''filter'' is non-true, and arg1 is non-nil/false, the 15 returned values after ''filter'' replace the 15 arguments provided to the function for subsequent filtering purposes. Note that the ''environment'' arg1-arg15 aren't replaced: only the filter function arguments (and subsequent ChatFrame code) are affected. Note that your function will be called once for every frame the message-event is registered for. It's possible to get two calls for whisper, say, and yell messages, and seven for channel messages. Due to this non-deterministic calling, your filter function should not have side-effects. == Example filter implementation == Writing a filter is fairly straightforward: local function myChatFilter(self, event, msg, author, ...) if msg:find("buy gold") then return true end if author == "Knownspammer" then return true end if msg:find("lol") then return false, gsub(msg, "lol", ""), author, ... end end ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", myChatFilter) ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", myChatFilter) ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", myChatFilter) ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", myChatFilter) You should use the variables passed into the function rather than the global arg1, arg2 etc :{{icon-exclamation}}'''3.1 change''': The filter function is no longer passed "(msg)". : It is now passed the chat frame, the event and arg1, arg2 ... arg15. : If you return a non-nil arg1, you must also return all of arg2 ... arg15 == Example Chatframe addon use == Chatframe addons / whisper managers etc should of course make use of these filters. local function myChatEventHandler(self,event,arg1,...) local filterFuncList = ChatFrame_GetMessageEventFilters(event) if filterFuncList then for _, filterFunc in pairs(filterFuncList) do local filter, newarg1 = filterFunc(self,event,arg1,...) if filter then return end if newarg1 then arg1 = newarg -- you should actually probably do this for all of arg2..arg11 since that's what framexml does end end end -- whoop de do, not filtered, go about our business and display etc end == Details == This set of functions was added in [[patch 2.4]]. The arguments of the filter function were incompatibly changed in [[patch 3.1]]. Re-adding an already-existing filter is harmless - the second addition is ignored. Removing a filter that has not been added is harmless - there is no error. You first have to define your filter function - local filterfunc(self,event,arg1,...) - and after that use ChatFrame_AddMessageEventFilter("event", filterfunc) in your lua code. All possible chat events, that can be used are listed [[Events/Communication]]. __NOTOC__
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Apinav
(
edit
)
Template:Editlink
(
edit
)
Template:Framexml
(
edit
)
Template:Framexmlfunc
(
edit
)
Template:Icon-exclamation
(
edit
)
Template:Icon-information
(
edit
)
Template:Wowapi
(
edit
)
Template:Wowtoolsfilelink
(
edit
)