Thread Tools Display Modes
Prev Previous Post   Next Post Next
01-24-12, 05:42 PM   #1
hershe
A Deviate Faerie Dragon
Join Date: Jun 2011
Posts: 10
Chat Filters

Hello again! Looking for some help with people familiar with the chat filtering functions. Basically here's what I'm trying to accomplish. I author an addon that can send chat messages... These messages can be customized, their content changes dynamically (like "time left" is different every time), and there can be any given number of them based on how many the user has added. In other words, there is no static list of messages or patterns that can be filtered for.

So, since I can't predict what needs to be filtered out, my goal now is to make a new addon that can collect and store each message that needs to be filtered out as it is received. I'm making modifications to the existing addon to use AceComm to notify the new addon that a message that needs to be filtered as been sent, and with the exact text of the message. As is, the new addon successfully receives these notifications and stores each of the messages in a table. The table is then used in a filtering function to hide the message.

Problem is there is some sort of timing issue that's causing me trouble. When I send a message to be filtered, it won't filter it the first time... but if the identical message shows up again to be filtered, it will filter it the next time. It's like there's a lag between the addition of the messages to be filtered to the filter table and when that table is actually used to filter... Problem is the message is sent just before the addon notification is sent to filter it, so there is no time to wait for lag.

Please let me know if you can see where this issue is stemming from... I assume there's something I need to do to make the filtering wait until the filter table is ready, or make it re-apply itself. Here's the code of the addon. I've got some Print()'s in there for debugging, don't mind those.


PHP Code:
FriedSpam LibStub("AceAddon-3.0"):NewAddon("FriedSpam""AceConsole-3.0""AceEvent-3.0""AceComm-3.0")

--
table to hold messages that need to be filtered
local filterMessages 
= {}



function 
FriedSpam:OnInitialize()
    -- 
Called when the addon is loaded
end

function FriedSpam:OnEnable() -- Called when the addon is enabled
    self
:Print("FriedSpam Enabled")
    --
AceComm 3.0notification of a new message that needs to be filtered.
    
self:RegisterComm("FriedSpam")
end

function FriedSpam:OnDisable()
    -- 
Called when the addon is disabled
    self
:Print("FriedSpam Disabled")
    
FriedSpam:UnregisterAllEvents()
end

--Filter Function
local function FriedSpamChatFilter(self,event,msg,...)
    
FriedSpam:Print("running 1")
    for 
k,v in pairs(filterMessages) do
          
FriedSpam:Print("running 2")
          
FriedSpam:Print(msg)           
          
FriedSpam:Print(v)
          
FriedSpam:Print(msg == v)
        if 
msg == v then
            FriedSpam
:Print("running 3")
            return 
true
        end
    end
      FriedSpam
:Print("running 4")
    return 
false,msg,...
end

--Create Filters
ChatFrame_AddMessageEventFilter
("CHAT_MSG_SAY"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_OFFICER"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_WARNING"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND_LEADER"FriedSpamChatFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_EMOTE"FriedSpamChatFilter)


--
Handler for when a new message to be filtered for has been sent
function 
FriedSpam:OnCommReceived(prefixmessagedistributionsender)
    
filterMessages[message] = message


    ChatFrame_RemoveMessageEventFilter
("CHAT_MSG_SAY"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_YELL"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_WHISPER"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_WHISPER_INFORM"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_GUILD"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_OFFICER"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_PARTY"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_PARTY_LEADER"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_RAID"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_RAID_LEADER"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_RAID_WARNING"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_BATTLEGROUND"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_BATTLEGROUND_LEADER"FriedSpamChatFilter)
    
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_EMOTE"FriedSpamChatFilter)

    
ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_OFFICER"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_WARNING"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND_LEADER"FriedSpamChatFilter)
    
ChatFrame_AddMessageEventFilter("CHAT_MSG_EMOTE"FriedSpamChatFilter)
    
end 
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Chat Filters


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off