Minion Beta! - Help us test our new AddOn updater. Get it now!
(1 Kb)
Updated: 07-10-10 03:13 AM
Updated:07-10-10 03:13 AM
Created:07-10-10 03:13 AM


Version: 0.9
by: daVinci1980 [More]

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)
-- Need real logic here, but whatevs.
function MyMod.GetCurrentDkp(who)
return 100

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))

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)

Ignore will ignore the specified message from the specified player exactly once, freeing all of your callback functions from needing similar functionality.

Optional Files (0)

There have been no comments posted to this file.
Be the first to add one.

Category Jump: