Intercepting CHANNEL_INVITE_REQUEST

I want to inspect the channel name in an invitation and automatically dismiss matching patterns. (Yes, this is to shut down the gold spammers.) How do I prevent the event from getting to UIParent_OnEvent? (That handler pops up the accept dialog unless all invitations are blocked, in which case it calls DeclineChannelInvite.)

I figure I need to create a simple frame, register the event, and write a handler to match a pattern and dismiss the invite. But how to get it done early in the pipeline, before the default handler?

You can see the default handler here:

UIParent:UnregisterEvent("CHANNEL_INVITE_REQUEST")

Thanks, that looks useful. I could then call the UIParent handler for channels I want to pass through.

Here’s a first cut:

-- DeclineSpamChannelInvitations

local dsciFrame = CreateFrame("Frame")

dsciFrame:SetScript("OnEvent", function(self, event, channelID, name)
      if ("CHANNEL_INVITE_REQUEST" == event) then
         print("DeclineSpamChannelInvitations:", self, event, channelID, name)
         if string.find(channelID, "GOLD") then
            print("Spammer " .. name .. "invited you to channel " .. channelID)
            DeclineChannelInvite(channelID)
            return
         end
         -- for all other channels, invoke default handler
         UIParent_OnEvent(UIParent, event, channelID, name)
      end
   end
)

dsciFrame:RegisterEvent("CHANNEL_INVITE_REQUEST")

-- uncomment this once we know above is working
-- UIParent::UnregisterEvent("CHANNEL_INVITE_REQUEST")

if "CHANNEL_INVITE_REQUEST" is the only event the frame is registered for then

if ("CHANNEL_INVITE_REQUEST" == event) then

and its end statement is not required as that is the only event the handler will receive.

Just a bit of pedantry.

Edit: If this is just for you it’s probably fine but if you intend it for a wider audience you might want to consider what to do if “they” have set the "blockChannelInvites" CVar.

It seems Blizzard has taken care of this so I no longer need it. I threw the addon up on GitHub for posterity, as “DeclineSpamChannelInvitations”, so others can lift the code.