Lua Code:
hooksecurefunc("StaticPopup_Show", function(which, sender)
if which == "PARTY_INVITE" then
print("StaticPopup_Show", which, sender)
local dialog = StaticPopup_Visible("PARTY_INVITE")
StaticPopup_OnClick(_G[dialog], 2)
SendChatMessage("No thanks.", "WHISPER", nil, sender)
end
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).