View Single Post
04-16-12, 02:19 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Lua Code:
  1. hooksecurefunc("StaticPopup_Show", function(which, sender)
  2.     if which == "PARTY_INVITE" then
  3.         print("StaticPopup_Show", which, sender)
  4.         local dialog = StaticPopup_Visible("PARTY_INVITE")
  5.         StaticPopup_OnClick(_G[dialog], 2)
  6.         SendChatMessage("No thanks.", "WHISPER", nil, sender)
  7.     end
  8. end)

1. Catch the actual function that shows the popup, and securely run your own function after the original runs. This ensures that you do not break or taint any parts of the StaticPopup system. Your function gets the same arguments as the original.

2. Check the first argument to see if it's the PARTY_INVITE dialog.

3. Comment out the print line once you're sure it's working.

4. Get the name of the frame being used for this dialog. This function can return nil (if the specified dialog is not being displayed) but in this case, we know it is being displayed since our function is running immediately after the Blizzard function that shows this dialog, so we don't need to check that the dialog variable is non-nil before using it.

5. Use the dialog's own OnClick handler to close it and decline the invite. This is easier and more future-proof than calling the relevant functions yourself.

6. Send a message to the sender (second argument).
  Reply With Quote