WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Chat Filters (https://www.wowinterface.com/forums/showthread.php?t=42446)

hershe 01-24-12 05:42 PM

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 


hershe 01-24-12 05:59 PM

And.... I think I just figured it out.

The first addon needs to send the notification of a message that needs to be filtered for FIRST, before the message is actually sent. I made this small change and things appear to work perfect.

Although I am still curious if there's any other concern for timing... like right in my test, the notification was sent to me via the addon whisper channel, just before the message itself was sent to me in whisper. I ASSUME this forces the timing to be in sequence, such that the filter must be recieved before the message is displayed because both use the whisper channel. Would this hold true if the notification was sent to the addon Raid channel, while the message itself was sent to SAY? Or is there potential that the message in SAY is received before the filter notification is received, even though the notification was sent first?

Xubera 01-28-12 04:24 AM

well if memory serves correctly. AceComm communicates between different clients (two different WoW Windows) and therefore it uses throttling to communicate between lanes of chat messages. Meaning that in order to prevent the server from kicking you for sending too much data in one cycle, it breaks the message apart. Now even if this message is short enough to send over in one packet, AceComm would still use its timing function to send the message.

So sending the alert to make and addition to the filter, then in the same cycle send the message, it can't possibly send the filter update in time.

That is assuming I remember what AceComm was used for :)


All times are GMT -6. The time now is 05:17 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI