McFilter adds basic filtering and callback registration for chat messages. The goal is to be simple, lightweight and self contained. Currently supports registering callbacks in response to chat events--does not support chat filter callbacks yet. They will be added shortly.
What follows is an example of a simple mod that responds to a whisper with a request for their current DKP.
Given that you have this function:
function MyMod.Whisper(dest, str)
SendChatMessage(str, "WHISPER", nil, dest)
end
-- Need real logic here, but whatevs.
function MyMod.GetCurrentDkp(who)
return 100
end
Then, you'd add a filter function, which must be defined before you register the chat callback
function MyMod.OnPotentialRequest(msg, author, language)
if (msg:find("^![dD][kK][pP]") then
MyMod.Whisper(string.format("Your current DKP is %.2f", MyMod.GetCurrentDkp(author))
end
end
You would add a callback first, like this:
McFilter.RegisterChatCallback("CHAT_MSG_WHISPER", MyMod.OnPotentialRequest)
Additionally, to ensure that your mod won't cause an infinite loop (for example, if your response was "!dkp {resultNum}"), you could modify your MyMod.Whisper(dest, str) to look like this:
function MyMod.Whisper(dest, str)
McFilter.Ignore(str, UnitName("player"))
SendChatMessage(str, "WHISPER", nil, dest)
end
Ignore will ignore the specified message from the specified player exactly once, freeing all of your callback functions from needing similar functionality.